0
2.5kviews
Write a C program to toggle P2.1 continuously with 100 ms delay. (Use simple delay subroutine).
1 Answer
written 6.0 years ago by | • modified 5.9 years ago |
The program
#include < reg 51.h>
void add_delay (unsigned int);
sbit data_bit = P2^1;
void main (void)
{
while (1)
{
data_bit =1; // set P2.1 bit
add_delay (100);
data_bit =0; // reset P2.1bit
add_delay (100);
}
}
void add_delay (unsigned int delay_time)
{
unsigned int x,y;
for (x = 0; x <delay_time; x ++)
for (y =0; y<1275; y++);
}