#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?
but yu expect the port pins are complemented only once
No. We don't expect that. You do.
We have read enough of the documentation, particularly the tutorials, to know that falling through the end of main() is not typically something one should do in an embedded C program if one doesn't want unexpected things to happen.
Your expectations are.
Then please help me stating what should be the code for my need. The code should complement the port pins only once. Please help me.
You have already been notified that your expectation that it is ok to fall out of main() is ok.
Since it isn't, change your code so that it doesn't end. There are no OS available to catch you, so add an infinite loop.
Even if i add an infinite loop like
while(1) { port1 = ~port1; } The same thing happens(actually that was my problem). It means that i need to make it happen only once. I can do like below
int f=0; while(1) { if(f==0) port1 = ~port1; f++; } This keeps the statement port1= ~port1; happen only once theoratically.But it doesnt actually.
Think about what happens when f gets bigger than an int...
And if you post any more code, put the proper "pre" tags around it so we can read it easier.
View all questions in Keil forum