欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: STC12C5A60S2驅動ST7789的測試代碼 [打印本頁]

作者: michaelchain    時間: 2021-12-28 12:26
標題: STC12C5A60S2驅動ST7789的測試代碼
就一個main.c, 幾種顏色切換, 僅用作屏幕好壞判斷, 點亮測試, 在這里發一個備忘
  1. #include "stc12c5a60s2.h"
  2. #include <intrins.h>

  3. #define     RED          0XF800          //紅色
  4. #define     GREEN        0X07E0          //綠色
  5. #define     BLUE         0X001F          //藍色
  6. #define     WHITE        0XFFFF          //白色

  7. #define DATA_H P2
  8. #define DATA_L P0

  9. sbit LCD_CS = P3^2; // -> 9
  10. sbit LCD_CD = P3^4; // -> 11 就是TFT上的LCD_WR引腳
  11. sbit LCD_RESET = P3^6; // -> 15
  12. sbit LCD_MOSI = P1^5; // ->13
  13. sbit LCD_MISO = P1^6; // -> 14
  14. sbit LCD_SCK = P1^7;// -> 10 就是TFT上的LCD_RS引腳

  15. void Delay1ms()                //@12.000MHz
  16. {
  17.         unsigned char i, j;

  18.         i = 12;
  19.         j = 169;
  20.         do
  21.         {
  22.                 while (--j);
  23.         } while (--i);
  24. }

  25. void delay_ms(unsigned int ms)
  26. {
  27.         while(ms--)
  28.         {
  29.                 Delay1ms();
  30.         }
  31. }

  32. unsigned char SPI_RW(unsigned char byte)
  33. {
  34.         unsigned char bit_ctr;
  35.        
  36.         for(bit_ctr=0;bit_ctr<8;bit_ctr++) // 輸出8位
  37.         {
  38.                 LCD_SCK=0;
  39.                 LCD_MOSI=(byte&0x80); // MSB TO MOSI
  40.                 byte=(byte<<1);        // shift next bit to MSB
  41.                 LCD_SCK=1;
  42.                 byte|=LCD_MISO;                // capture current MISO bit
  43.         }
  44.         return byte;
  45. }

  46. void LCD_CD_DATA(unsigned char val)
  47. {
  48.         LCD_CS=0;
  49.         LCD_CD=1;
  50.         SPI_RW(val);
  51.         LCD_CS=1;
  52. }

  53. void LCD_CD_REG(unsigned char reg)
  54. {
  55.         LCD_CS=0;
  56.         LCD_CD=0;
  57.         SPI_RW(reg);
  58.         LCD_CS=1;
  59. }

  60. void LCD_Init()
  61. {
  62.         P0=0;
  63.         P2=0;
  64.         LCD_RESET=0;
  65.         delay_ms(10);
  66.         LCD_RESET=1;
  67.         delay_ms(120);
  68.         //---------------------------------------------------------------------------------------------------//
  69.         LCD_CD_REG(0x11);
  70.         delay_ms(120); //Delay 120ms
  71.         //------------------------------display and color format setting--------------------------------//
  72.         LCD_CD_REG(0x36);
  73.         LCD_CD_DATA(0x00);
  74.         LCD_CD_REG(0x3a);
  75.         LCD_CD_DATA(0x05);
  76.         //--------------------------------ST7789V Frame rate setting----------------------------------//
  77.         LCD_CD_REG(0xb2);
  78.         LCD_CD_DATA(0x0c);
  79.         LCD_CD_DATA(0x0c);
  80.         LCD_CD_DATA(0x00);
  81.         LCD_CD_DATA(0x33);
  82.         LCD_CD_DATA(0x33);
  83.         LCD_CD_REG(0xb7);
  84.         LCD_CD_DATA(0x35);
  85.         //---------------------------------ST7789V Power setting--------------------------------------//
  86.         LCD_CD_REG(0xbb);
  87.         LCD_CD_DATA(0x28);
  88.         LCD_CD_REG(0xc0);
  89.         LCD_CD_DATA(0x2c);
  90.         LCD_CD_REG(0xc2);
  91.         LCD_CD_DATA(0x01);
  92.         LCD_CD_REG(0xc3);
  93.         LCD_CD_DATA(0x0b);
  94.         LCD_CD_REG(0xc4);
  95.         LCD_CD_DATA(0x20);
  96.         LCD_CD_REG(0xc6);
  97.         LCD_CD_DATA(0x0f);
  98.         LCD_CD_REG(0xd0);
  99.         LCD_CD_DATA(0xa4);
  100.         LCD_CD_DATA(0xa1);
  101.         //--------------------------------ST7789V gamma setting---------------------------------------//
  102.         LCD_CD_REG(0xe0);
  103.         LCD_CD_DATA(0xd0);
  104.         LCD_CD_DATA(0x01);
  105.         LCD_CD_DATA(0x08);
  106.         LCD_CD_DATA(0x0f);
  107.         LCD_CD_DATA(0x11);
  108.         LCD_CD_DATA(0x2a);
  109.         LCD_CD_DATA(0x36);
  110.         LCD_CD_DATA(0x55);
  111.         LCD_CD_DATA(0x44);
  112.         LCD_CD_DATA(0x3a);
  113.         LCD_CD_DATA(0x0b);
  114.         LCD_CD_DATA(0x06);
  115.         LCD_CD_DATA(0x11);
  116.         LCD_CD_DATA(0x20);
  117.         LCD_CD_REG(0xe1);
  118.         LCD_CD_DATA(0xd0);
  119.         LCD_CD_DATA(0x02);
  120.         LCD_CD_DATA(0x07);
  121.         LCD_CD_DATA(0x0a);
  122.         LCD_CD_DATA(0x0b);
  123.         LCD_CD_DATA(0x18);
  124.         LCD_CD_DATA(0x34);
  125.         LCD_CD_DATA(0x43);
  126.         LCD_CD_DATA(0x4a);
  127.         LCD_CD_DATA(0x2b);
  128.         LCD_CD_DATA(0x1b);
  129.         LCD_CD_DATA(0x1c);
  130.         LCD_CD_DATA(0x22);
  131.         LCD_CD_DATA(0x1f);
  132.         LCD_CD_REG(0x29);
  133.         LCD_CD_REG(0x2c);
  134. }

  135. void LCD_SetArea(unsigned int stx,unsigned int sty,unsigned int endx,unsigned int endy)
  136. {
  137.         LCD_CD_REG(0x2A);  
  138.         LCD_CD_DATA(stx>>8);   
  139.         LCD_CD_DATA(stx&0xff);           
  140.         LCD_CD_DATA(endx>>8);
  141.         LCD_CD_DATA(endx&0xff);       

  142.         LCD_CD_REG(0x2B);
  143.         LCD_CD_DATA(sty>>8);
  144.         LCD_CD_DATA(sty&0xff);       
  145.         LCD_CD_DATA(endy>>8);
  146.         LCD_CD_DATA(endy&0xff);       
  147. }

  148. void LcdWirteColorData(unsigned int color)
  149. {
  150.         LCD_CS=0;
  151.         LCD_CD=1;
  152.         SPI_RW(color>>8);
  153.         SPI_RW(color);
  154.         LCD_CS=1;
  155. }

  156. void LCD_Clear(unsigned int color)
  157. {  
  158.         unsigned int i,j;

  159.         LCD_SetArea(0,0,239,319);
  160.   LCD_CD_REG(0x2C);
  161.         for(i=0;i<320;i++)
  162.         {
  163.                 for(j=0;j<240;j++)
  164.                 {
  165.                         LcdWirteColorData(color);
  166.                 }
  167.         }
  168. }

  169. void main()
  170. {
  171.         delay_ms(100);
  172. //        SPI_Init();
  173.         LCD_Init();
  174.        
  175.         while(1)
  176.         {
  177.                 LCD_Clear(WHITE);
  178.                 delay_ms(300);
  179.                 LCD_Clear(RED);
  180.                 delay_ms(300);
  181.                 LCD_Clear(BLUE);
  182.                 delay_ms(300);
  183.                 LCD_Clear(GREEN);
  184.                 delay_ms(300);
  185.         }
  186. }

復制代碼







作者: 312439374    時間: 2022-1-11 20:49
能共享下電路嗎?
作者: lgwd    時間: 2022-1-12 13:08
通常開發LCD硬件都是購買某個廠家的產品。廠家都會提供全套演示程序,包括硬件連接說明、基本的LCD命令和數據的讀寫、基本圖形的繪制程序。單個程序意義不大,因為自己去摸索編制這些,不僅很花功夫且問題多多。一些LCD驅動芯片的初始化程序達到三百多行,自己根據芯片手冊去寫都難以成功!




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1