#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?
while (1) { port1 = ~port1; }
Why do you think that an infinite loop _around_ the code line that inverts the pins should not result in constantly toggling pins?
What do you think happen if you add an empty infinite loop _after_ you have inverted the port pins once?
int f = 0; while (1) { if (f == 0) port1 = ~port1; f++; }
What do you think happens when you keep on incrementing f again and again? What will happen when f reaches the limit for possible values?
By the way - why not post the source code as I do - formatted as code and not inlined in the text?
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