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

}

8 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
  3. Why do we take p1= 0*55 and p1 = 0*aa

    ReplyDelete
    Replies
    1. We are giving some value to P1 port and creating some delay ,and again giving another value and delay .which will seem like toggling

      Delete
  4. Write an assembly language for 8051 to toggle all the bits of ports 0?
    Please solve this question

    ReplyDelete
  5. Write an 8051 C Program to toggle only pin P1.5 continuously every 250ms. Use Timer 0, mode 2 (8 bit auto reload to create the delay).

    ReplyDelete
  6. Write an 8051 C Program to toggle only pin P1.5 continuously every 250ms. Use Timer 0, mode 2 (8 bit auto reload to create the delay.

    ReplyDelete
  7. Write an 8051 C program to toggle all the bits of port p1
    continuously with some delay in between. Use Timer 0 16 bit
    mode to generate the delay. Assume Timer 0 register value is
    the sum of your date of date of birth in Hexadecimal

    ReplyDelete

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