#include "main.h" #define RELOAD (65535-9216) //定时器填充值(1ms) unsigned char TH, TL; extern Menu *NOW; //菜单指针 extern enum OPR opr; //按键状态 unsigned char freshScreenTriger = 0; void int0() interrupt 0 //外部中断:检测左右旋钮 { // IE0 = 0; //消抖 // delay(20); // IE0 = 0; // // if(PIN_3 == 0) // { // delay(10); // if(PIN_3 == 0) // opr = left; // } // else if(PIN_3 == 1) // { // delay(10); // if(PIN_3 == 1) // opr = right; // } unsigned char LS, CS, flag = 0; LS = PIN_3; while(!PIN_1) { CS = PIN_3; flag = 1; } if(flag == 1) { if((LS == 0) && (CS == 1)) opr = right; if((LS == 1) && (CS == 0)) opr = left; } } void time() interrupt 1 //定时中断:检测确认按键 { EA = 0; TH0 = TH; TL0 = TL0 + TL; TL0 = TL0 + 23; if(PIN_4 == 0) { delay(50); if(PIN_4 == 0) opr = confirm; } EA = 1; } int main() { TH = RELOAD / 256; //填充值预计算 TL = RELOAD - (RELOAD / 256) * 256; TH0 = TH; TL0 = TL; TMOD = 0x01; //使用定时器T0,高4位全为0,低4位GATE=0,C/T=0,采用工作方式1,M1=0,M1=1 TR0 = 1; //启动定时器0 EA = 1; //打开中断总开关 ET0 = 1; //打开定时器0中断开关 IT0 = 1; //中断触发方式为下边沿触发 EX0 = 1; //打开外部中断0 EA = 1; //打开中断总开关 displayInit(); //屏幕初始化 clear(); menuInit(); //菜单及其他初始化 while(1) { NOW->f(NOW); } }