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

Can SFRs and Sbits be defined as volatile?

sbit P07 = 0x87;
void main()
{
while(P07);    // End Program unless we get error
printf("Error - line went low");  // Print Error being recieved
for(;;)        // End after Error
}

Problem is that it never gets out of the first while loop even when P07 (Port 0, pin 7) changes states. I am using DS2252T which allows ports to be bit addressable. What am I doing wrong?

Thanks

  • Are you sure that it's never getting out of the loop; could it just be that your printf is not working?

    I think that volatile is implicit in SFR & sbit definitions?

  • What makes P0.7 go low?

    Jon

  • I found my problem.

    P0.7 was forced high previously in my code.

    Quote from "C and the 8051, Hardware, Mdular Programming and multi-tasking Volume I" by Thomas W. Schultz --

    any port you are using as an input must have a 1 written out to it.

    As the ports are going through an inverter on the board, the high was actually a low, and therefore not allowing the port to be used as an input.

    I admit, I am still learning C and still learning the 8051, so I tend to make lots of mistakes that a real Embedded programmer would catch.

    I think I explained the problem and solution well enough here. If not ask away and I'll give you the references in the books I am using that make it clearer than I can explain.