|
這是按鍵掃描函數(shù)
unsigned char key_scan() {
static unsigned char key_lock = 0; // 按鍵鎖定標(biāo)志
// 檢測(cè)按鍵按下(低電平有效)
if(!KEY1 || !KEY2 || !KEY3 || !KEY4) {
if(key_lock == 0) { // 首次檢測(cè)到按下
delay_ms(20); // 消抖
key_lock = 1;
if(!KEY1) return KEY1_PRESS;
else if(!KEY2) return KEY2_PRESS;
else if(!KEY3) return KEY3_PRESS;
else if(!KEY4) return KEY4_PRESS;
}
}
else {
key_lock = 0; // 按鍵釋放
}
return KEY_UNPRESS;
}
這是主函數(shù)
void main() {
unsigned char key;
// 初始化
lcd1602_init();//LCD1602初始化
lcd1602_show_string(0, 0, "Braille System");
lcd1602_show_string(0, 1, "Select:");
// 初始化所有點(diǎn)為不凸起狀態(tài)
P1 = 0xFF;
P2 = 0xFF;
while(1) {
key = key_scan();
if(key == 1 && current_index > 0) { // 上一個(gè)
current_index--;
lcd1602_show_string(7, 1, braille_library[current_index].pinyin);
beep();
}
else if(key == 2 && current_index < BRAILLE_COUNT-1) { // 下一個(gè)
current_index++;
lcd1602_show_string(7, 1, braille_library[current_index].pinyin);
beep();
}
else if(key == 3) { // 顯示
show_braille_pattern(braille_library[current_index].dot_pattern);
lcd1602_show_string(0, 0, "Showing: ");
lcd1602_show_string(8, 0, braille_library[current_index].pinyin);
beep();
}
else if(key == 4) { // 確認(rèn)/返回
P1 = 0xFF; P2 = 0xFF;
lcd1602_show_string(0, 0, "Braille System");
lcd1602_show_string(0, 1, "Select:");
lcd1602_show_string(7, 1, braille_library[current_index].pinyin);
beep();
}
delay_ms(10);
}
}
我在proteus里面運(yùn)行,一開始能夠正常顯示,但是按鍵234就會(huì)顯示全部黑塊,然后再顯示一個(gè)黑塊,其他也操作不了了。
這到底是什么問題啊 球球各位大佬解答。!有點(diǎn)急。!
|
|