这是按键扫描函数
unsigned char key_scan() {
static unsigned char key_lock = 0; // 按键锁定标志
// 检测按键按下(低电平有效)
if(!KEY1 || !KEY2 || !KEY3 || !KEY4) {
if(key_lock == 0) { // 首次检测到按下
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;
}
这是主函数
void main() {
unsigned char key;
// 初始化
lcd1602_init();//LCD1602初始化
lcd1602_show_string(0, 0, "Braille System");
lcd1602_show_string(0, 1, "Select:");
// 初始化所有点为不凸起状态
P1 = 0xFF;
P2 = 0xFF;
while(1) {
key = key_scan();
if(key == 1 && current_index > 0) { // 上一个
current_index--;
lcd1602_show_string(7, 1, braille_library[current_index].pinyin);
beep();
}
else if(key == 2 && current_index < BRAILLE_COUNT-1) { // 下一个
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) { // 确认/返回
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里面运行,一开始能够正常显示,但是按键234就会显示全部黑块,然后再显示一个黑块,其他也操作不了了。
这到底是什么问题啊 球球各位大佬解答!!!有点急!!!
|