使用发光管1秒亮灭
#include<reg52.h>
#define uchar unsigned char
#define uint unsignef int
sbit L1=P1^0;
uchar num;
void main()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TH0=(65536-45872)%256;
TF0=0;
L1=0;
ET0=1;
TR0=1;
EA=1;
while(1);
}
void to_
time() interrupt 1
{
TH0=(65536-45872)/256;
TH0=(65536-45872)%256;
num++;
if(num==20) //此处应该是20,可才是280ms,只有是71时才是1s变化一次
{
num=0;
L1=~L1;
}
}
希望能告诉我原因
#define uint unsigned int
#define uchar unsigned char
sbit led1 =P1^1;
uchar num;
void main()
{
num=0;
TMOD = 0x01;
TH0 = (65536-45872)/256;
TL0 = (65536-45872)%256;
EA=1;//开总中断
ET0=1;//开定时器0中断
TR0=1;//启动定时器
while(1)
{
if(num==20)
{
num=0;
led1=~led1;
}
}
}
void T0_time() interrupt 1
{
TH0 = (65536-45872)/256;
TL0 = (65536-45872)%256;
num++;
}
一周热门 更多>