Write an 8051 C program to toggle all the bit of P0, P1 and P2 continuously with a 250 ms time dealy.

By

Write an 8051 C program to toggle all the bit of P0, P1 and P2 continuously with a 250 ms time dealy.

Solution :

sfr P0 = 0x80;  // declare by yourself

sfr P1 = 0x90;  // declare by yourself

sfr P2 = 0xA0;  // declare by yourself

void MSDelay(unsigned int);

 // MSDelay is as same as 250ms


void main(void) {

  unsigned int z;  

  while(1) {       //repeat forever

    P0=0x55;      

    P1=0x55;      

    P2=0x55;      

    MSDelay(250);  //time delay

    P0=0xAA;      

    P1=0xAA;      

    P2=0xAA;      

    MSDelay(250);  //time delay

} }

0 comments:

Post a comment

If you have any questions or droughts feel free to ask here.