屏幕截圖 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);
}
|