附录1 程序
#include
uchar tishi[]={\提示信息 uchar timeovr[]={\
extern signed char second,minute,hour,hour0; extern signed char pmin,phour,ps1;
#define SetTime(H,M,S) {second=S;minute=M;hour=H;hour0=H;} #define CPU_F ((double)8000000) //定义CPU 的时钟频率为8M #define
delay_us(x)
__delay_cycles((long)(CPU_F*(double)x/1000000.0))// 定义延时1us #define
delay_ms(x)
__delay_cycles((long)(CPU_F*(double)x/1000.0)) // 定义延时1ms
#define keyin (P3IN & 0x0f)
#define IR_DIR_IN P1DIR&=~BIT5 //红外接收头P1.5设置为输入
31
#define IRIN (P1IN&BIT5) //红外接收头输入值 uchar keypress,keypress1; char dat[8]; void Clock_Init() {
uchar i;
BCSCTL1&=~XT2OFF; //START XT2(8MHZ) BCSCTL2|=SELM1+SELS;
do{ //等待时钟转换 IFG1&=~OFIFG; for(i=0;i<100;i++) _NOP(); }
while((IFG1&OFIFG)!=0); IFG1&=~OFIFG; }
void keyscan1() {
if(keyin ==0x0e) //如果有键被按下
32
{
Delay5ms(); //延时消抖 if(keyin ==0x0e) //再次检测按键状态 {
keypress++;
while(keyin == 0x0e); //等待按键被放开 if(keypress==1) {
CCTL0&=~CCIE; LocateXY(11,1);
LcdWriteCommand(0x0f,1); }
if(keypress==2) {
LocateXY(8,1); }
if(keypress==3) {
LocateXY(5,1); }
if(keypress==4) {
33
keypress=0;
LcdWriteCommand(0x0c,1); CCTL0|=CCIE; } } }
if(keypress!=0) {
if(keyin ==0x0d) {
//delay(); if(keyin ==0x0d) {
while(keyin==0x0d); if(keypress==1) {
second+=1; if(second==60) second=0; Display(); LocateXY(11,1);
34
}
if(keypress==2) {
minute+=1; if(minute==60) minute=0; Display(); LocateXY(8,1); }
if(keypress==3) {
hour+=1; if(hour==24) hour=0; Display(); LocateXY(5,1); } } }
if(keyin==0x0b) {
// delay();
35