找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 180|回复: 1
打印 上一主题 下一主题
收起左侧

仿真LCD1602不亮

[复制链接]
跳转到指定楼层
楼主


求问为什么这个仿真lcd1602 不亮啊而且高低电平也没有显示
#include "lcd1602.h"
#include "stm32f1xx_hal.h"
#include "delay.h"

static void LCD_Enable(void);
static void LCD_Write8Bits(uint8_t data)
{
    HAL_GPIO_WritePin(LCD_DATA_PORT, LCD_D0_PIN, (data & 0x01) ? GPIO_PIN_SET : GPIO_PIN_RESET);
    HAL_GPIO_WritePin(LCD_DATA_PORT, LCD_D1_PIN, (data & 0x02) ? GPIO_PIN_SET : GPIO_PIN_RESET);
    HAL_GPIO_WritePin(LCD_DATA_PORT, LCD_D2_PIN, (data & 0x04) ? GPIO_PIN_SET : GPIO_PIN_RESET);
    HAL_GPIO_WritePin(LCD_DATA_PORT, LCD_D3_PIN, (data & 0x08) ? GPIO_PIN_SET : GPIO_PIN_RESET);
    HAL_GPIO_WritePin(LCD_DATA_PORT, LCD_D4_PIN, (data & 0x10) ? GPIO_PIN_SET : GPIO_PIN_RESET);
    HAL_GPIO_WritePin(LCD_DATA_PORT, LCD_D5_PIN, (data & 0x20) ? GPIO_PIN_SET : GPIO_PIN_RESET);
    HAL_GPIO_WritePin(LCD_DATA_PORT, LCD_D6_PIN, (data & 0x40) ? GPIO_PIN_SET : GPIO_PIN_RESET);
    HAL_GPIO_WritePin(LCD_DATA_PORT, LCD_D7_PIN, (data & 0x80) ? GPIO_PIN_SET : GPIO_PIN_RESET);

    LCD_Enable();
}

void LCD_Init(void) {
    HAL_Delay(50);

}
void LCD_SendCommand(uint8_t cmd) {
    HAL_GPIO_WritePin(LCD_CTRL_PORT, LCD_RS_PIN, GPIO_PIN_RESET);
    HAL_GPIO_WritePin(LCD_CTRL_PORT, LCD_RW_PIN, GPIO_PIN_RESET);

    LCD_Write8Bits(cmd >> 8);
    LCD_Write8Bits(cmd & 0x0F);
}

void LCD_SendData(uint8_t data) {
    HAL_GPIO_WritePin(LCD_CTRL_PORT, LCD_RS_PIN, GPIO_PIN_SET);
    HAL_GPIO_WritePin(LCD_CTRL_PORT, LCD_RW_PIN, GPIO_PIN_RESET);

    LCD_Write8Bits(data >> 4);
    LCD_Write8Bits(data & 0x0F);
}

static void LCD_Enable(void) {
    HAL_GPIO_WritePin(LCD_CTRL_PORT, LCD_EN_PIN, GPIO_PIN_RESET);
    Delay_us(1);
    HAL_GPIO_WritePin(LCD_CTRL_PORT, LCD_EN_PIN, GPIO_PIN_SET);
    Delay_us(1);
    HAL_GPIO_WritePin(LCD_CTRL_PORT, LCD_EN_PIN, GPIO_PIN_RESET);
    Delay_us(100);
}

void LCD_SendString(char *str) {
    while (*str) {
        LCD_SendData(*str++);
    }
}

void LCD_SetCursor(uint8_t row, uint8_t col) {
    uint8_t address = (row == 0) ? (0x80 + col) : (0xC0 + col);
    LCD_SendCommand(address);
}

void LCD_Clear(void) {
    LCD_SendCommand(0x01);
    HAL_Delay(2);
}
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:940483 发表于 2025-4-14 15:37 | 只看该作者
LCD_Init()你这里面初始化函数哪里去了?怎么只有个延时
GPIO也没有配成输出模式
还有你的数据发送逻辑,高4位,低四位都没分清楚啊
估计还有错,暂且看出这么多
LCD1602指导手册认真多看两遍
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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