This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

serial port and timer

Hi,

I have a problem.I must send through the serial port the number 1 and the number 0 every second using a timer of the c167cs. Would someone know me to help?

Parents
  • if (a = 0) { ... }
    

    is an assignment, i.e. it doesn't matter what value a had before your test. You must use == to compare, i.e.

    if (a == 0) { ... }
    

    Or reverse the two parts of the if/else and drop the explicit comparison:

    if (a) {
        S0TBUF = '1';
        a = 0;
    } else {
        S0TBUF = '0';
        a = 1;
    }
    

    You can also remove the if statement totally:

    S0TBUF = '0' + (a++ & 1);
    


    This extracts the odd/even bit of a, and continuously increments a.

Reply
  • if (a = 0) { ... }
    

    is an assignment, i.e. it doesn't matter what value a had before your test. You must use == to compare, i.e.

    if (a == 0) { ... }
    

    Or reverse the two parts of the if/else and drop the explicit comparison:

    if (a) {
        S0TBUF = '1';
        a = 0;
    } else {
        S0TBUF = '0';
        a = 1;
    }
    

    You can also remove the if statement totally:

    S0TBUF = '0' + (a++ & 1);
    


    This extracts the odd/even bit of a, and continuously increments a.

Children