You place both statments as an if, instead of blocking the statments as [if]
[else]
blocks.
I mean that in the next shift, P4 shift one time to the LEFT: 0x02 -> 0x04,
then the next if statment take place: P4 shift back to RIGHT: 0x04 -> 0x02.
The sequence occur each interrupt cycle.
Please describe your problem clear, so other people can help you.
Your problem isn't a compiler or even ke*l problem.
I guess you wish to realize a constant and repeatedly shift through P4.
If so, you have to register wether the two shift events reach there bounderies. If so, register and turn around the shift direction.
if you put th second condition in an ELSE statment, you will get the seceuence: 1, 2, 4, 8, 16, 32, 64, 128, 64, 128, 64, 128 ... and so on, because you have to decideif you are Up-shifting or Down-Shifting. Sometihg likethis wil go well,
if you put th second condition in an ELSE statment, you will get the seceuence: 1, 2, 4, 8, 16, 32, 64, 128, 64, 128, 64, 128 ... and so on, because you have to decideif you are Up-shifting or Down-Shifting. Sometihg likethis wil go well,
unsigned char UP = 1;
void timer0 interrupt() using 1{
if (UP)
if ( P4 < 0x80 )
P4 <<= 1;
else{
UP = 0;
P4 >>= 1;
}
else
if ( P4 > 0x01)
P4 >>= 1;
else{
UP = 1;
P4 <<= 1;
}