|
- #include "bsp_1602display.h"
- void Delay(uint32_t nCont)
- {
- for(;nCont>0;nCont--);
- }
- //----顯示-----//
- static void delay(uint16_t cnt)
- {
- for(;cnt!=0;cnt--);
- }
- void GPIO_Config1(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE,ENABLE);
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_Init(GPIOD,&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_10MHz;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_Init(GPIOE,&GPIO_InitStructure);
- }
- /*1602寫命令函數(shù)*/
- void WriteCmd(u8 cmd)
- {
- delay(10000);
- RS0;
- RW0;
- GPIO_Write(GPIOE,cmd);
- delay(5000);
- GPIO_ResetBits(GPIOD,GPIO_Pin_10);
- E1;
- delay(5000);
- GPIO_ResetBits(GPIOD,GPIO_Pin_10);
- }
- /*1602寫數(shù)據(jù)函數(shù)*/
- void WriteData(u8 Dat)
- {
- delay(10000);
- RS1;
- RW0;
- GPIO_ResetBits(GPIOD,GPIO_Pin_10);
- delay(5000);
- GPIO_Write(GPIOE,Dat);
- delay(5000);
- E1;
- delay(5000);
- GPIO_ResetBits(GPIOD,GPIO_Pin_10);
- }
- /*1602初始化函數(shù)*/
- void Init1602(void)
- {
- WriteCmd(0x38);
- delay(1000);
- WriteCmd(0x08);
- delay(1000);
- WriteCmd(0x01);
- delay(1000);
- WriteCmd(0x06);
- delay(1000);
- WriteCmd(0x0c);
- delay(1000);
- }
- void Set_xy(unsigned char x,unsigned char y)
- {
- unsigned char ss;
- if(x==0)
- ss=0x80+y;
- if(x==1)
- ss=0xc0+y;
- WriteCmd(ss);
- }
- void disp(unsigned char x,unsigned char y,unsigned char *s)
- {
- Set_xy(x,y);
- while(*s)
- {
- WriteData(*s);
- s++;
- }
- }
- void num_deal(unsigned char x,uint16_t data)
- {
- uint16_t a,b,c,d,e,f,g,h;
- a=data/10000000;
- b=data/1000000%10;
- c=data/100000%10;
- d=data/10000%10;
- e=data/1000%10;
- f=data/100%10;
- g=data/10%10;
- h=data%10;
- WriteCmd(0x80+x);
- WriteData(a+0x30);
- WriteData(b+0x30);
- WriteData(c+0x30);
- WriteData(d+0x30);
- WriteData(e+0x30);
- WriteData(f+0x30);
- WriteData(g+0x30);
- WriteData(h+0x30);
- }
復(fù)制代碼
比如說,我讓data等于123456,但是1602卻沒有任何反應(yīng)!字符可以顯示,是我最后一個函數(shù)有問題嗎!? |
|