- This topic has 3 replies, 2 voices, and was last updated 12 years, 11 months ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.
|
Microcontroller › AVR › AVR PORT pins
what is the difference between these two instructions
PORTD| = (1<<PD0) and PORTD = (1<<PD0)?
also what is it mean by PORTD| = (0<<PD0) and PORTD = (0<<PD0) and PORTD& = ~(1<<PD0) ?
i think u know the truth table of AND & OR logic
the same opperaton is going on here..
in first two statements..
PORTD |= (1<<PD0 ) and PORTD = (1<<PD0) both opperations are same
but in second statemnt(PORTD = (1<<PD0)), we r dng PD0 as a ONE and remaing all pins are ZERO.
in first statemnt (PORTD |= (1<<PD0)), only PD0 as ONE and we r not touching remng PINS..that mean
if PD1=1,
in first statemnt PDO=1 and PD1 also 1
but in second PD0 =1 and PD1 is ZERO.
and remaing also same…..
i hope u undersd…………
thanks for the reply
what happens in proteus simulator that i tell u
if the following code is written to blink the LED then it blinks fine
PORTD = (1<<PD0);
_delay_ms(1000);
PORTD = (0<<PD0);
but if the code is
PORTD|= (1<<PD0);
_delay_ms(1000);
PORTD| = (0<<PD0);
then it stays on. no blinking
but again if the code is changed to
PORTD|= (1<<PD0);
_delay_ms(1000);
PORTD& = ~(1<<PD0);
led starts blinking
so my questions is why and how?
ok…
seee here
PORTD|= (1<<PD0);
_delay_ms(1000);
PORTD| = (0<<PD0);
ur dng OR operation, means applying LOGICAL OR.
that mean dng 1 ORING with 0….
again the result also 1.
that is the reason….
and one more suggetn is give delay after clearing PD0
means
PORTD|= (1<<PD0);
_delay_ms(1000);
PORTD| = (0<<PD0);
_delay_ms(1000);
k?