atmega32 avr c programming code

Status
Not open for further replies.

boukamoha

Member level 5
Joined
Aug 3, 2012
Messages
85
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,891
hi every one
can some one tell me the difference between setting the portB of ATMEGA32 as PORTB=0b11111110; and PORTB &=(1<<PB0) and PORTB &=0b11111110
best regards
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
PORTB = 0b11111110;      // assigning a value to PORTB unconditionally
 
PORTB &=0b11111110;      // reading PORTB and MASKING OUT the LSB bit ONLY
PORTB = PORTB & 0xFE;      // same statement written differently
 
PORTB &= (1<<PB0);      // isn't correct if it should be the same as the previous statement
// it reads as PORTB = PORTB & 0x01 (1<<PB0) is (1<<0) or bit shift (0) positions(s)...
 
PORTB &= ~(1<<PB0);      // if you want the same effect as the previous statement
 
// so to set a bit
PORTB |= (1<<PB0);
// to clear a bit
PORTB &= ~(1<<PB0);

 
Last edited by a moderator:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…