找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1484|回复: 0
打印 上一主题 下一主题
收起左侧

STM32驱动12864程序 我是时序不对呢,IO不对?

[复制链接]
跳转到指定楼层
楼主
ID:224700 发表于 2018-8-12 23:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
求助大佬,我是时序不对呢,IO不对呀,怎么驱动不了12864呢,内心极度崩塌。。。。。。。。

  1. #ifndef _H_LCD_12684_H
  2. #define _H_LCD_12684_H
  3. #include "sys.h"

  4. //#define PIN_PSB    (1<<3)
  5. //#define PIN_RST    (1<<5)  //片选信号
  6. //#define PIN_E_CLK  (1<<6)
  7. //#define PIN_RW     (1<<7)
  8. //#define PIN_RS_CS  (1<<8)

  9. //#define PIN_Data0  (1<<9)
  10. //#define PIN_Data1  (1<<10)
  11. //#define PIN_Data2  (1<<11)
  12. //#define PIN_Data3  (1<<12)
  13. //#define PIN_Data4  (1<<13)
  14. //#define PIN_Data5  (1<<14)
  15. //#define PIN_Data6  (1<<15)
  16. //#define PIN_Data7  (1<<0)

  17. //#define PSB(x)     GPIOB->ODR = (GPIOB->ODR & ~PIN_PSB)  | (x ? PIN_PSB:  0);
  18. //#define RST(x)     GPIOB->ODR = (GPIOB->ODR & ~PIN_RST)  | (x ? PIN_RST:  0);
  19. //#define E_CLK(x)   GPIOB->ODR = (GPIOB->ODR & ~PIN_E_CLK)| (x ? PIN_E_CLK:0);                                               
  20. //#define RW(x)      GPIOB->ODR = (GPIOB->ODR & ~PIN_RW)   | (x ? PIN_RW :  0);                                             
  21. //#define RS_CS(x)   GPIOB->ODR = (GPIOB->ODR & ~PIN_RS_CS)| (x ? PIN_RS_CS:0);                                          
  22. //                                    
  23. //#define Data0(x)   GPIOB->ODR = (GPIOB->ODR & ~PIN_Data0)| (x ? PIN_Data0 : 0);
  24. //#define Data1(x)   GPIOB->ODR = (GPIOB->ODR & ~PIN_Data1)| (x ? PIN_Data1 : 0);
  25. //#define Data2(x)   GPIOB->ODR = (GPIOB->ODR & ~PIN_Data2)| (x ? PIN_Data2 : 0);
  26. //#define Data3(x)   GPIOB->ODR = (GPIOB->ODR & ~PIN_Data3)| (x ? PIN_Data3 : 0);
  27. //#define Data4(x)   GPIOB->ODR = (GPIOB->ODR & ~PIN_Data4)| (x ? PIN_Data4 : 0);
  28. //#define Data5(x)   GPIOB->ODR = (GPIOB->ODR & ~PIN_Data5)| (x ? PIN_Data5 : 0);
  29. //#define Data6(x)   GPIOB->ODR = (GPIOB->ODR & ~PIN_Data6)| (x ? PIN_Data6 : 0);
  30. //#define Data7(x)   GPIOB->ODR = (GPIOB->ODR & ~PIN_Data7)| (x ? PIN_Data7 : 0);

  31. #define LCD_PSB    PBout(4)
  32. #define LCD_RST    PBout(5)  //片选信号
  33. #define LCD_E_CLK  PBout(6)
  34. #define LCD_RW     PBout(7)
  35. #define LCD_RS_CS  PBout(8)

  36. #define LCD_Data0  PBout(9)
  37. #define LCD_Data1  PBout(10)
  38. #define LCD_Data2  PBout(11)
  39. #define LCD_Data3  PBout(12)
  40. #define LCD_Data4  PBout(13)
  41. #define LCD_Data5  PBout(14)
  42. #define LCD_Data6  PBout(15)
  43. #define LCD_Data7  PBout(0)


  44. void LCD_12864_Write_Com(uint8_t command);
  45. void LCD_12864_Write_Data(uint8_t Data);
  46. void LCD_12864_Init(void);
  47. void LCD_Display_String(uint8_t x,uint8_t y,uint8_t *s) ;


  48. #endif


  49. #include "LCD_12864.h"
  50. #include "delay.h"
  51. #include "usart.h"

  52. u8 Shit[]="HCXY_智能控制实验室";
  53. u8 Fuck[]="世界那么大";
  54. u8 Bitch[]="http://www.jianshengdrlab.com/forum.php";
  55. u8 Hangover[]="Perfact The Test!";

  56. /**************************************************************************
  57. 函数名:
  58. 属  性:
  59. 参  数:
  60. 功  能:写指令
  61. 日  期:
  62. 返回值:
  63. 描  述:
  64. ***************************************************************************/
  65. void LCD_12864_Write_Com(uint8_t command)
  66. {
  67.         u8 temp=0x01;
  68.         u8 table[8]={0};
  69.         u8 count;
  70.   LCD_RW=0;
  71.         LCD_RS_CS=0;
  72.         LCD_E_CLK=0;
  73.         delay_us(10);
  74.         for(count=0;count<8;count++)
  75.         {
  76.                 if(command&temp)
  77.                         table[count]=1;
  78.                 else
  79.                         table[count]=0;
  80.                 temp=temp<<1;
  81.         }
  82.         temp=0x01;
  83.         
  84.         LCD_Data0=table[0];
  85.         LCD_Data1=table[1];
  86.         LCD_Data2=table[2];
  87.         LCD_Data3=table[3];
  88.         LCD_Data4=table[4];
  89.         LCD_Data5=table[5];
  90.         LCD_Data6=table[6];
  91.         LCD_Data7=table[7];
  92.         delay_us(5);
  93.         
  94.         LCD_E_CLK=1;
  95.         delay_us(500);
  96.         LCD_E_CLK=0;
  97.         delay_us(500);
  98. }
  99. /**************************************************************************
  100. 函数名:
  101. 属  性:
  102. 参  数:
  103. 功  能:
  104. 日  期:
  105. 返回值:
  106. 描  述:
  107. ***************************************************************************/
  108. void LCD_12864_Write_Data(uint8_t Data)
  109. {
  110.         u8 temp=0x01;
  111.         u8 table[8]={0};
  112.         u8 count;
  113.   LCD_RW=0;
  114.         LCD_RS_CS=1;
  115.         LCD_E_CLK=0;
  116.         delay_us(10);
  117.         for(count=0;count<8;count++)
  118.         {
  119.                 if(Data&temp)
  120.                         table[count]=1;
  121.                 else
  122.                         table[count]=0;
  123.                 temp=temp<<1;
  124.         }
  125.         temp=0x01;
  126.         
  127.         LCD_Data0=table[0];
  128.         LCD_Data1=table[1];
  129.         LCD_Data2=table[2];
  130.         LCD_Data3=table[3];
  131.         LCD_Data4=table[4];
  132.         LCD_Data5=table[5];
  133.         LCD_Data6=table[6];
  134.         LCD_Data7=table[7];
  135.         delay_us(5);
  136.         
  137.         LCD_E_CLK=1;
  138.         delay_us(500);
  139.         LCD_E_CLK=0;
  140.         delay_us(500);
  141. }
  142. /**************************************************************************
  143. 函数名:
  144. 属  性:
  145. 参  数:
  146. 功  能:
  147. 日  期:
  148. 返回值:
  149. 描  述:
  150. ***************************************************************************/
  151. void LCD_Display_String(uint8_t X,uint8_t Y,uint8_t *P)
  152. {
  153.         switch(Y)
  154.         {
  155.                 case 0:
  156.                              LCD_12864_Write_Com(0x80 + X);//第一行
  157.                              break;
  158.                 case 1:
  159.                              LCD_12864_Write_Com(0x90 + X);//第二行
  160.                              break;
  161.                 case 2:
  162.                              LCD_12864_Write_Com(0x88 + X);//第三行
  163.                              break;
  164.                 case 3:
  165.                              LCD_12864_Write_Com(0x98 + X);//第四行
  166.                              break;
  167.                 default:break;
  168.         }
  169.                 while(*P!='\0')
  170.                 {
  171.                         LCD_12864_Write_Data(*P);
  172.                         delay_us(100);
  173.                         P++;
  174.                 }
  175. }
  176. /**************************************************************************
  177. 函数名:
  178. 属  性:
  179. 参  数:
  180. 功  能:
  181. 日  期:
  182. 返回值:
  183. 描  述:
  184. ***************************************************************************/
  185. void LCD_12864_Init(void)
  186. {
  187. //        GPIO_InitTypeDef GPIOA_InitStruct;
  188.         GPIO_InitTypeDef GPIOB_InitStruct;
  189.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);
  190.         
  191. //        GPIOA_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
  192. //        GPIOA_InitStruct.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
  193. //        GPIOA_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
  194. //        GPIO_Init(GPIOA,&GPIOA_InitStruct);
  195.         
  196.         GPIOB_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
  197.         GPIOB_InitStruct.GPIO_Pin=GPIO_Pin_All;
  198.         GPIOB_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
  199.         GPIO_Init(GPIOB,&GPIOB_InitStruct);
  200.         
  201.         GPIO_SetBits(GPIOB,GPIO_Pin_All);
  202. //  GPIO_SetBits(GPIOA,GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7\
  203. //                           |GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_13|GPIO_Pin_14\
  204. //                           |GPIO_Pin_15);        
  205.                 LCD_RST=0;              //复位
  206.                 delay_ms(10);        //延时
  207.                 LCD_RST=1;              //复位置高
  208.                 delay_ms(50);
  209.           LCD_PSB=1;
  210.                 LCD_12864_Write_Com(0x30);  //Extended Function Set :8BIT设置,RE=0: basic instruction set, G=0 :graphic display OFF
  211.                 delay_us(100);              //大于100uS的延时程序
  212.                 LCD_12864_Write_Com(0x30);  //Function Set
  213.                 delay_us(40);               //大于37uS的延时
  214.                 LCD_12864_Write_Com(0x0c);  //Display on Control
  215.                 delay_us(100);              //大于100uS的延时
  216.                 LCD_12864_Write_Com(0x10);  //Cursor Display Control光标设置
  217.                 delay_us(100);              //大于100uS的延时程序
  218.                 LCD_12864_Write_Com(0x01);  //清屏
  219.                 delay_ms(20);               //大于10mS的延时
  220.                 LCD_12864_Write_Com(0x06);  //Enry Mode Set,光标从右向左加1位移动
  221.                 delay_us(100);              //大于100uS的延时
  222.                
  223. /********************开机画面***********************/
  224.           LCD_Display_String(0,0,Shit);       //显示第1行
  225.     LCD_Display_String(0,1,Fuck);       //显示第2行
  226.     LCD_Display_String(0,2,Bitch);      //显示第3行
  227.     LCD_Display_String(0,3,Hangover);   //显示第4行
  228.                 printf("12464\n");
  229. }
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表