按鍵問題

麻煩各位幫我看看,我這程序按鍵只有第一次按下有效。比如,我設(shè)置了78H、60H、7BH三個(gè)按鍵功能,第一次按下三個(gè)鍵中的任意鍵會(huì)有各個(gè)按鍵的功能顯示,但后面再按按鍵就沒有反應(yīng)了 #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); //串口調(diào)試 void Init_UART0(); //串口初始化

/*********************************************************** * 延時(shí)函數(shù) ***********************************************************/ void delayms(uint xms) { uint i,j; for(i=xms;i>0;i--) for(j=110;j>0;j--); }

/*********************************************************** * 數(shù)碼管顯示 ***********************************************************/ void display() { // CH452_Write(CH452_DIG7 | 0 |CH452_BCD_DOT_X ); //顯示數(shù)碼管的第8位,并加顯小數(shù)點(diǎn) // CH452_Write(CH452_DIG6 | 3); //顯示數(shù)碼管的第7位 // CH452_Write(CH452_DIG5 | 2); //顯示數(shù)碼管的第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);

}

/********************************************************** * 處理按鍵值函數(shù) *************************************************************/ 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) //顯示時(shí)分 {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) //顯示開啟時(shí)間 {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) //顯示關(guān)閉時(shí)間 {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; }

/*********************************************************** * 顯示左循環(huán)函數(shù) *************************************************************/ void Init_UART0(void) { ES=0; //關(guān)串口中斷 AUXR |= 0x40; //定時(shí)器1工作在1T模式 SCON = 0x50; //8位模特率,無奇偶校驗(yàn)

}

void shife8() { uchar i; for(i=0;i<8;i++) { CH452_Write(CH452_LEFTCYC); //寫左循環(huán)命令 delayms(300); //移動(dòng)的速度控制 } } /*********************************************************** * 主函數(shù) *************************************************************/ void main() { //CH452_DOUT=1; // 設(shè)置該引腳為輸入方向 IE0=0; //設(shè)置CH452按鍵中斷 EX0=1; EA=1; CH452_Write(CH452_RESET); CH452_Write(CH452_BCD); // 選擇BCD譯碼方式,掃描極限為8個(gè)數(shù)碼管 // CH452_Write(CH452_SELF_BCD ); // 選擇自定義BCD譯碼方式,掃描極限為8個(gè)數(shù)碼管 // CH452_Write(CH452_TWINKLE + 0x26);//設(shè)置閃爍控制,0x26表示[0010 0110]: Init_UART0(); //串口初始化 //高四位的第2位數(shù)碼管閃爍,低四位的第2和第3位閃爍 CH452_Write(CH452_SYSON2); // 開啟顯示、鍵盤 display(); // 顯示 shife8(); //左循環(huán)8次

// CH452_Write(CH452_CLR_BIT |16); //段位清0,從第一位到第八位,從0段到第63段,剛好8個(gè)數(shù)碼管,8X8=64。 // CH452_Write(CH452_LEVEL|0x2b); //加載光柱,編碼小于光柱的會(huì)點(diǎn)亮,大于和等于光柱的都會(huì)熄滅 while(1) { CH452_Write(0); SEND_RS232(10,5); //串口調(diào)試輸出數(shù)據(jù)用

} }

/*********************************************************** * // INT0中斷服務(wù)程序 *************************************************************/ void int0_int(void) interrupt 0 //using 1 {

keyp=CH452_Read(); //按鍵值 keyp=workkeycode(keyp); //處理按鍵值

//CH452_Write(CH452_SLEEP); }


熱門產(chǎn)品 : USB3.0 HUB控制器:CH634

按鍵沒反應(yīng)需要檢查下你按鍵按下去之后,中斷引腳有沒有拉低。還有讀取完成之后中斷引腳有沒有拉高。


要按兩下才會(huì)拉低,之后就不會(huì)拉高了。不過按一下雖然沒有拉低,但數(shù)碼管的顯示值有變化


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频