找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 611|回复: 3
收起左侧

为什么按下按键后LCD1602全部黑块然后不能再操作了?球球大家解答

[复制链接]
ID:1149720 发表于 2025-5-7 02:13 | 显示全部楼层 |阅读模式
这是按键扫描函数
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就会显示全部黑块,然后再显示一个黑块,其他也操作不了了。
这到底是什么问题啊球球各位大佬解答!!!有点急!!!
回复

使用道具 举报

ID:1149734 发表于 2025-5-7 09:42 | 显示全部楼层
a按键扫描存在问题
回复

使用道具 举报

ID:584814 发表于 2025-5-7 10:04 | 显示全部楼层
检查接线,想解决问题就上完整的工程文件,大神不会跳神。
回复

使用道具 举报

ID:844772 发表于 2025-5-7 11:01 | 显示全部楼层
给看看怎么接线的;还有lcd的程序。不过,很多时候就是简单的宏定义错落。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表