这里附上的是主程序部分和电路连接

 

 

这里用的12864液晶是5v的,电路链接部分 RS PE2 RW PE4 EN PE6  15口PSB串并 PE3
 
  
  1. #include "stm32f10x.h"  
  2.  
  3.  
  4. GPIO_InitTypeDef GPIO_InitStructure;  
  5. #define RS_SET  GPIO_SetBits(GPIOE, GPIO_Pin_2)  
  6. #define RS_CLR  GPIO_ResetBits(GPIOE, GPIO_Pin_2)  
  7.    
  8. #define RW_SET  GPIO_SetBits(GPIOE, GPIO_Pin_4)  
  9. #define RW_CLR  GPIO_ResetBits(GPIOE, GPIO_Pin_4)  
  10.  
  11.  
  12. #define EN_SET  GPIO_SetBits(GPIOE, GPIO_Pin_6)  
  13. #define EN_CLR  GPIO_ResetBits(GPIOE, GPIO_Pin_6)  
  14.  
  15.  
  16. #define PSB_SET  GPIO_SetBits(GPIOE, GPIO_Pin_3)  
  17. #define PSB_CLR  GPIO_ResetBits(GPIOE, GPIO_Pin_3)  
  18.  
  19.  
  20. #define DATA_IO GPIOC->ODR  
  21.  
  22.  
  23. void RCC_Configuration(void);  
  24. void LCD12864_Config(void);  
  25. void Delay_nus(__IO uint32_t nCount);  
  26. void Delay_mus(__IO uint32_t nCount);  
  27. uint8_t table[]="做我女朋友吧!";  
  28.  
  29.  
  30. void write_12864com(uint8_t com)  
  31. {  
  32. RW_CLR;  
  33. RS_CLR;  
  34. Delay_nus(500);  
  35. DATA_IO=com;  
  36. EN_SET;  
  37. Delay_nus(1000);  
  38. EN_CLR;  
  39. Delay_nus(1000);  
  40. }  
  41.  
  42.  
  43. void write_12864dat(uint8_t dat)  
  44. {  
  45. RW_CLR;  
  46. RS_SET;  
  47. Delay_nus(500);  
  48. DATA_IO=dat;  
  49. EN_SET;  
  50. Delay_nus(1000);  
  51. EN_CLR;  
  52. Delay_nus(1000);  
  53. }  
  54.  
  55.  
  56. void init12864lcd(void)  
  57. {  
  58. Delay_mus(500);  
  59. write_12864com(0x30);  
  60. Delay_nus(500);  
  61. write_12864com(0x30);  
  62. Delay_nus(500);  
  63. write_12864com(0x0f);  
  64. Delay_nus(500);  
  65. write_12864com(0x01);  
  66. Delay_nus(25);  
  67. write_12864com(0x06);  
  68. Delay_nus(2500);  
  69. write_12864com(0x0c);  
  70. Delay_nus(500);  
  71. }  
  72.  
  73.  
  74. void display(void)  
  75. {  
  76. uint8_t i;  
  77. write_12864com(0x80);  
  78. for(i=0;i<14;i++)  
  79. {  
  80. write_12864dat(table[i]);  
  81. Delay_mus(50);  
  82. }  
  83. }  
  84.    
  85. void LCD12864_Config(void)  
  86. {  
  87.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOC , ENABLE);  
  88.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_6;    
  89.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  
  90.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  
  91.   GPIO_Init(GPIOE, &GPIO_InitStructure);    
  92.     
  93.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3  
  94.       |GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;    
  95.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  
  96.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  
  97.   GPIO_Init(GPIOC, &GPIO_InitStructure);  
  98. }  
  99.  
  100.  
  101.    
  102. int main(void)  
  103. {  
  104.   RCC_Configuration();   //系统时钟配置  
  105.   LCD12864_Config();   
  106.   PSB_SET;   
  107.   init12864lcd();  
  108.   while (1)  
  109.   {  
  110.       display();  
  111.   }  
  112. }  
  113.  
  114.  
  115.    
  116. void RCC_Configuration(void)  
  117. {     
  118.   SystemInit();  
  119. }  
  120.  
  121.  
  122.    
  123. void Delay_nus(uint32_t nCount)  
  124. {  
  125.  uint32_t j;  
  126.  while(nCount--)  
  127.  {   
  128.     j=8;  
  129.     while(j--);  
  130.  }  
  131. }  
  132.  
  133.  
  134.    
  135. void Delay_mus(uint32_t nCount)  
  136. {  
  137.     while(nCount--)  
  138.     Delay_nus(1100);  
  139. }