找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2327|回复: 3
收起左侧

STC12C5A60S2驱动ST7789的测试代码

[复制链接]
ID:912806 发表于 2021-12-28 12:26 | 显示全部楼层 |阅读模式
就一个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. }

复制代码






评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:367875 发表于 2022-1-11 20:49 | 显示全部楼层
能共享下电路吗?
回复

使用道具 举报

ID:106977 发表于 2022-1-12 13:08 | 显示全部楼层
通常开发LCD硬件都是购买某个厂家的产品。厂家都会提供全套演示程序,包括硬件连接说明、基本的LCD命令和数据的读写、基本图形的绘制程序。单个程序意义不大,因为自己去摸索编制这些,不仅很花功夫且问题多多。一些LCD驱动芯片的初始化程序达到三百多行,自己根据芯片手册去写都难以成功!
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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