找回密码
 立即注册
楼主: 13245768

求助,2.4寸tft屏幕显示异常 | 颜色经过修改后对了

[复制链接]
已绑定手机

14

主题

83

回帖

700

积分

高级会员

积分
700
 楼主| 发表于 2026-8-20 14:55:08 | 显示全部楼层
1324*** 发表于 2026-8-20 14:44
屏幕下半边是白色,看起来蓝是相机问题,也是只能显示一条,且颜色不对 ...
  1. #include<AI8051U.h>
  2. sbit SCLK=P1^0;
  3. sbit MOSI=P1^1;
  4. sbit MISO=P1^2;
  5. sbit CS=P1^3;
  6. sbit RES=P1^4;
  7. sbit DC=P1^5;
  8. void Delay(unsigned long int t) { while(--t){_nop_();} }
  9. void Gpio_init(void)
  10. {
  11. P0M0=0x00;P0M1=0x00;
  12. P1M0=0xff;P1M1=0x00;
  13. P2M0=0x00;P2M1=0x00;
  14. P3M0=0x00;P3M1=0x00;
  15. P4M0=0x00;P4M1=0x00;
  16. P5M0=0x00;P5M1=0x00;
  17. }
  18. void SpiSendBit(bit dat)
  19. {
  20.     MOSI = dat;
  21.     SCLK = 1;
  22.     _nop_(); _nop_(); _nop_();
  23.     SCLK = 0;
  24. }
  25. void SpiSendByte(unsigned char dat)
  26. {
  27.     unsigned char j;
  28.     for(j=0x80; j; j>>=1)
  29.           {
  30.         SpiSendBit(dat & j);
  31.           }
  32. }
  33. void Lcd_Cmd(unsigned char cmd)
  34. {
  35.     CS = 0;
  36.     DC = 0;
  37.     SpiSendByte(cmd);
  38.     CS = 1;
  39. }
  40. void Lcd_Cmd_Ncs(unsigned char cmd)
  41. {
  42.     DC = 0;
  43.     SpiSendByte(cmd);
  44. }
  45. void Lcd_Data(unsigned char dat)
  46. {
  47.     CS = 0;
  48.     DC = 1;
  49.     SpiSendByte(dat);
  50.     CS = 1;
  51. }
  52. void Lcd_Data_Ncs(unsigned char dat)
  53. {
  54.     DC = 1;
  55.     SpiSendByte(dat);
  56. }
  57. void Lcd_Init(void)
  58. {
  59.           RES = 0;
  60.                 Delay(50000);
  61.                 RES = 1;
  62.                 Delay(1000000);
  63.     /* ---- 1. 软件复位 ---- */
  64.     Lcd_Cmd(0x01);      // Software Reset
  65.     Delay(70000);      // 复位后延时等待
  66.                
  67.           /* ---- 7. 退出睡眠,开启显示 ---- */
  68.     Lcd_Cmd(0x11);      // Sleep OUT
  69.     Delay(1000000);      // 退出睡眠后需延时
  70.     /* ---- 2. 电源控制 ---- */
  71.     Lcd_Cmd(0xC0);      // Power Control 1
  72.     Lcd_Data(0x21);     // VRH[5:0] = 21h(参考命令表默认)
  73.     Lcd_Cmd(0xC1);      // Power Control 2
  74.     Lcd_Data(0x10);     // BT[2:0] = 0(命令表默认 10h)
  75.                 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  76.                 CS=0;
  77.     Lcd_Cmd_Ncs(0xC5);      // VCOM Control 1
  78.     Lcd_Data_Ncs(0x31);     // VMH[6:0] = 31h
  79.     Lcd_Data_Ncs(0x3C);     // VML[6:0] = 3Ch
  80.                 CS=1;
  81.                 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  82.     Lcd_Cmd(0xC7);      // VCOM Control 2
  83.     Lcd_Data(0xC0);     // nVM=1, VMF 参考命令表
  84.     /* ---- 3. 时序 / 帧率控制 ---- */
  85.                 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  86.                 CS=0;
  87.     Lcd_Cmd_Ncs(0xB1);      // Frame Control (Normal Mode)
  88.     Lcd_Data_Ncs(0x00);     // DIVA[1:0] = 00
  89.     Lcd_Data_Ncs(0x1B);                // RTNA[4:0] = 1Bh
  90.                 CS=1;
  91.                 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  92.     CS=0;
  93.     Lcd_Cmd_Ncs(0xB6);      // Display Function Control
  94.     Lcd_Data_Ncs(0x0A);     // PTG[1:0]=00, PT[1:0]=10
  95.     Lcd_Data_Ncs(0x82);     // REV=1, GS=0, SS=0, SM=0, ISC=0010
  96.     Lcd_Data_Ncs(0x27);     // NL[5:0] = 27h(240行)
  97.                 CS=1;
  98.                 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  99.     /* ---- 4. 像素格式设定 ---- */
  100.     Lcd_Cmd(0x3A);      // Pixel Format Set
  101.     Lcd_Data(0x55);     // DPI=110(16bit), DBI=110(16bit) -> RGB565
  102.     /* ---- 5. 内存访问控制(显示方向 / RGB顺序)---- */
  103.     Lcd_Cmd(0x36);      // Memory Access Control
  104.     Lcd_Data(0x08);     // MY=0,MX=0,MV=0,ML=0,BGR=1,MH=0
  105.     /* ---- 6. 正负伽马校正 ---- */
  106.     // Positive Gamma Correction
  107.                 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  108.                 CS=0;
  109.     Lcd_Cmd_Ncs(0xE0);
  110.     Lcd_Data_Ncs(0x0F); Lcd_Data_Ncs(0x16); Lcd_Data_Ncs(0x14);
  111.     Lcd_Data_Ncs(0x0A); Lcd_Data_Ncs(0x0D); Lcd_Data_Ncs(0x06);
  112.     Lcd_Data_Ncs(0x43); Lcd_Data_Ncs(0x75); Lcd_Data_Ncs(0x33);
  113.     Lcd_Data_Ncs(0x06); Lcd_Data_Ncs(0x0E); Lcd_Data_Ncs(0x00);
  114.     Lcd_Data_Ncs(0x0C); Lcd_Data_Ncs(0x09); Lcd_Data_Ncs(0x08);
  115.                 CS=1;
  116.                 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  117.                 CS=0;
  118.     // Negative Gamma Correction
  119.     Lcd_Cmd_Ncs(0xE1);
  120.     Lcd_Data_Ncs(0x08); Lcd_Data_Ncs(0x2B); Lcd_Data_Ncs(0x2D);
  121.     Lcd_Data_Ncs(0x04); Lcd_Data_Ncs(0x10); Lcd_Data_Ncs(0x04);
  122.     Lcd_Data_Ncs(0x3E); Lcd_Data_Ncs(0x24); Lcd_Data_Ncs(0x4E);
  123.     Lcd_Data_Ncs(0x04); Lcd_Data_Ncs(0x0F); Lcd_Data_Ncs(0x0E);
  124.     Lcd_Data_Ncs(0x35); Lcd_Data_Ncs(0x38); Lcd_Data_Ncs(0x0F);
  125.                 CS=1;
  126.                 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  127.     Lcd_Cmd(0x29);      // Display ON
  128. }
  129. /* 全屏显示 RGB565 图片(240x320),高字节在前,一维数组 */
  130. void Display(const unsigned char img[])
  131. {
  132.     unsigned long i;
  133.     /* 设置全屏写入窗口 */
  134.           CS=0;
  135.     Lcd_Cmd_Ncs(0x2A);              /* Column Address Set */
  136.     Lcd_Data_Ncs(0x00); Lcd_Data_Ncs(0x00);   /* SC = 0 */
  137.     Lcd_Data_Ncs(0x00); Lcd_Data_Ncs(0xEF);   /* EC = 239 */
  138.                 CS=1;
  139.           _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  140.           CS=0;
  141.     Lcd_Cmd_Ncs(0x2B);              /* Page Address Set */
  142.     Lcd_Data_Ncs(0x00); Lcd_Data_Ncs(0x00);   /* SP = 0 */
  143.     Lcd_Data_Ncs(0x01); Lcd_Data_Ncs(0x3F);   /* EP = 319 */
  144.                 CS=1;
  145.                 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  146.                 CS=0;
  147.     Lcd_Cmd_Ncs(0x2C);              /* Memory Write */
  148.                
  149.     for (i = 0; i < 240 * 320; i++)
  150.     {
  151.         Lcd_Data_Ncs(img[i * 2]);       /* 高字节 */
  152.         Lcd_Data_Ncs(img[i * 2 + 1]);   /* 低字节 */
  153.     }
  154.                 CS=1;
  155. }
  156. void Test(void)
  157. {
  158.     unsigned long i;
  159.     /* 设置全屏写入窗口 */
  160.           CS=0;
  161.     Lcd_Cmd_Ncs(0x2A);              /* Column Address Set */
  162.     Lcd_Data_Ncs(0x00); Lcd_Data_Ncs(0x00);   /* SC = 0 */
  163.     Lcd_Data_Ncs(0x00); Lcd_Data_Ncs(0xEF);   /* EC = 239 */
  164.                 CS=1;
  165.           _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  166.           CS=0;
  167.     Lcd_Cmd_Ncs(0x2B);              /* Page Address Set */
  168.     Lcd_Data_Ncs(0x00); Lcd_Data_Ncs(0x00);   /* SP = 0 */
  169.     Lcd_Data_Ncs(0x01); Lcd_Data_Ncs(0x3F);   /* EP = 319 */
  170.                 CS=1;
  171.                 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
  172.                 CS=0;
  173.     Lcd_Cmd_Ncs(0x2C);              /* Memory Write */
  174.    
  175.     for (i = 0; i < 240 * 320; i++)
  176.     {
  177.                 Lcd_Data_Ncs(0xf8);
  178.                 Lcd_Data_Ncs(0x00);
  179.     }
  180.                 CS=1;
  181. }
  182. void main()
  183. {
  184. WDT_CONTR = 0x00;
  185. Gpio_init();
  186. Lcd_Init();
  187. Test();
  188. while(1);
  189. }
复制代码

颜色经过修改后对了
回复

使用道具 举报 送花

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

本版积分规则

QQ|手机版|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2026-11-9 08:50 , Processed in 0.085312 second(s), 48 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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