第一范文网 - 专业文章范例文档资料分享平台

stm32控制 lcd1602 并且测试通过

来源:用户分享 时间:2025/5/23 17:09:56 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

//PD15-PD8 对应 LCD1602的D7-D0 //PC0 RS //PC1 WR //PC2 E

#include\

//LCD1602 的命令 状态

#define Set_RS() GPIO_SetBits(GPIOC,GPIO_Pin_0); // 数据

#define Reset_RS() GPIO_ResetBits(GPIOC,GPIO_Pin_0); // 命令 状态

#define Set_RW() GPIO_SetBits(GPIOC,GPIO_Pin_1); // 读 #define Reset_RW() GPIO_ResetBits(GPIOC,GPIO_Pin_1);// 写

#define Set_E() GPIO_SetBits(GPIOC,GPIO_Pin_2); // 使能 #define Reset_E() GPIO_ResetBits(GPIOC,GPIO_Pin_2);// 失能 uint8_t Buffer1[]={\

uint8_t Buffer2[]={%uint8_t Buffer[];

GPIO_InitTypeDef GPIO_InitStructure;

void RCC_Config(void); void GPIO_Config(void); void Busy_Wait(void);

void Write_Cmd(uint8_t Cmd); void Write_Data(uint8_t Data);

void Write_String(uint8_t cmd,uint8_t* p); void LCD1602_Init(void); void Delay(uint32_t t); //uint8_t Read_Data(void);

int main(void) {

RCC_Config(); GPIO_Config(); LCD1602_Init();

Write_String(0x80,Buffer1); Write_String(0xc0,Buffer2); while(1);

}

void RCC_Config(void) {

SystemInit();

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO,ENABLE); }

void GPIO_Config(void) {

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOD,&GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2; GPIO_Init(GPIOC,&GPIO_InitStructure); }

void Busy_Wait(void) {

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD,&GPIO_InitStructure);

Reset_RS(); Set_RW(); Reset_E(); //Delay(5); Set_E(); // Delay(25);

while(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_15)==1);

Reset_E(); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOD,&GPIO_InitStructure); }

void Write_Cmd(uint8_t Cmd) {

Busy_Wait(); Reset_RS(); Reset_RW(); Reset_E();

// Delay(5); Set_E();

GPIO_Write(GPIOD,(0xff00&(Cmd<<8))); /*

GPIO_WriteBit(GPIOE,GPIO_Pin_10,(BitAction)((Cmd&0x80)>>7));//D7 GPIO_WriteBit(GPIOE,GPIO_Pin_9,(BitAction)((Cmd&0x40)>>6)); //D6 GPIO_WriteBit(GPIOE,GPIO_Pin_8,(BitAction)((Cmd&0x20)>>5)); //D5 GPIO_WriteBit(GPIOE,GPIO_Pin_7,(BitAction)((Cmd&0x10)>>4)); //D4 GPIO_WriteBit(GPIOD,GPIO_Pin_1,(BitAction)((Cmd&0x08)>>3)); //D3 GPIO_WriteBit(GPIOD,GPIO_Pin_0,(BitAction)((Cmd&0x04)>>2)); //D2 GPIO_WriteBit(GPIOD,GPIO_Pin_15,(BitAction)((Cmd&0x02)>>1)); //D1 GPIO_WriteBit(GPIOD,GPIO_Pin_14,(BitAction)((Cmd&0x01))); //D0 */

//Delay(25); Reset_E(); }

void Write_Data(uint8_t Data) {

Busy_Wait(); Set_RS(); Reset_RW(); Reset_E();

// Delay(5); Set_E();

GPIO_Write(GPIOD,(0xff00&(Data<<8)));

/*

GPIO_WriteBit(GPIOE,GPIO_Pin_10,(BitAction)((Data&0x80)>>7));//D7 GPIO_WriteBit(GPIOE,GPIO_Pin_9,(BitAction)((Data&0x40)>>6)); //D6 GPIO_WriteBit(GPIOE,GPIO_Pin_8,(BitAction)((Data&0x20)>>5)); //D5 GPIO_WriteBit(GPIOE,GPIO_Pin_7,(BitAction)((Data&0x10)>>4)); //D4 GPIO_WriteBit(GPIOD,GPIO_Pin_1,(BitAction)((Data&0x08)>>3)); //D3 GPIO_WriteBit(GPIOD,GPIO_Pin_0,(BitAction)((Data&0x04)>>2)); //D2 GPIO_WriteBit(GPIOD,GPIO_Pin_15,(BitAction)((Data&0x02)>>1)); //D1 GPIO_WriteBit(GPIOD,GPIO_Pin_14,(BitAction)((Data&0x01))); //D0 */

// Delay(25); Reset_E(); }

void Write_String(uint8_t cmd,uint8_t* p) {

//uint8_t i=0;

Write_Cmd(cmd); while(*p!='\\0') { Write_Data(*p++);

// Buffer[i++]=Read_Data(); } }

void LCD1602_Init(void) {

Write_Cmd(0x38); Write_Cmd(0x0c); Write_Cmd(0x06); Write_Cmd(0x01); }

//14ns

void Delay(__IO uint32_t t) {

while(t--); } /*

uint8_t Read_Data(void) {

uint8_t Value; Busy_Wait(); Reset_WR(); Reset_E(); Delay(5); Set_E();

Value=GPIO_ReadOutputDataBit(GPIOE,GPIO_Pin_10)||GPIO_ReadOutputDataBit(GPIOE,GPIO_Pin_9)||GPIO_ReadOutputDataBit(GPIOE,GPIO_Pin_8)||GPIO_ReadOutputDataBit(GPIOE,GPIO_Pin_7)||

GPIO_ReadOutputDataBit(GPIOD,GPIO_Pin_1)||GPIO_ReadOutputDataBit(GPIOD,GPIO_Pin_0)||GPIO_ReadOutputDataBit(GPIOD,GPIO_Pin_15)||GPIO_ReadOutputDataBit(GPIOD,GPIO_Pin_14); Delay(25); Reset_E(); return Value; } */

搜索更多关于: stm32控制 lcd1602 并且测试通过 的文档
stm32控制 lcd1602 并且测试通过.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c76v867am1w7zlrl1b2wa_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top