0
Write C language program to toggle all bits of P0, P1, P2 and P3 ports continuously with certain delay.
c program • 2.6k  views
0
0

The program

#include < reg51.h>  
void Add_delay (unsigned int);  
void main (void)   
while(1) //repeat loop  
{  
    P0=0xff; //toggle all bits of port 0  
    Add_delay (200); // add delay  
    P0=0x00; //toggle all bits of port 0   
    Add_delay (200); //add delay   
    P1=0xff; //toggle all bits of port 1  
    Add_delay (200); //add delay  
    P1=0x00; //toggle all bits of port 1  
    Add_delay (200); //add delay    
    P2=0xff; //toggle all bits of port 0  
    Add_delay (200); //add delay  
    P2=0x00; //toggle all bits of port 2  
    Add_delay (200); //add delay   
    P3=0xff; //toggle all bits of port 3  
    Add_delay (200); //add delay   
    P3=0x00; //toggle all bits of port 3   
    Add_delay (200); //add delay  
}   
void Add_delay (unsigned int delay)  
{   
    unsigned int x,y;   
    for(x=0; x< delay; x++)  
    for (y=0; y<1275; y++);     
}
0
Please log in to add an answer.

Continue reading

Find answer to specific questions by searching them here. It's the best way to discover useful content.

Find more