求大神帮助!为什么我的程序没有显示的?
线我检查过了,一共接8根,没有接错。
延时函数用的原子哥的,没放上来。
- #ifndef __LCD12864_H
- #define __LCD12864_H
- #include "STM32f10x.h"
- #define LCD12864_GPIO_APBxClock_FUN RCC_APB2PeriphClockCmd
- #define LCD12864_SCL_GPIO_CLK RCC_APB2Periph_GPIOB
- #define LCD12864_SCL_PORT GPIOB
- #define LCD12864_SCL_PIN GPIO_Pin_6
- #define LCD12864_SDA_GPIO_CLK RCC_APB2Periph_GPIOB
- #define LCD12864_SDA_PORT GPIOB
- #define LCD12864_SDA_PIN GPIO_Pin_7
- #define LCD12864_CS_GPIO_CLK RCC_APB2Periph_GPIOB
- #define LCD12864_CS_PORT GPIOB
- #define LCD12864_CS_PIN GPIO_Pin_8
- #define SCL_H GPIO_SetBits(LCD12864_SCL_PORT, LCD12864_SCL_PIN)
- #define SCL_L GPIO_ResetBits(LCD12864_SCL_PORT, LCD12864_SCL_PIN)
- #define SDA_H GPIO_SetBits(LCD12864_SDA_PORT, LCD12864_SDA_PIN)
- #define SDA_L GPIO_ResetBits(LCD12864_SDA_PORT, LCD12864_SDA_PIN)
- #define CS_H GPIO_SetBits(LCD12864_CS_PORT, LCD12864_CS_PIN)
- #define CS_L GPIO_ResetBits(LCD12864_CS_PORT, LCD12864_CS_PIN)
- void LCD12864_Init(void);
- void LCD12864_Write_Com( unsigned char cmdcode );
- void LCD12864_Write_Data( unsigned char Dispdata );
- void LCD12864_display(unsigned char line,unsigned char row,unsigned char data);
- void LCD12864_displays(uint8_t line,uint8_t row,unsigned char *data);
- void LCD12864_display_Init(void);
- #endif /* __LCD12864_H */
复制代码- #include "lcd12864.h"
- #include "delay.h"
- //ÅäÖÃLCD12864µÄGPIOģʽ
- void LCD12864_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- LCD12864_GPIO_APBxClock_FUN(LCD12864_SCL_GPIO_CLK,ENABLE);
- LCD12864_GPIO_APBxClock_FUN(LCD12864_SDA_GPIO_CLK,ENABLE);
- LCD12864_GPIO_APBxClock_FUN(LCD12864_CS_GPIO_CLK,ENABLE);
-
- // ½« SCL µÄGPIOÅäÖÃΪÍÆÍ츴ÓÃģʽ
- GPIO_InitStructure.GPIO_Pin = LCD12864_SCL_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(LCD12864_SCL_PORT, &GPIO_InitStructure);
-
- // ½« SDA µÄGPIOÅäÖÃΪÍÆÍ츴ÓÃģʽ
- GPIO_InitStructure.GPIO_Pin = LCD12864_SDA_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(LCD12864_SDA_PORT, &GPIO_InitStructure);
-
- // ½« CS µÄGPIOÅäÖÃΪÍÆÍ츴ÓÃģʽ
- GPIO_InitStructure.GPIO_Pin = LCD12864_CS_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(LCD12864_CS_PORT, &GPIO_InitStructure);
-
- SCL_L;
- CS_L;
-
- }
- /*
- * @brief ÏòLCD12864·¢ËÍÒ»¸ö×Ö½Ú
- * @param ÎÞ
- * @retval ÎÞ
-
- */
-
- static void LCD12864_Send_Byte( unsigned char data )
- {
- uint8_t i;
- for(i = 0;i < 8;i++)
- {
- if((data << i) & 0x80)
- {
- SDA_H;
- }
- else
- {
- SDA_L;
- }
- SCL_H;
- delay_us(4);
- SCL_L;
- delay_us(4);
- }
- }
- /*
- * @brief ÏòLCD12864д¿ØÖÆÖ¸Áî
- * @param ÎÞ
- * @retval ÎÞ
- */
- void LCD12864_Write_Com( unsigned char cmdcode )
- {
- CS_H;
- LCD12864_Send_Byte(0xf8);
- LCD12864_Send_Byte(cmdcode & 0xf0);
- LCD12864_Send_Byte((cmdcode << 4) & 0xf0);
- CS_L;
- delay_us(500);
- }
- /*
- * @brief ÏòLCD12864дÏÔʾµÄÊý¾Ý
- * @param ÎÞ
- * @retval ÎÞ
- */
- void LCD12864_Write_Data( unsigned char Dispdata )
- {
- CS_H;
- LCD12864_Send_Byte(0xfa);
- LCD12864_Send_Byte(Dispdata & 0xf0);
- LCD12864_Send_Byte((Dispdata << 4));
- CS_L;
- delay_us(500);
- }
- //Ïò¹æ¶¨ÐкÍÁÐдÈëÊý¾Ý
- void LCD12864_display(unsigned char line,unsigned char row,unsigned char data)
- {
- switch(line)
- {
- case 1: LCD12864_Write_Com(0x80+row); break;
- case 2: LCD12864_Write_Com(0x90+row); break;
- case 3: LCD12864_Write_Com(0x88+row); break;
- case 4: LCD12864_Write_Com(0x98+row); break;
- }
- LCD12864_Write_Data(data);
-
- }
- //Ïò¹æ¶¨ÐкÍÁÐдÈë¶à¸öÊý¾Ý
- void LCD12864_displays(uint8_t line,uint8_t row,unsigned char *data)
- {
- switch(line)
- {
- case 1: LCD12864_Write_Com(0x80+row); break;
- case 2: LCD12864_Write_Com(0x90+row); break;
- case 3: LCD12864_Write_Com(0x88+row); break;
- case 4: LCD12864_Write_Com(0x98+row); break;
- }
- //LCD12864_Write_Data(*data);
- while(*data!=' ')
- {
- LCD12864_Write_Data( *data );
- data++;
- }
- }
- //
- void LCD12864_display_Init(void)
- {
- LCD12864_Write_Com(0x30);
- LCD12864_Write_Com(0x01);
- delay_ms(10);
- LCD12864_Write_Com(0x02);
- delay_ms(10);
- LCD12864_Write_Com(0x0c);
- LCD12864_Write_Com(0x81);
- }
复制代码- #include "stm32f10x.h"
- #include "lcd12864.h"
- #include "delay.h"
- int main(void)
- {
- unsigned char shuzu[]={"wo shi shui ne?"};
- unsigned char shuzu1[]={"¸´ºÏ¹"};
- LCD12864_Init();
- LCD12864_display_Init();
- LCD12864_Write_Data('a');
- LCD12864_displays(2,1,shuzu);
- LCD12864_displays(3,1,shuzu1);
-
- while(1)
- {
- }
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>