Squirrels have fuzzy tails.
0 Members and 4 Guests are viewing this topic.
PORTA ^= (1 << bitno);
1. tempRegister = read PORTA2. tempRegister ^= (1<<bitno)3. write PORTA(tempRegister)
sbi(PINA, bitno);
A2D,6 {change to} Digital_I/O 8
#define SET(x,y) (x|=(1<<y))#define CLR(x,y) (x&=(~(1<<y)))#define CHK(x,y) (x & (1<<y))#define TOG(x,y) (x^=(1<<y))#define _BV(bit) (1 << (bit))#define sbi(port,bit) (port)|=(1<<(bit))#define cbi(port,bit) (port)&=~(1<<(bit))
cbi(PINB,0); sbi(PINB,0);
sbi(PINB,0);
You only need to set the bit to make it toggle. So you can just write:Code: [Select]sbi(PINB,0);You never need to clear it as the hardware does that for you.
PORTB |= _BV(0); PORTB &= ~(_BV(0));
You are setting the pin to a know state ie 'high' or 'low'. Whereas the toggle method I mention above will toggle it to its opposite state.
sbi(PINB,0); // Toggledelaysbi(PINB,0); // Toggle back
sbi(PINB,0);sbi(PINB,0);
while(1){ sbi(PINB,0);}
PORTB &= ~(_BV(0)); PORTB &= ~(_BV(1)); PORTB &= ~(_BV(2));
PORTB &= ~(_BV(0)|_BV(1)|_BV(2));
PORTB &= 0xF8;
EDIT:Could it be something with PB7 sharing a crystal pin?
uint8_t temp = PORTB;temp &= ~(_BV(0)|_BV(1)|_BV(2));PORTB = temp;
I'll check the datasheet - presume its still an ATMega328P ?
13.2.2 Toggling the PinWriting a logic one to PINxn toggles the value of PORTxn, independent on the value of DDRxn.Note that the SBI instruction can be used to toggle one single bit in a port.