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

PROBLEM WITH THE C CODE

#include<reg51.h>

sfr port= 0x80;
void main()
{ port=~port;
}

This code was successfully compiled...but yu expect the port pins are complemented only once..But what i experiened when used with a simulator software, was the port pins get complemented for infinite times( somthing like the 'port=~port;' instruction was put in a while(1) loop..)

What could be the wrong?

Parents
  • All of the previous answers tell you why your code is wrong. But the reason that your first post is in an infinite loop is beacuse Keil forces an LJMP to main at the end of your code. This is to prevent the very problem discribed, that is over running your code with no possible exit from main. You can only prevent this by inserting a proper 'forever' loop.
    Please read and run some of the sample code in the 'Getting Started' manual. This action is well defined in the manual.
    Bradford

Reply
  • All of the previous answers tell you why your code is wrong. But the reason that your first post is in an infinite loop is beacuse Keil forces an LJMP to main at the end of your code. This is to prevent the very problem discribed, that is over running your code with no possible exit from main. You can only prevent this by inserting a proper 'forever' loop.
    Please read and run some of the sample code in the 'Getting Started' manual. This action is well defined in the manual.
    Bradford

Children
No data