立即注册 登录
返回首页

uid:471403的个人空间

日志

stm32链接lcd1602 四线驱动 解决乱码

已有 1722 次阅读2019-2-9 14:55

void Init_LCD1602() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); write_com(0x28); delay_ms(30); write_com(0x01); delay_ms(30); write_com(0x06); delay_ms(30); write_com(0x0c); delay_ms(30); } /******************指令************************/ void write_com(u8 com) { rs=0; rw=0; en=1; GPIO_Write(GPIOA,com/16*16); en=0; en=1; GPIO_Write(GPIOA,com%16*16); en=1; en=0; } /*******************数据 乱码在硬件下正常的情况下,主要为高四位和低四位的冲突,表现为只发其中之一,忽略再次使能************************/ void write_dat(u8 date) { rs=1; rw=0; en=1; GPIO_Write(GPIOA,date/16*16); //先发高四位 en=0; en=1; GPIO_Write(GPIOA,date%16*16);//再发低四位 en=1; en=0; }
#ifndef __1602_H 
#define __1602_H 

#include "sys.h"

#define rs PBout(0) 
#define rw PBout(1)
#define en PBout(2) 

void Init_LCD1602(void); 
void write_com(unsigned char com); 
void write_dat(unsigned char date); 
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal); 

#endif

路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

返回顶部