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

}

2 comments:

  1. Write a program to toggle pin P1.2 every second
    Please solve this question.. please

    ReplyDelete
  2. Thaks for sharing the post with us. We are
    Mobile App Development Company in Mumbai serving around 1K+customer.

    ReplyDelete

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