Tag zusammen! Ich möchte PORTB 1 bis 4 abfragen?
Habe schon vieles probiert aber nichts hat wirklich funktioniert!
Hier mein letzter versuch:(Und wenn das denn mal geht.... giebt es eine kürzere Möglichkeit???)
Und die einzelne Abfrage eines Pins auf logisch 0 habe ich bis jetzt auch nicht gefunden!Code:int anzahl_Zyl(void) //fragt BP1-PB4 ab und giebt Einstellung Zylinderanzahl zurück
{
DDRB |= 0x00;
int a = 0;
//PORTB 765 4 321 0
if((PINB |= ~(1<<PINB1) && (PINB |= ~(1<<PINB2) && (PINB |= ~(1<<PINB3) && (PINB & (1<<PINB4))a =1; //000 1 000 0
if((PINB |= ~(1<<PINB1) && (PINB |= ~(1<<PINB2) && (PINB & (1<<PINB3) && (PINB |= ~(1<<PINB4))a =2; //000 0 100 0
if((PINB |= ~(1<<PINB1) && (PINB |= ~(1<<PINB2) && (PINB & (1<<PINB3) && (PINB & (1<<PINB4))a =3; //000 1 100 0
if((PINB |= ~(1<<PINB1) && (PINB & (1<<PINB2) && (PINB |= ~(1<<PINB3) && (PINB |= ~(1<<PINB4))a =4; //000 0 010 0
if((PINB |= ~(1<<PINB1) && (PINB & (1<<PINB2) && (PINB |= ~(1<<PINB3) && (PINB & (1<<PINB4))a =5; //000 1 001 0
if((PINB |= ~(1<<PINB1) && (PINB & (1<<PINB2) && (PINB & (1<<PINB3) && (PINB |= ~(1<<PINB4))a =6; //000 0 110 0
if((PINB |= ~(1<<PINB1) && (PINB & (1<<PINB2) && (PINB & (1<<PINB3) && (PINB & (1<<PINB4))a =7; //000 1 110 0
if((PINB & (1<<PINB1) && (PINB |= ~(1<<PINB2) && (PINB |= ~(1<<PINB3) && (PINB |= ~(1<<PINB4))a =8; //000 0 001 0
if((PINB & (1<<PINB1) && (PINB |= ~(1<<PINB2) && (PINB |= ~(1<<PINB3) && (PINB & (1<<PINB4))a =9; //000 1 101 0
if((PINB & (1<<PINB1) && (PINB |= ~(1<<PINB2) && (PINB & (1<<PINB3) && (PINB |= ~(1<<PINB4))a =10; //000 0 101 0
if((PINB & (1<<PINB1) && (PINB |= ~(1<<PINB2) && (PINB & (1<<PINB3) && (PINB & (1<<PINB4))a =11; //000 1 101 0
if((PINB & (1<<PINB1) && (PINB & (1<<PINB2) && (PINB |= ~(1<<PINB3) && (PINB |= ~(1<<PINB4))a =12; //000 0 011 0
return a;
}
Grüße Stephan