microcontroller - Why is my C program skipping over this if statement? -
i have c program writing in code composer studio.
#include <msp430.h> /* * main.c */ int main(void) { wdtctl = wdtpw | wdthold; // stop watchdog timer int r5_sw=0, r6_led=0, temp=0; p1out = 0b00000000; // mov.b #00000000b,&p1out p1dir = 0b11111111; // mov.b #11111111b,&p1dir p2dir = 0b00000000; // mov.b #00000000b,&p2dir while (1) { // read switches , save them in r5_sw r5_sw = p2in; // check read mode if (r5_sw & bit0) { r6_led = r5_sw & (bit3 | bit4 | bit5); // copy pattern switches , mask p1out = r6_led; // send pattern out } // display rotation mode else { r6_led = r5_sw & (bit3|bit4|bit5); // check direction if (r5_sw & bit1) {// rotate left r6_led << 1; } else { r6_led >> 1; } // rotate right // mask excessive bits of pattern , send out r6_led &= 0xff; // clear bits beyound byte when rotate not see garbage coming in p1out = r6_led; // check speed if (r5_sw & bit2) {__delay_cycles( 40000); } //fast else {__delay_cycles(100000); } //slow } } }
when gets if statment in debug mode
if (r5_sw & bit1) {// rotate left r6_led << 1; } else { r6_led >> 1; } // rotate right
it skips on it, doesn't run if or else block. @ point in code r5_sw
22
0010 0010
in binary r5_sw & bit1
should evaluate true. missing here?
if use operation <<
or >>
without assigning result discarded. try this:
if (r5_sw & bit1) {// rotate left r6_led = r6_led << 1; } else { r6_led = r6_led >> 1; } // rotate right
or, brevity:
if (r5_sw & bit1) {// rotate left r6_led <<= 1; } else { r6_led >>= 1; } // rotate right
Comments
Post a Comment