本人學生菜鳥一枚,剛從51渡過。打算把51上實現的功能在stm32上面實現一遍, 遇到5v的1602 用了很長時間才搞定。目前所有的io口都是用的sn74h245來驅動的。 我遇到的問題就是 stm32 3.3v 驅動不了 還有就是延時的問題 ,有興趣的可以試試。
stm32單片機源程序如下:
- #include "stm32f10x.h"
- #include "delay.h"
- #define Set_RS GPIO_SetBits(GPIOB,GPIO_Pin_15)
- //#define Set_RW GPIO_SetBits(GPIOB,GPIO_Pin_3)
- #define Set_EN GPIO_SetBits(GPIOB,GPIO_Pin_2)
- #define CLR_RS GPIO_ResetBits(GPIOB,GPIO_Pin_15)
- #define CLR_RW GPIO_ResetBits(GPIOB,GPIO_Pin_3)
- #define CLR_EN GPIO_ResetBits(GPIOB,GPIO_Pin_2)
- GPIO_InitTypeDef GPIO_InitStructure;
- unsigned char table[]="You are big Pig";
- void Send_Com(unsigned char Send_Com)
- {
- CLR_RS;
- GPIO_Write(GPIOA,Send_Com);
- Delay_ms(10);
- Set_EN;
- Delay_ms(10);
- CLR_EN;
- }
- void Send_Dat(unsigned char Send_Dat)
- {
- Set_RS;
- GPIO_Write(GPIOA,Send_Dat);
- Delay_ms(10);
- Set_EN;
- Delay_ms(10);
- CLR_EN;
- }
- void init()
- {
- CLR_EN;
- Send_Com(0x38);
- Send_Com(0x0c);
-
- Send_Com(0x06);
-
- Send_Com(0x01);
- }
- void GPIO_Configuration(void)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
-
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_15|GPIO_Pin_3|GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB,&GPIO_InitStructure);
-
-
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_Init(GPIOA,&GPIO_InitStructure);
- }
- int main(void)
- {
- unsigned char num;
- GPIO_Configuration();
- init();
- Send_Com(0x80);
- for(num=0;num<=14;num++)
- {
- Send_Dat(table[num]);
- Delay_ms(10);
- }
- while(1);
- }
復制代碼
所有資料51hei提供下載:
1602液晶顯示.rar
(216.63 KB, 下載次數: 107)
2018-10-24 01:11 上傳
點擊文件名下載附件
|