stm32 LCD12864 串口无显示

2019-07-14 18:55发布

求大神帮助!为什么我的程序没有显示的?
线我检查过了,一共接8根,没有接错。



延时函数用的原子哥的,没放上来。
  1. #ifndef __LCD12864_H
  2. #define        __LCD12864_H

  3. #include "STM32f10x.h"

  4. #define         LCD12864_GPIO_APBxClock_FUN                 RCC_APB2PeriphClockCmd


  5. #define         LCD12864_SCL_GPIO_CLK                                         RCC_APB2Periph_GPIOB
  6. #define         LCD12864_SCL_PORT                                                         GPIOB
  7. #define         LCD12864_SCL_PIN                                                                 GPIO_Pin_6


  8. #define         LCD12864_SDA_GPIO_CLK                                         RCC_APB2Periph_GPIOB
  9. #define         LCD12864_SDA_PORT                                                                 GPIOB
  10. #define         LCD12864_SDA_PIN                                                                 GPIO_Pin_7

  11. #define         LCD12864_CS_GPIO_CLK                                           RCC_APB2Periph_GPIOB
  12. #define         LCD12864_CS_PORT                                                                 GPIOB
  13. #define         LCD12864_CS_PIN                                                                 GPIO_Pin_8


  14. #define   SCL_H                      GPIO_SetBits(LCD12864_SCL_PORT, LCD12864_SCL_PIN)
  15. #define         SCL_L                                        GPIO_ResetBits(LCD12864_SCL_PORT, LCD12864_SCL_PIN)

  16. #define   SDA_H                      GPIO_SetBits(LCD12864_SDA_PORT, LCD12864_SDA_PIN)
  17. #define         SDA_L                                        GPIO_ResetBits(LCD12864_SDA_PORT, LCD12864_SDA_PIN)

  18. #define   CS_H                      GPIO_SetBits(LCD12864_CS_PORT, LCD12864_CS_PIN)
  19. #define         CS_L                                        GPIO_ResetBits(LCD12864_CS_PORT, LCD12864_CS_PIN)


  20. void LCD12864_Init(void);
  21. void LCD12864_Write_Com( unsigned char cmdcode );
  22. void LCD12864_Write_Data( unsigned char Dispdata );
  23. void LCD12864_display(unsigned char line,unsigned char row,unsigned char data);
  24. void LCD12864_displays(uint8_t line,uint8_t row,unsigned char *data);
  25. void LCD12864_display_Init(void);


  26. #endif /* __LCD12864_H */
复制代码
  1. #include  "lcd12864.h"
  2. #include "delay.h"


  3. //ÅäÖÃLCD12864µÄGPIOģʽ

  4. void LCD12864_Init(void)
  5. {       
  6.         GPIO_InitTypeDef GPIO_InitStructure;
  7.        
  8.         LCD12864_GPIO_APBxClock_FUN(LCD12864_SCL_GPIO_CLK,ENABLE);
  9.         LCD12864_GPIO_APBxClock_FUN(LCD12864_SDA_GPIO_CLK,ENABLE);
  10.         LCD12864_GPIO_APBxClock_FUN(LCD12864_CS_GPIO_CLK,ENABLE);
  11.        
  12.                 // ½« SCL µÄGPIOÅäÖÃΪÍÆÍ츴ÓÃģʽ
  13.         GPIO_InitStructure.GPIO_Pin = LCD12864_SCL_PIN;
  14.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  15.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  16.         GPIO_Init(LCD12864_SCL_PORT, &GPIO_InitStructure);
  17.        
  18.                         // ½« SDA µÄGPIOÅäÖÃΪÍÆÍ츴ÓÃģʽ
  19.         GPIO_InitStructure.GPIO_Pin = LCD12864_SDA_PIN;
  20.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  21.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  22.         GPIO_Init(LCD12864_SDA_PORT, &GPIO_InitStructure);
  23.        
  24.                         // ½« CS µÄGPIOÅäÖÃΪÍÆÍ츴ÓÃģʽ
  25.         GPIO_InitStructure.GPIO_Pin = LCD12864_CS_PIN;
  26.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  27.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  28.         GPIO_Init(LCD12864_CS_PORT, &GPIO_InitStructure);
  29.        
  30.         SCL_L;
  31.         CS_L;
  32.        
  33. }


  34. /*
  35.   * @brief        ÏòLCD12864·¢ËÍÒ»¸ö×Ö½Ú
  36.   * @param  ÎÞ
  37.   * @retval ÎÞ
  38.        
  39. */
  40.   
  41. static void LCD12864_Send_Byte( unsigned char data )  
  42. {  
  43.    uint8_t i;  
  44.    for(i = 0;i < 8;i++)  
  45.    {  
  46.      if((data << i) & 0x80)  
  47.      {  
  48.        SDA_H;
  49.      }  
  50.      else  
  51.      {  
  52.        SDA_L;  
  53.      }  
  54.                  SCL_H;
  55.                  delay_us(4);
  56.                  SCL_L;
  57.                  delay_us(4);
  58.    }  
  59. }


  60. /*
  61.   * @brief        ÏòLCD12864д¿ØÖÆÖ¸Áî
  62.   * @param  ÎÞ
  63.   * @retval ÎÞ       
  64. */

  65. void LCD12864_Write_Com( unsigned char cmdcode )  
  66. {  
  67.   CS_H;
  68.   LCD12864_Send_Byte(0xf8);
  69.   LCD12864_Send_Byte(cmdcode & 0xf0);
  70.   LCD12864_Send_Byte((cmdcode << 4) & 0xf0);  
  71.         CS_L;
  72.   delay_us(500);  
  73. }


  74. /*
  75.   * @brief        ÏòLCD12864дÏÔʾµÄÊý¾Ý
  76.   * @param  ÎÞ
  77.   * @retval ÎÞ       
  78. */

  79. void LCD12864_Write_Data( unsigned char Dispdata )  
  80. {  
  81.    CS_H;  
  82.    LCD12864_Send_Byte(0xfa);  
  83.    LCD12864_Send_Byte(Dispdata & 0xf0);  
  84.    LCD12864_Send_Byte((Dispdata << 4));
  85.          CS_L;
  86.    delay_us(500);  
  87. }

  88. //Ïò¹æ¶¨ÐкÍÁÐдÈëÊý¾Ý
  89. void LCD12864_display(unsigned char line,unsigned char row,unsigned char data)
  90. {
  91.         switch(line)
  92.   {
  93.     case 1: LCD12864_Write_Com(0x80+row); break;
  94.     case 2: LCD12864_Write_Com(0x90+row); break;
  95.     case 3: LCD12864_Write_Com(0x88+row); break;
  96.     case 4: LCD12864_Write_Com(0x98+row); break;
  97.   }
  98.         LCD12864_Write_Data(data);
  99.        
  100. }


  101. //Ïò¹æ¶¨ÐкÍÁÐдÈë¶à¸öÊý¾Ý
  102. void LCD12864_displays(uint8_t line,uint8_t row,unsigned char *data)
  103. {
  104.         switch(line)
  105.   {
  106.     case 1: LCD12864_Write_Com(0x80+row); break;
  107.     case 2: LCD12864_Write_Com(0x90+row); break;
  108.     case 3: LCD12864_Write_Com(0x88+row); break;
  109.     case 4: LCD12864_Write_Com(0x98+row); break;
  110.   }
  111.         //LCD12864_Write_Data(*data);
  112.         while(*data!='')  
  113.   {  
  114.     LCD12864_Write_Data( *data );  
  115.     data++;   
  116.   }
  117. }


  118. //
  119. void LCD12864_display_Init(void)
  120. {
  121.   LCD12864_Write_Com(0x30);  
  122.   LCD12864_Write_Com(0x01);
  123.         delay_ms(10);
  124.   LCD12864_Write_Com(0x02);              
  125.   delay_ms(10);      
  126.   LCD12864_Write_Com(0x0c);
  127.         LCD12864_Write_Com(0x81);
  128. }
复制代码
  1. #include "stm32f10x.h"
  2. #include  "lcd12864.h"
  3. #include "delay.h"

  4. int main(void)
  5. {
  6.         unsigned char shuzu[]={"wo shi shui ne?"};
  7.         unsigned char shuzu1[]={"¸´ºÏ¹­"};
  8.         LCD12864_Init();
  9.         LCD12864_display_Init();
  10.         LCD12864_Write_Data('a');
  11.         LCD12864_displays(2,1,shuzu);
  12.         LCD12864_displays(3,1,shuzu1);
  13.        
  14.         while(1)
  15.         {
  16.         }
  17. }
复制代码

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。