大家仔细看看STM32驱动LCD1602液晶和51单片机区别有多大? ?? ?? ?? ?? ?前两天在百度里面看到很多网友在,求救STM32驱动LCD1602液晶问题,自己也想把LCD1602液晶用STM32来驱动一下,悲剧的是自己的学习板上没有LCD1602液晶,就有一个TIF 彩屏,无奈之下把以前51单片机用过的LCD1602液晶用万能板焊接后,用杜邦线连接到STM32开发板IO上,刚开始调试没有想像的那么理想,不过自己坚信STM32单片机一定可以向51单片机那样简单灵活的驱动LCD1602,连焊板子带调试整整用了两个晚上,首先介绍一下我在调试过程中遇到的问题,STM32单片机IO口驱动能力差,电压3.3V不像51单片机5v,所以LCD1602液晶驱动不起来,这里硬件电路所有IO口用10K电阻上拉来提升IO口驱动能力。电压是5V电压,大家也可以采用74HC245来驱动。程序是刚刚出炉的。
/************************************************************************************? ?? ? STM32 驱动 LCD1602 液晶程序***************************************************************************************/#ifndef? ?? ?? ?? ?? ? _LCD1602_H#define? ?? ?? ?? ?? ? _LCD1602_H#include "lcd1602.h"#include "SysTick.h"/***************************低电平************************************/#define? ?? ?LCD1602_RS0? ?? ? GPIOE->BRR??= 0x00000004? ?//RS低电平#define? ?? ?LCD1602_RW0? ?? ? GPIOE->BRR??= 0x00000010? ?//RW低电平#define? ?? ?LCD1602_EN0? ?? ? GPIOE->BRR??= 0x00000040? ?//EN低电平/****************************高电平***********************************/#define? ?? ?LCD1602_RS1? ?? ? GPIOE->BSRR = 0x00000004? ?//RS高电平#dRefine? ???LCD1602_RW1? ?? ? GPIOE->BSRR = 0x00000010? ?//RW低电平#define? ?? ?LCD1602_EN1? ?? ? GPIOE->BSRR = 0x00000040? ?//EN低电平#define? ?? ?DATA_OUT? ?? ?? ? GPIOD->ODR??//定义数据端口 PB0-PB7unsigned char? ?value_table[]={0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38 , 0x39};//BCD码0-9void Init_LCD1602(void);? ? //初始化子函数void Writr_LCD1602_BEENLOOK_Com(unsigned char Com);??//LCD1602液晶写指令void Writr_LCD1602_BEENLOOK_Data(unsigned char Date); //LCD1602液晶写数据void Write_LCD1602_BEENLOOK_Com_Data(unsigned char CountLine, unsigned char Date);//写指令和写数据?//==============================================================================////LCD1602液晶写指令void Writr_LCD1602_BEENLOOK_Com(unsigned char Com){LCD1602_RS0;LCD1602_RW0;LCD1602_EN0;DATA_OUT = Com;Delay_1ms(1);LCD1602_EN1;Delay_1ms(1);LCD1602_EN0;}//==============================================================================////LCD1602液晶写数据void Writr_LCD1602_BEENLOOK_Data(unsigned char Date){LCD1602_RS1;LCD1602_RW0;LCD1602_EN0;DATA_OUT = Date;Delay_1ms(1);LCD1602_EN1;Delay_1ms(1);LCD1602_EN0;}//==============================================================================////LCD1602液晶写指令和写数据void Write_LCD1602_BEENLOOK_Com_Data(unsigned char CountLine, unsigned char Date){if(CountLine == 0)? ?? ? //如果CountLine == 0{??Writr_LCD1602_BEENLOOK_Com(Date);??//等于0写指令}else? ?? ?? ? //否则写数据{??Writr_LCD1602_BEENLOOK_Data(Date);?}}//==============================================================================////LCD1602液晶初始化指令void Init_LCD1602(void){Writr_LCD1602_BEENLOOK_Com(0x38);Delay_1ms(1);?Writr_LCD1602_BEENLOOK_Com(0x0C);Delay_1ms(1);Writr_LCD1602_BEENLOOK_Com(0x06);Delay_1ms(1);Writr_LCD1602_BEENLOOK_Com(0x01);Delay_1ms(1);?}#endif/***************************************END****************************************/
STM32驱动LCD1602液晶程序_lcd1602程序