#include <STC8H.h>
#define uchar unsigned char
#define uint unsigned int
sbit JR_JDQ = P1^7;
sbit JS_JDQ = P1^5;
sbit FMQ = P1^6;
sbit DCF_JDQ = P1^4;
sbit KEY1 = P1^1;
sbit ID1 = P3^3;
sbit ID2 = P3^4;
sbit ID3 = P3^5;
bit t0zd0b=0;
void TM0_init() //250us
{
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x1A; //设置定时初始值
TH0 = 0xFF; //设置定时初始值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
EA = 1; //开总中断
ET0 = 1; //开T0中断
}
/*
必须开启T0中断,延时函数才起作用
*/
void delay_1ms(void)
{
uchar i = 4; //每次256us,1ms中断4次
while (i) {
if (t0zd0b)
{
t0zd0b = 0; //清除时间中断标志
--i;
}
}
}
void delay_ms(uint var)//延时单位为毫秒,最多延时65.535秒(65535mS)
{
while (var--)
{
delay_1ms();
}
}
#define d_s(s) delay_ms((s)*1000ul)//延时单位为秒
void IO_init()
{
P1M0 = 0x00;
P1M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
}
void TM0_Isr() interrupt 1
{
if(TF0)
TF0=0;
t0zd0b=1;
}
void main()
{
IO_init();
TM0_init();
while (1)
{
if(KEY1 == 1 && ID1 == 1)
{
JR_JDQ = 1;d_s(1);
JS_JDQ = 1;d_s(1);
}
else if(KEY1 == 1 && ID2 == 1)
{
FMQ = 1;d_s(1);
DCF_JDQ = 1;d_s(1);
}
else if(KEY1 == 1 && ID3 == 1)
{
JR_JDQ = 0;d_s(1);
JS_JDQ = 0;d_s(1);
FMQ = 0;d_s(1);
DCF_JDQ = 0;d_s(1);
}
}
} |