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

Port Pin toggle

I wrote a code for to toggle the port that is given below
#include<reg51.h>

sbit CLOCK = P0^2;

void main()
{
while(1)
{

CLOCK = CLOCK^1;
}
}
its not toggling in the IDE please guide me
Mahesh

Parents
  • You please compile these two codes in Keil and watch the opcode generated thro disassembly window. You can fine which is better.

    #include<reg51.h>
    sbit CLOCK = P0^2;
    void main()
    {
             if(CLOCK)
    	 {
    	   CLOCK = 0;
    	 }
    	 else
    	 {
    	   CLOCK = 1;
    	 }
    }
    


    void main()
    {
    	CLOCK = CLOCK ? 0 : 1;
    }
    
    

    Dont see the size of the c file. See the size of the bin file.

Reply
  • You please compile these two codes in Keil and watch the opcode generated thro disassembly window. You can fine which is better.

    #include<reg51.h>
    sbit CLOCK = P0^2;
    void main()
    {
             if(CLOCK)
    	 {
    	   CLOCK = 0;
    	 }
    	 else
    	 {
    	   CLOCK = 1;
    	 }
    }
    


    void main()
    {
    	CLOCK = CLOCK ? 0 : 1;
    }
    
    

    Dont see the size of the c file. See the size of the bin file.

Children