I have some doubts about configuration of ATmega328P interface with Push button in Atmel studio 6.I am going to configure the reg and port .please conform to me ,it's correct or not.
step1: DDRB |= 1 << PINB0; //This is for making pin B0 as output direction
// PINBO=0b 0000 0000
mask1=0b 0000 0000
1<<PINBO= 0000 0001
DDRB= 0000 0001
DDRB|=1<<PINB0=0000 0001
(Its correct or not)
PORTB ^= 1 << PINB0;//this is make 5v output in PINB0
PORTB=0b 0000 00001
PINB0=0b 0000 0000
Mask=0b0000 0001
1<<PINB0=0b0000 0001
Step 2: PORTB^=1<<PINB0=0b 0000 00001
DDRB |= 1 << PINB2;//make Pin B1 as output direction
DDRB=0b 0000 0100
PINB2=0b0000 0000
mask =0b0000 0001
1<<PINB2=0b0000 0100
PORTB^=1<<PINB0=0b0000 0100
(Its correct or not)
Step3: DDRB &= ~(1 << PINB1);//make pin B1 as input for push button interface
DDRB=0x0000 0010
pinB1=0x0000 0000
Mask1=0x0000 0001
1<<PINB1=0x0000 0010
~(1<<PINB1)=0x 1111 1101
DDRB &= ~(1 << PINB1)=0x 0000 0000
(Its correct or not)
step 4: PORTB |= 1 << PINB1;(for 5v to PIN B1)
PINB1=0x 0000 0000
mask1=0x 0000 0001
1<<PINb1=0x0000 0010
PORTB=0x0000 0010
PORTB |= 1 << PINB1 =0x 0000 0010;
(Its correct or not)
My question pinb0,b2 is output ,b1 is input
So,DDRB=0x 0000 0101;
every time we should do AND and OR operation with above steps or,first one is correct.
step1: DDRB |= 1 << PINB0; //This is for making pin B0 as output direction
// PINBO=0b 0000 0000
mask1=0b 0000 0000
1<<PINBO= 0000 0001
DDRB= 0000 0001
DDRB|=1<<PINB0=0000 0001
(Its correct or not)
PORTB ^= 1 << PINB0;//this is make 5v output in PINB0
PORTB=0b 0000 00001
PINB0=0b 0000 0000
Mask=0b0000 0001
1<<PINB0=0b0000 0001
Step 2: PORTB^=1<<PINB0=0b 0000 00001
DDRB |= 1 << PINB2;//make Pin B1 as output direction
DDRB=0b 0000 0100
PINB2=0b0000 0000
mask =0b0000 0001
1<<PINB2=0b0000 0100
PORTB^=1<<PINB0=0b0000 0100
(Its correct or not)
Step3: DDRB &= ~(1 << PINB1);//make pin B1 as input for push button interface
DDRB=0x0000 0010
pinB1=0x0000 0000
Mask1=0x0000 0001
1<<PINB1=0x0000 0010
~(1<<PINB1)=0x 1111 1101
DDRB &= ~(1 << PINB1)=0x 0000 0000
(Its correct or not)
step 4: PORTB |= 1 << PINB1;(for 5v to PIN B1)
PINB1=0x 0000 0000
mask1=0x 0000 0001
1<<PINb1=0x0000 0010
PORTB=0x0000 0010
PORTB |= 1 << PINB1 =0x 0000 0010;
(Its correct or not)
My question pinb0,b2 is output ,b1 is input
So,DDRB=0x 0000 0101;
every time we should do AND and OR operation with above steps or,first one is correct.