闪灯
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit led1=P1^0;
uchar num;
void main()
{
TMOD=0x00;
TH0=(8192-4607)/32;
TL0=(8192-4607)%32;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(num == 200)
{
num=0;
led1=~led1;
}
}
}
void T0_time() interrupt 1
{
TH0=(8192-4607)/32;
TL0=(8192-4607)%32;
num++;
}
下上下上全亮
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit led1=P1^0;
sbit led2=P1^1;
uint num1, num2;
void main()
{
TMOD=0x03;
TH0=6;
TL0=6;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
{
if(num1>=3686)
{num1=0;
led1=~led1;
}
if(num2>=1843)
{
num2=0;
led2=~led2;
}
}
}
void TL0_time() interrupt 1
{TL0=6;
num1++;
}
void TH0_time() interrupt 3
{
TH0=6;
num2++;
}
|