麻烦各位帮我看看,我这程序按键只有第一次按下有效。比如,我设置了78H、60H、7BH三个按键功能,第一次按下三个键中的任意键会有各个按键的功能显示,但后面再按按键就没有反应了 #include #include #define uchar unsigned char #define uint unsigned int
#include "CH452W4.C" unsigned char minute=30,hour=12,second; unsigned char month=12,day=24,year1=20,year2=12; unsigned char minute1=30,hour1=20,minute2=30,hour2=11; unsigned char status=0; uchar keyp;
void SEND_RS232(uchar i,j); //串口调试 void Init_UART0(); //串口初始化
/*********************************************************** * 延时函数 ***********************************************************/ void delayms(uint xms) { uint i,j; for(i=xms;i>0;i--) for(j=110;j>0;j--); }
/*********************************************************** * 数码管显示 ***********************************************************/ void display() { // CH452_Write(CH452_DIG7 | 0 |CH452_BCD_DOT_X ); //显示数码管的第8位,并加显小数点 // CH452_Write(CH452_DIG6 | 3); //显示数码管的第7位 // CH452_Write(CH452_DIG5 | 2); //显示数码管的第6位 CH452_Write(CH452_DIG4 |year1/10); //显示年 CH452_Write(CH452_DIG3 |year1%10); CH452_Write(CH452_DIG2 |0x12); //显示"-" CH452_Write(CH452_DIG1 |year2/10); CH452_Write(CH452_DIG0 |year2%10);
}
/********************************************************** * 处理按键值函数 *************************************************************/ uchar workkeycode(uchar x) { uchar result; if(x==0x78) //显示月日 {delayms(10); if(x==0x78) status=1; while(!x); while(1) { CH452_Write(CH452_DIG0 |day%10); CH452_Write(CH452_DIG1 |day/10); CH452_Write(CH452_DIG2 |0x12); CH452_Write(CH452_DIG3 |month%10); CH452_Write(CH452_DIG4 |month/10); } } if(x==0x60) //显示时分 {delayms(10); if(x==0x60) status=2; while(!x); while(1) { CH452_Write(CH452_DIG0 |minute%10); CH452_Write(CH452_DIG1 |minute/10); CH452_Write(CH452_DIG2 |0x12); CH452_Write(CH452_DIG3 |hour%10); CH452_Write(CH452_DIG4 |hour/10); } } if(x==0x7B) //显示秒 {delayms(10); if(x==0x7B) status=3; while(!x); while(1) { CH452_Write(CH452_DIG0 |second%10); CH452_Write(CH452_DIG1 |second/10); CH452_Write(CH452_DIG2 |0x10); CH452_Write(CH452_DIG3 |0x10); CH452_Write(CH452_DIG4 |0x10); } } if(x==0x43) //显示开启时间 {delayms(10); if(x==0x43) status=4; while(!x); while(1) { CH452_Write(CH452_DIG0 |minute1%10); CH452_Write(CH452_DIG1 |minute1/10); CH452_Write(CH452_DIG2 |0x12); CH452_Write(CH452_DIG3 |hour1%10); CH452_Write(CH452_DIG4 |hour1/10); } } if(x==0x78) //显示关闭时间 {delayms(10); if(x==0x78) status=5; while(!x); while(1) { CH452_Write(CH452_DIG0 |minute2%10); CH452_Write(CH452_DIG1 |minute2/10); CH452_Write(CH452_DIG2 |0x12); CH452_Write(CH452_DIG3 |hour2%10); CH452_Write(CH452_DIG4 |hour2/10); } } return (result); }
void SEND_RS232 (uchar i,j) { TI=0; SBUF = i; while (TI==0); TI=0; SBUF = j; SBUF=0x00; while (TI==0); TI=0; }
/*********************************************************** * 显示左循环函数 *************************************************************/ void Init_UART0(void) { ES=0; //关串口中断 AUXR |= 0x40; //定时器1工作在1T模式 SCON = 0x50; //8位模特率,无奇偶校验
}
void shife8() { uchar i; for(i=0;i<8;i++) { CH452_Write(CH452_LEFTCYC); //写左循环命令 delayms(300); //移动的速度控制 } } /*********************************************************** * 主函数 *************************************************************/ void main() { //CH452_DOUT=1; // 设置该引脚为输入方向 IE0=0; //设置CH452按键中断 EX0=1; EA=1; CH452_Write(CH452_RESET); CH452_Write(CH452_BCD); // 选择BCD译码方式,扫描极限为8个数码管 // CH452_Write(CH452_SELF_BCD ); // 选择自定义BCD译码方式,扫描极限为8个数码管 // CH452_Write(CH452_TWINKLE + 0x26);//设置闪烁控制,0x26表示[0010 0110]: Init_UART0(); //串口初始化 //高四位的第2位数码管闪烁,低四位的第2和第3位闪烁 CH452_Write(CH452_SYSON2); // 开启显示、键盘 display(); // 显示 shife8(); //左循环8次
// CH452_Write(CH452_CLR_BIT |16); //段位清0,从第一位到第八位,从0段到第63段,刚好8个数码管,8X8=64。 // CH452_Write(CH452_LEVEL|0x2b); //加载光柱,编码小于光柱的会点亮,大于和等于光柱的都会熄灭 while(1) { CH452_Write(0); SEND_RS232(10,5); //串口调试输出数据用
} }
/*********************************************************** * // INT0中断服务程序 *************************************************************/ void int0_int(void) interrupt 0 //using 1 {
keyp=CH452_Read(); //按键值 keyp=workkeycode(keyp); //处理按键值
//CH452_Write(CH452_SLEEP); }