资源描述:
《stm32控制lcd1602并且测试通过》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、//PD15-PD8对应LCD1602的D7・D()RSWRE//PCO//PCI//PC2#includeMstm32flOx.hn//LCD1602的命令状态#defineSet_RS()GPIO_SetBits(GPIOC,GPIO_Pin_0);//数据#defineReset_RS()GPIO_ReselBits(GPIOC,GPIO_Pin_0);//命令状态#defineSet_RW()GPI0_SetBits(GP10C,GPI0_Pin_l);//读#defineReset_RW()GP
2、IO_ResetBits(GPIOC,GPIO_Pin_l);//写#defineSet_E()GPI0_SetBits(GPI0C,GPI0_Pin_2);//使能#defineReset_E()GPI0_ResetBits(GPI0C,GPI0_Pin_2);//失能uint8_tBufferl[]={HFGasdkkkH};uint8_tBuffer2[]={MCDABabcdefghijkr'};uint8_tBufferf];GPIO」nitTypeDefGPIOJnitStructure;vo
3、idRCC_Config(void);voidGPIO_Config(void);voidBusy_Wait(void);voidWrite_Cmd(uint8_tCmd);voidWrite_Data(uint8_tData);voidWrite_String(uint8_tcmd,uint8_t*p);voidLCD1602」nil(void);voidDelay(uint32_tt);//uint8_tRead_Data(void);intmain(void){RCC_Config();GPlO_C
4、onfig();LCD1602_Init();Write_String(0x80,Buffer1);Write_String(0xc0,Buffer2);while(l);voidRCC_Config(void){Systemlnit();RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD
5、RCC_APB2Periph_GPIOC
6、RCC_APB2Periph_AFIO,ENABLE);voidGPIO_Config(void)GPIOInitStructure.GPI
7、OPin=GPIOPinAll;GPIO」nitSuricture.GPIO_Mode二GPIO_Mode_Out_PP;GPIO」nitStnictu「e.GPIO_Speed二GPIO_Speed_50MHz;GPIOJnit(GPIOD,&GPIOJnitStructure);GPIOInitStructure.GPIOPin=GPIOPin0
8、GPIOPin1
9、GPIOPin2;GPIO_Init(GPIOC,&GPIO_InitStructure);}voidBusy_Wait(void){GP
10、IOInitStructure.GPIOPin=GPIOPinAll;GPIOInitStructure.GPIOMode=GPIOModeINFLOATING;GPIO」nil(GPIOD,&GPIO_InilSgclure);Reset_RS();Set_RW();Reset_E();//Delay(5);Set_E();//Delay(25);while(GPI0_ReadInputDataBit(GP10D,GPI0_Pin_15)==l);Reset_E();GPIOJnitStructure.
11、GPIO_Pin=GPIO_Pin_All;GPIO」nitStructure.GPIO_Mode二GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOD,&GPIO_InitStructure);voidWrite_Cmd(uint8_tCmd){Busy_Wait();Reset_RS();Reset_RW();Reset_,E();//Delay(5);Set_E();GPIO_Write(GPI
12、OD,(OxffO0&(Cmd«8)));GPIO_WriteBit(GPIOE,GPIO_Pin_10,(BitAction)((Cmd&0x80)»7));//D7GPIO_WriteBit(GPIOE,GPIO_Pin_9,(BitAction)((Cmd&0x40)»6));//D6GPIO_WriteBit(GPIOE,GPIO_Pin_8,(BitAction)((Cmd&0x20)»5));//D5GPIO_Wr