2025年st7735r(st7735r和st7735s)

st7735r(st7735r和st7735s)void LCD CtrlWrite IC unsigned char c nbsp nbsp nbsp nbsp unsigned char i 0 nbsp nbsp nbsp nbsp DDRA BV PA0 BV PA1 BV PA2 BV PA3 BV PA4 nbsp nbsp nbsp nbsp CLR LCD CS nbsp nbsp nbsp nbsp




  1. void LCD_CtrlWrite_IC(unsigned char c)
  2. {
  3. unsigned char i=0;
  4. DDRA |= _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3) | _BV(PA4);
  5. CLR_LCD_CS(); //片选后指令为拉低
  6. CLR_LCD_RS();
  7. for(i=0;i<8;i++)
  8. {
  9. if(c & 0x80) SET_LCD_SDA();
  10. else  CLR_LCD_SDA();

  11. CLR_LCD_SCK();SET_LCD_SCK();
  12. c <<= 1;
  13. }
  14. SET_LCD_CS();
  15. }
  16. void LCD_DataWrite_IC(unsigned char data)
  17. {
  18. unsigned char i=0;
  19. DDRA |= _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3) | _BV(PA4);
  20. CLR_LCD_CS(); //片选后指令为拉高
  21. SET_LCD_RS();
  22. for(i=0;i<8;i++)
  23. {
  24. if(data & 0x80) SET_LCD_SDA();
  25. else  CLR_LCD_SDA();

  26. CLR_LCD_SCK();SET_LCD_SCK();
  27. data <<= 1;
  28. }
  29. SET_LCD_CS();
  30. }
  31. void LCD_DataWrite(unsigned char LCD_DataH,unsigned char LCD_DataL)
  32. {
  33. LCD_DataWrite_IC(LCD_DataH);
  34. LCD_DataWrite_IC(LCD_DataL);
  35. }



  36. void  write_command(unsigned char c)
  37. {
  38. unsigned char i=0;
  39. DDRA |= _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3) | _BV(PA4);
  40. CLR_LCD_CS();
  41. CLR_LCD_RS();
  42. for(i=0;i<8;i++)
  43. {
  44. if(c & 0x80) SET_LCD_SDA();
  45. else  CLR_LCD_SDA();

  46. CLR_LCD_SCK();SET_LCD_SCK();
  47. c <<= 1;
  48. }
  49. SET_LCD_CS();
  50. }
  51. void  write_data(unsigned char d)
  52. {
  53. unsigned char i=0;
  54. DDRA |= _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3) | _BV(PA4);
  55. CLR_LCD_CS();
  56. SET_LCD_RS();
  57. for(i=0;i<8;i++)
  58. {
  59. if(d & 0x80) SET_LCD_SDA();
  60. else  CLR_LCD_SDA();

  61. CLR_LCD_SCK(); SET_LCD_SCK();
  62. d <<= 1;
  63. }
  64. SET_LCD_CS();
  65. }

  66. void dsp_single_colour(unsigned char DH,unsigned char DL)
  67. {
  68. unsigned char i,j;
  69. //RamAdressSet();
  70. for (i=0;i<160;i++)
  71. for (j=0;j<128;j++)
  72.       LCD_DataWrite(DH,DL);
  73. }
  74. void init_lcd18(void)
  75. {
  76.       DDRA |= _BV(PA0) | _BV(PA1) | _BV(PA2) | _BV(PA3) | _BV(PA4);             //PA0-4设置输出
  77.       CLR_LCD_RESET();
  78.       _delay_ms(5);
  79.       SET_LCD_RESET();
  80.       _delay_ms(5);

  81. //------------------------------------------------------------------//  
  82. //-------------------Software Reset-------------------------------//
  83. //------------------------------------------------------------------//
  84. write_command(0x01); //Sofeware setting
  85. _delay_ms(10);
  86. write_command(0x11); //Sleep out
  87. _delay_ms(120); //Delay 120ms
  88. //------------------------------------ST7735S Frame Rate-----------------------------------------//
  89. write_command(0xB1);
  90. write_data(0x01);
  91. write_data(0x2C);
  92. write_data(0x2D);
  93. write_command(0xB2);
  94. write_data(0x01);
  95. write_data(0x2C);
  96. write_data(0x2D);
  97. write_command(0xB3);
  98. write_data(0x01);
  99. write_data(0x2C);
  100. write_data(0x2D);
  101. write_data(0x01);
  102. write_data(0x2C);
  103. write_data(0x2D);
  104. //------------------------------------End ST7735R Frame Rate-----------------------------------------//
  105.       write_command(0xB4);//Column inversion
  106.       write_data(0x07);
  107. //------------------------------------ST7735R Power Sequence-----------------------------------------//

  108. write_command(0xC0);
  109. write_data(0xA2);
  110. write_data(0x02);
  111. write_data(0x84);
  112. write_command(0xC1);
  113. write_data(0XC5);
  114. write_command(0xC2);
  115. write_data(0x0A);
  116. write_data(0x00);
  117. write_command(0xC3);
  118. write_data(0x8A);
  119. write_data(0x2A);
  120. write_command(0xC4);
  121. write_data(0x8A);
  122. write_data(0xEE);
  123. //---------------------------------End ST7735S Power Sequence-------------------------------------//
  124. write_command(0xC5); //VCOM
  125. write_data(0x1A);
  126. write_command(0x36); //MX, MY, RGB mode
  127. write_data(0xC8);
  128. //------------------------------------ST7735S Gamma Sequence-----------------------------------------//
  129. write_command(0xE0);
  130. write_data(0x02);
  131. write_data(0x1c);
  132. write_data(0x07);
  133. write_data(0x12);
  134. write_data(0x37);
  135. write_data(0x32);
  136. write_data(0x29);
  137. write_data(0x2d);
  138. write_data(0x29);
  139. write_data(0x25);
  140. write_data(0x2b);
  141. write_data(0x39);
  142. write_data(0x00);
  143. write_data(0x01);
  144. write_data(0x03);
  145. write_data(0x10);
  146. write_command(0xE1);
  147. write_data(0x03);
  148. write_data(0x1d);
  149. write_data(0x07);
  150. write_data(0x06);
  151. write_data(0x2e);
  152. write_data(0x2c);
  153. write_data(0x29);
  154. write_data(0x2d);
  155. write_data(0x2e);
  156. write_data(0x2e);
  157. write_data(0x37);
  158. write_data(0x3f);
  159. write_data(0x00);
  160. write_data(0x00);
  161. write_data(0x02);
  162. write_data(0x10);

  163.       write_command(0x2A);
  164.       write_data(0x00);
  165.       write_data(0x02);
  166.       write_data(0x00);
  167.       write_data(0x81);
  168.       
  169.       write_command(0x2B);
  170.       write_data(0x00);
  171.       write_data(0x01);
  172.       write_data(0x00);
  173.       write_data(0xA0);
  174. //------------------------------------End ST7735S Gamma Sequence-----------------------------------------//
  175. write_command(0x3A); //65k mode
  176. write_data(0x05);
  177. write_command(0x29); //Display on
  178. */
  179. }

  180. //===========================================================================

  181. void  RamAdressSet(void)
  182. {
  183. write_command(0x2A);
  184. write_data(0x00);
  185. write_data(0x00);
  186. write_data(0x00);
  187. write_data(0x7f);
  188.   
  189. write_command(0x2B);
  190. write_data(0x00);
  191. write_data(0x00);
  192. write_data(0x00);
  193. write_data(0x9f);               
  194. }



  195. void PutPixel(unsigned int x_start,unsigned int y_start,unsigned int color)
  196. {
  197.       LCD_CtrlWrite_IC(0x2a);
  198.       LCD_DataWrite_IC(x_start);
  199.       LCD_DataWrite_IC(0x5f);
  200.       LCD_CtrlWrite_IC(0x2b);
  201.       LCD_DataWrite_IC(y_start+0x34);
  202.       LCD_DataWrite_IC(0x7F);
  203.       LCD_CtrlWrite_IC(0x2c);
  204.       LCD_DataWrite_IC(color>>8);
  205.       LCD_DataWrite_IC(color&0xff);       
  206. }



  207. void RedLine(void)
  208. {
  209.       unsigned char  i=0,j=0;
  210.       i=66; // 11格灰阶
  211.       for(j=0;j<16;j++)
  212.       {
  213.             PutPixel(i,j,0xf800);
  214.       }

  215. }


  216. void Output_Pixel(unsigned int x,unsigned int y)
  217. {
  218. LCD_CtrlWrite_IC(0x2A);  //Column Address Set       ****
  219.       LCD_DataWrite_IC(x);//xsh
  220.       LCD_DataWrite_IC(x);//xsl      
  221.       LCD_CtrlWrite_IC(0x2B);//Row Address Set          ****
  222.       LCD_DataWrite_IC(y);//ysl
  223.       LCD_DataWrite_IC(y);//ysl
  224.       LCD_CtrlWrite_IC(0x2c);
  225.       LCD_DataWrite(0xf8,0x00);
  226. RamAdressSet();
  227. }

  228. void Display_ASCII8X16(unsigned int x0,unsigned int y0,unsigned char *s)
  229. {
  230.       int i,j,k,x,y,xx;
  231.       
  232.       unsigned char qm;
  233.       
  234.       long int ulOffset;
  235.       
  236.       char  ywbuf[32],temp[2];

  237.       for(i = 0; i<strlen((char*)s);i++)
  238.       {
  239.             if(((unsigned char)(*(s+i))) >= 161)
  240.             {
  241.                      temp[0] = *(s+i);
  242.                      temp[1] = '0';
  243.                      return;
  244.             }
  245.            
  246.             else
  247.             {
  248.                      qm = *(s+i);

  249.                      ulOffset = (long int)(qm) * 16;
  250.                     
  251.          for (j = 0; j < 16; j ++)
  252.          {
  253.                               ywbuf[j]=Zk_ASCII8X16[ulOffset+j];
  254.                }
  255.         
  256.          for(y = 0;y < 16;y++)
  257.          {
  258.                         for(x=0;x<8;x++)
  259.                         {
  260.                      k=x % 8;
  261.                     
  262.                                        if(ywbuf[y]&(0x80 >> k))
  263.                                        {
  264.                                                 xx=x0+x+i*8;
  265.                                           Output_Pixel(xx,y+y0);
  266.                                        }
  267.                                  }
  268.          }

  269.             }
  270.       }         
  271. }


  272. void Display_Desc(void)
  273. {
  274. Display_ASCII8X16(1,52,str1);
  275. Display_ASCII8X16(1,64,str2);
  276. Display_ASCII8X16(1,76,str3);
  277. Display_ASCII8X16(1,88,str4);
  278. Display_ASCII8X16(1,100,str5);
  279. Display_ASCII8X16(1,112,str6);
  280. }
编程小号
上一篇 2025-02-19 08:21
下一篇 2025-03-26 12:30

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ri-ji/40294.html