/*******最简单的延时呼吸灯**********/
/****2020-5-5******/
#include<reg51.h>
sbit LED = P3^0;
#define uint unsigned int
#define uchar unsigned char
uint j,n;
void delay_ms(uint n);
main()
{
while(1)
{
j++;
LED = ~LED; // 开机LED=1,取反后=0, j满一个循环后,再次取反后为1,
delay_ms(300-j); //3ms
LED = ~LED; //取反,打开 第二个循环为关
delay_ms(j); //延时j,
if(j == 300)
{
j = 0;
LED = ~LED;
}
}
}
void delay_ms(uint n)
{
uchar b,c; uint d;
for(c=1;c>0;c--)
for(b=20;b>0;b--)
for(d=n;d>0;d--);
}
|