Em bí rồi không biết sai chỗ nào nạp chạy thì không hiện lên màn hình. Nếu nó thông báo lỗi gì thì em còn fix đc còn vụ này thì em vô phương cứu chữa!
code:
#include"LcdTxt.h"
void WriteHighNibble(int8_t data){
if(data &0x80){
PIN_HIGH(LCD_PORT, D7_PIN);
}
else{
PIN_LOW(LCD_PORT, D7_PIN);
}
if(data &0x40){
PIN_HIGH(LCD_PORT, D6_PIN);
}
else{
PIN_LOW(LCD_PORT, D6_PIN);
}
if(data &0x20){
PIN_HIGH(LCD_PORT, D5_PIN);
}
else{
PIN_LOW(LCD_PORT, D5_PIN);
}
if(data &0x10){
PIN_HIGH(LCD_PORT, D4_PIN);
}
else{
PIN_LOW(LCD_PORT, D4_PIN);
}
}
void WriteLowNibble(int8_t data){
if(data &0x08){
PIN_HIGH(LCD_PORT, D7_PIN);
}
else{
PIN_LOW(LCD_PORT, D7_PIN);
}
if(data &0x04){
PIN_HIGH(LCD_PORT, D6_PIN);
}
else{
PIN_LOW(LCD_PORT, D6_PIN);
}
if(data &0x02){
PIN_HIGH(LCD_PORT, D5_PIN);
}
else{
PIN_LOW(LCD_PORT, D5_PIN);
}
if(data &0x01){
PIN_HIGH(LCD_PORT, D4_PIN);
}
else{
PIN_LOW(LCD_PORT, D4_PIN);
}
}
void LcdCMD(int8_t cmd){
PIN_LOW(LCD_PORT, RS_PIN);
WriteHighNibble(cmd);
PIN_HIGH(LCD_PORT, EN_PIN);
PIN_LOW(LCD_PORT, EN_PIN);
WriteLowNibble(cmd);
PIN_HIGH(LCD_PORT, EN_PIN);
PIN_LOW(LCD_PORT, EN_PIN);
HAL_Delay(2);
}
void LcdInit(void){
PIN_LOW(LCD_PORT, EN_PIN);
PIN_LOW(LCD_PORT, RS_PIN);
HAL_Delay(15);
WriteLowNibble(0x03);
PIN_HIGH(LCD_PORT, EN_PIN);
PIN_LOW(LCD_PORT, EN_PIN);
HAL_Delay(5);
WriteLowNibble(0x03);
PIN_HIGH(LCD_PORT, EN_PIN);
PIN_LOW(LCD_PORT, EN_PIN);
HAL_Delay(1);
WriteLowNibble(0x02);
PIN_HIGH(LCD_PORT, EN_PIN);
PIN_LOW(LCD_PORT, EN_PIN);
HAL_Delay(1);
LcdCMD(_LCD_4BIT_2LINE_5x7FONT);
LcdCMD(_LCD_TURN_ON);
LcdCMD(_LCD_CLEAR);
LcdCMD(_LCD_ENTRY_MODE);
}
void ShowChar(int8_t data){
PIN_HIGH(LCD_PORT, RS_PIN);
WriteHighNibble(data);
PIN_HIGH(LCD_PORT, EN_PIN);
PIN_LOW(LCD_PORT, EN_PIN);
WriteLowNibble(data);
PIN_HIGH(LCD_PORT, EN_PIN);
PIN_LOW(LCD_PORT, EN_PIN);
HAL_Delay(1);
}