unsigned char count=0,count_f=0;
void init_time()
{
TMOD=0x16;
TH0=0xff; //八位重装计数
TL0=0xff;
TH1=(65535-50000)/256;
TL1=(65535-50000)%256; //定时50ms
EA=1; //IE寄存器总开关
ET0=1; //定时器0使能
ET1=1; //定时器1使能
TR0=1; //开启T0
TR1=1; //开启T1
}
void service_jishu() interrupt 1
{
count_f ++; //计数器,用来计数
}
void sevice_dingshi() interrupt 3
{
TH1=(65535-50000)/256;
TL1=(65535-50000)%256;
count++:
if(count==20) 定时1s //可改写时间
{
//编写相关代码程序
}
}
蓝桥杯-定时器&计数器模块
于 2023-03-03 13:47:41 首次发布