找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

帖子
查看: 315|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

仿真LCD1602不亮

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主


求問(wèn)為什么這個(gè)仿真lcd1602 不亮啊而且高低電平也沒(méi)有顯示
#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空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:940483 發(fā)表于 2025-4-14 15:37 | 只看該作者
LCD_Init()你這里面初始化函數(shù)哪里去了?怎么只有個(gè)延時(shí)
GPIO也沒(méi)有配成輸出模式
還有你的數(shù)據(jù)發(fā)送邏輯,高4位,低四位都沒(méi)分清楚啊
估計(jì)還有錯(cuò),暫且看出這么多
LCD1602指導(dǎo)手冊(cè)認(rèn)真多看兩遍
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表