标题:
仿真LCD1602不亮
[打印本页]
作者:
哈哈125
时间:
2025-4-13 23:45
标题:
仿真LCD1602不亮
屏幕截图 2025-04-12 202159.png
(43.28 KB, 下载次数: 0)
下载附件
2025-4-13 23:42 上传
求问为什么这个仿真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);
}
作者:
Tonghao666
时间:
2025-4-14 15:37
LCD_Init()你这里面初始化函数哪里去了?怎么只有个延时
GPIO也没有配成输出模式
还有你的数据发送逻辑,高4位,低四位都没分清楚啊
估计还有错,暂且看出这么多
LCD1602指导手册认真多看两遍
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1