Hallo Ich möchte PINB0 bis PINB3 und PINC2,PINC3,PINC6 und PINC7 mit einer Variable schalten. die Variable ist eine unsigned char also ein Byte. Leider komme ich nicht weiter. mein letzter Versuch war wie folgt: if (message.data[0]&(0b00000001)) PORTB = (1<<PB0); else PORTB &=~(1<<PB0); if (message.data[0]&(0b00000010)) PORTB = (1<<PB1); else PORTB &=~(1<<PB1); if (message.data[0]&(0b00000100)) PORTB = (1<<PB2); else PORTB &=~(1<<PB2); if (message.data[0]&(0b00001000)) PORTB = (1<<PB3); else PORTB &=~(1<<PB3); if (message.data[0]&(0b00010000)) PORTB = (1<<PC2); else PORTB &=~(1<<PC2); if (message.data[0]&(0b00100000)) PORTB = (1<<PC3); else PORTB &=~(1<<PC3); if (message.data[0]&(0b01000000)) PORTB = (1<<PC6); else PORTB &=~(1<<PC6); if (message.data[0]&(0b10000000)) PORTB = (1<<PC7); else PORTB &=~(1<<PC7); danke für eure hilfe lg Manfred
Wenn du PORTC beschreiben willst sollte auch PORTC dran stehen und nicht PORTB, ansonsten wo liegt das Problem? http://www.mikrocontroller.net/articles/Bitmanipulation
vielleicht gehts so. Bin mir gerade selbst nicht mehr sicher :) "PINB0 bis PINB3 und PINC2,PINC3,PINC6 und PINC7" PORTB &= 0xF0 PORTB |= (data & 0x0F) PORTC &= 0x33 PORTC |= (data & 0xCC)
1 | PORTB = PINB & (0xF0 | (data & 0x0F)); |
2 | PORTC = PINC & (0x33 | ((data & 0x30) >> 2) | (data & 0xC0)); |
Oliver
Danke für die Hilfe, es Funktioniert ich hab einen Schreibfehler gehabt if (message.data[0]&(0b00000001)) PORTB = (1<<PB0); else PORTB &=~(1<<PB0); so ists richtig if (message.data[0]&(0b00000001)) PORTB |= (1<<PB0); else PORTB &=~(1<<PB0); lg Manfred
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.