初中生
最后登录1970-1-1
在线时间 小时
注册时间2018-4-3
|
初学STM32f103想写一个DS1602的代码。但是写完烧进去发现液晶只亮屏,代码如下。
uint8_t LCD_Wait_Ready(void)
{
uint8_t status;
LCD_RS_OUT();
LCD_RW_OUT();
LCD_EN_OUT();
GPIOA->ODR = 0xFF;
RS_OUT = 0;
RW_OUT = 1;
EN_OUT = 1;
HAL_Delay(5);
status = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_7);
EN_OUT = 0;
return status;
}
void LCD_WriteCom(uint8_t com)
{
LCD_RS_OUT();
LCD_RW_OUT();
LCD_EN_OUT();
while( LCD_Wait_Ready() );
RS_OUT = 0;
RW_OUT = 0;
GPIOA->ODR = com;
HAL_Delay(5);
EN_OUT = 0;
HAL_Delay(5);
EN_OUT = 1;
}
void LCD_WriteData(uint8_t dat)
{
LCD_RS_OUT();
LCD_RW_OUT();
LCD_EN_OUT();
while( LCD_Wait_Ready() );
RS_OUT = 1;
RW_OUT = 0;
GPIOA->ODR = dat;
HAL_Delay(5);
EN_OUT = 0;
HAL_Delay(5);
EN_OUT = 1;
}
void LCD_Set_Cursor(uint8_t x, uint8_t y)
{
uint8_t addr;
if (y == 0)
addr = 0x00 + x;
else
addr = 0x40 + x;
LCD_WriteCom(addr | 0x80);
}
void LCD_Show_Str(uint8_t x, uint8_t y, uint8_t *str)
{
LCD_Set_Cursor(x, y);
while(*str != '\0')
{
LCD_WriteData(*str++);
}
}
void LCD_Init(void)
{
LCD_WriteCom(0x38); //16*2ÏÔʾ,5*7µãÕó,8Êý¾Ý¿Ú
LCD_WriteCom(0x0c); //¿ªÏÔʾ£¬¹â±ê¹Ø±Õ
LCD_WriteCom(0x06); //ÎÄ×Ö²»¶¯£¬µØÖ·×Ô¶¯+1
LCD_WriteCom(0x01); //ÇåÆÁ
}
|
|