0
10kviews
Write C language program to toggle all bits of P0, P1, P2 and P3 ports continuously with certain delay.
1 Answer
0
952views

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++);     
}
Please log in to add an answer.