Write an 8051 C program to toggle bits of P1 continuously with a 250 ms delay.

By

Write an 8051 C program to toggle bits of P1 continuously with a 250 ms delay.

Solution:

#include <reg51.h>

void MSDelay(unsigned int);

void main(void) {

  while(1) {       //repeat forever

    P1=0x55;      

    MSDelay(250);  //time delay

    P1=0xAA;  

    MSDelay(250)    }}



Assume the program is tested for the DS89C420 with XTML=11.0592MHz. 
     
90ns =1275 = 114750ns = 1ms

void MSDelay(unsigned int itime) {

  unsigned int i,j;

  for (i=0; i<itime; i++)

    for (j=0; j<1275; j++); // 1ms delay

}

0 comments:

Post a Comment

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