以一秒為例,給你寫了一個程式,自己看吧,修改TH0、TL0和count就可以設定任意時間間隔閃爍了
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED=P1^0;
bit flag;
uchar count=0;
void delay(uchar c)
{
uchar a, b;
for (; c>0;c--)
for (b=142;b>0;b--)
for (a=2; a>0; a--);
}
void main(void)
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
if(flag==1)
LED=0;
delay(100);
LED=1;
flag=0;
void time0(void) interrupt 1
count++;
if (count>=20)
count=0;
flag=1;
以一秒為例,給你寫了一個程式,自己看吧,修改TH0、TL0和count就可以設定任意時間間隔閃爍了
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED=P1^0;
bit flag;
uchar count=0;
void delay(uchar c)
{
uchar a, b;
for (; c>0;c--)
for (b=142;b>0;b--)
for (a=2; a>0; a--);
}
void main(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(flag==1)
{
LED=0;
delay(100);
LED=1;
flag=0;
}
}
}
void time0(void) interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if (count>=20)
{
count=0;
flag=1;
}