STC89C52与LCD1602液晶显示的软硬件仿真

STC89C52与LCD1602液晶显示的软硬件仿真

硬件仿真平台:protues8.13
软件仿真平台:keil5

硬件连接图:
在这里插入图片描述
软件代码实现: (复制后 粘贴到keil5中,即可使用,无需修改)

#include <REGX52.H>

#define LCD_DATA P0       // 数据线连接 P0.0 - P0.7
#define RS P2_7           // RS 连接 P2.7
#define RW P2_6           // RW 连接 P2.6
#define E P2_5            // E 连接 P2.5

void delay(unsigned int ms) {
    unsigned int i, j;
    for (i = 0; i < ms; i++)
        for (j = 0; j < 110; j++);   // 根据实际情况调整延迟时间
}

void lcd_command(unsigned char command) {
    LCD_DATA = command;     // 将命令写入数据线
    RS = 0;                 // 设置为命令模式
    RW = 0;                 // 写入模式
    E = 1;                  // 使能信号置高
    delay(1);               // 稍作延时
    E = 0;                  // 使能信号置低
}

void lcd_data(unsigned char data1) {
    LCD_DATA = data1;        // 将数据写入数据线
    RS = 1;                 // 设置为数据模式
    RW = 0;                 // 写入模式
    E = 1;                  // 使能信号置高
    delay(1);               // 稍作延时
    E = 0;                  // 使能信号置低
}

void lcd_init() {
    lcd_command(0x38);      // 设置显示模式为2行、5x7点阵
    lcd_command(0x0C);      // 打开显示,关闭光标
    lcd_command(0x06);      // 光标右移
    lcd_command(0x01);      // 清除显示
    delay(5);               // 初始化需要一定的延时
}

void lcd_print_line1(const char *str) {
    lcd_command(0x80);      // 设置光标位置到第一行开头
    while (*str) {
        lcd_data(*str++);
    }
}

void lcd_print_line2(const char *str) {
    lcd_command(0xC0);      // 设置光标位置到第二行开头
    while (*str) {
        lcd_data(*str++);
    }
}

void main() {
    lcd_init();                 // 初始化液晶显示屏
    lcd_print_line1("hello ++ =="); // 显示 "hello world" 在第一行
    lcd_print_line2("Welcome to myblog");    // 显示 "hello me" 在第二行
    while (1);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

琅中之嶹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值