(基于51核的STC12C5A60S2,keil uvision5 mdk 5.25 编译)
#include <STC12C5A60S2.h>
//选择对应的代码进行测试 1——运行,0——不运行
sbit LED1 = P2 ^ 4;
sbit LED2 = P2 ^ 5;
sbit LED3 = P2 ^ 6;
sbit LED4 = P2 ^ 7;
sbit BEEP = P1 ^ 0; //置1则响
sbit KEY1 = P3 ^ 2;
sbit KEY2 = P3 ^ 4;
//---------------------------------------------------------------------
unsigned char TimerFlag=0;
//---------------------------------------------------------------------
void Timer0_Init()
{
TH0 = 0xd8; //设置定时器0的初始值10ms
TL0 = 0xf0;
TMOD = 0x01; //定时器0工作方式
TR0 = 1; //启动定时器0
ET0 = 1; //打开定时器0中断
EA = 1; //打开中断允许总控制
}
void Timer0() interrupt 1
{
TH0 = 0xd8; //重新设置定时器0的初始值
TL0 = 0xf0;
TimerFlag=1;
}
void Delay_n_10ms(unsigned int num)
{
TimerFlag=0;
while(num!=0)
{
if(TimerFlag==