查看: 1265|回复: 6

[原创] 【LPC55S69】基于rt-thread模拟SPI驱动LCD测试

[复制链接]
  • TA的每日心情
    开心
    2024-5-5 08:01
  • 签到天数: 1319 天

    [LV.10]以坛为家III

    124

    主题

    2833

    帖子

    31

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    7578
    最后登录
    2024-5-5
    发表于 2023-2-17 10:34:33 | 显示全部楼层 |阅读模式
       这篇使用模拟SPI方式,来测试下转接板的SPI转并口LCD硬件电路部分。


    一、硬件电路部分

    1.1、LCD部分电路图
    20230217100119.png


    JP1连接LCD显示屏模块
    20230217100211.png


    1.2、硬件实物图


    20230217100505.jpg

    二、测试程序
       
    2.1、lcd.c
    1. #include <rtthread.h>
    2. #include <rtdevice.h>
    3. #include "dfs_fs.h"
    4. #include "drv_pin.h"

    5. #define LCD_SPI_SCLK                      GET_PINS(1, 2)          //LSPI_HS_SCK
    6. #define LCD_SPI_MOSI                             GET_PINS(0, 26)                //LSPI_HS_MOSI
    7. #define LCD_CS                                                           GET_PINS(1, 1)                //LSPI_SSEL
    8. #define LCD_RS                                                     GET_PINS(1, 9)
    9. #define LCD_RST                                                     GET_PINS(1, 10)
    10. #define LCD_BK                                                     GET_PINS(1, 19)                //PLU_INO

    11. void sendbyte(uint8_t bt)
    12. {
    13.         uint8_t i=0;
    14.         rt_pin_write(LCD_SPI_SCLK, PIN_LOW);
    15.         for(i=0;i<8;i++)
    16.         {
    17.                 rt_pin_write(LCD_SPI_SCLK, PIN_LOW);
    18.                 if(bt&0x80)
    19.                 {
    20.                         rt_pin_write(LCD_SPI_MOSI, PIN_HIGH);
    21.                 }
    22.                 else
    23.                 {
    24.                         rt_pin_write(LCD_SPI_MOSI, PIN_LOW);
    25.                 }
    26.                 bt=bt<<1;
    27.                 rt_pin_write(LCD_SPI_SCLK, PIN_HIGH);
    28.         }
    29.         rt_pin_write(LCD_SPI_SCLK, PIN_LOW);
    30. }

    31. void senddat(uint16_t dat)
    32. {
    33.         rt_pin_write(LCD_CS, PIN_HIGH);
    34.         sendbyte((uint8_t)(dat>>8));
    35.         rt_pin_write(LCD_CS, PIN_LOW);
    36.         sendbyte((uint8_t)dat);
    37.         rt_pin_write(LCD_CS, PIN_HIGH);
    38. }

    39. void LCD_Writ_Bus(uint8_t dat)
    40. {
    41.         uint8_t i;
    42.         rt_pin_write(LCD_CS, PIN_LOW);
    43.         for(i=0;i<8;i++)
    44.         {
    45.                 rt_pin_write(LCD_SPI_SCLK, PIN_LOW);
    46.                 if(dat&0x80)
    47.                 {
    48.                         rt_pin_write(LCD_SPI_MOSI, PIN_HIGH);
    49.                 }
    50.                 else
    51.                 {
    52.                         rt_pin_write(LCD_SPI_MOSI, PIN_LOW);
    53.                 }
    54.                 rt_pin_write(LCD_SPI_SCLK, PIN_HIGH);
    55.                 dat<<=1;
    56.         }
    57.         rt_pin_write(LCD_CS, PIN_HIGH);
    58. }
    59. void LCD_WR_DATA8(uint8_t dat)
    60. {
    61.                 LCD_Writ_Bus(dat);
    62. }

    63. void LCD_WR_DATA(uint16_t dat)
    64. {
    65.         senddat(dat);
    66. }

    67. void LCD_WR_REG(uint16_t dat)
    68. {
    69.         rt_pin_write(LCD_RS, PIN_LOW);
    70.         senddat(dat);
    71.         rt_pin_write(LCD_RS, PIN_HIGH);
    72. }


    73. void lcd_register_write(uint16_t register_id,uint16_t value)
    74. {
    75.     LCD_WR_REG(register_id);
    76.     LCD_WR_DATA(value);
    77. }

    78. void lcd_gram_write_prepare(void)
    79. {
    80.     LCD_WR_REG(0x0022);
    81. }

    82. void lcd_gram_write(uint16_t rgb_code)
    83. {
    84.         LCD_WR_DATA(rgb_code);
    85. }

    86. void init_lcd(void)
    87. {
    88.         uint16_t i;
    89.         rt_pin_mode(LCD_SPI_SCLK , PIN_MODE_OUTPUT);
    90.         rt_pin_mode(LCD_SPI_MOSI , PIN_MODE_OUTPUT);
    91.         rt_pin_mode(LCD_CS ,                          PIN_MODE_OUTPUT);
    92.         rt_pin_mode(LCD_RS ,       PIN_MODE_OUTPUT);
    93.         rt_pin_mode(LCD_RST ,      PIN_MODE_OUTPUT);
    94.         rt_pin_mode(LCD_BK ,       PIN_MODE_OUTPUT);
    95.        
    96.         rt_pin_write(LCD_BK, PIN_HIGH);
    97.        
    98.         rt_pin_write(LCD_RST, PIN_LOW);
    99.         rt_thread_mdelay(100);
    100.         rt_pin_write(LCD_RST, PIN_HIGH);
    101.         rt_thread_mdelay(100);
    102.        
    103.         lcd_register_write(0x0000,0x0001);
    104.         lcd_register_write(0x0003,0xA8A4);
    105.         lcd_register_write(0x000C,0x0000);
    106.         lcd_register_write(0x000D,0x080C);
    107.         lcd_register_write(0x000E,0x2B00);
    108.         lcd_register_write(0x001E,0x00B0);
    109.         lcd_register_write(0x0001,0x2B3F);
    110.         lcd_register_write(0x0002,0x0600);
    111.         lcd_register_write(0x0010,0x0000);
    112.         lcd_register_write(0x0011,0x6070);
    113.         lcd_register_write(0x0005,0x0000);
    114.         lcd_register_write(0x0006,0x0000);
    115.         lcd_register_write(0x0016,0xEF1C);
    116.         lcd_register_write(0x0017,0x0003);
    117.         lcd_register_write(0x0007,0x0233);
    118.         lcd_register_write(0x000B,0x0000);
    119.         lcd_register_write(0x000F,0x0000);
    120.         lcd_register_write(0x0041,0x0000);
    121.         lcd_register_write(0x0042,0x0000);
    122.         lcd_register_write(0x0048,0x0000);
    123.         lcd_register_write(0x0049,0x013F);
    124.         lcd_register_write(0x004A,0x0000);
    125.         lcd_register_write(0x004B,0x0000);
    126.         lcd_register_write(0x0044,0xEF00);
    127.         lcd_register_write(0x0045,0x0000);
    128.         lcd_register_write(0x0046,0x013F);
    129.         lcd_register_write(0x0030,0x0707);
    130.         lcd_register_write(0x0031,0x0204);
    131.         lcd_register_write(0x0032,0x0204);
    132.         lcd_register_write(0x0033,0x0502);
    133.         lcd_register_write(0x0034,0x0507);
    134.         lcd_register_write(0x0035,0x0204);
    135.         lcd_register_write(0x0036,0x0204);
    136.         lcd_register_write(0x0037,0x0502);
    137.         lcd_register_write(0x003A,0x0302);
    138.         lcd_register_write(0x003B,0x0302);
    139.         lcd_register_write(0x0023,0x0000);
    140.         lcd_register_write(0x0024,0x0000);
    141.         lcd_register_write(0x0025,0x8000);
    142.         lcd_register_write(0x004e,0);
    143.         lcd_register_write(0x004f,0);
    144.        
    145.         for(i=50000;i>0;i--);
    146. }

    147. void lcd_cursor_set(uint16_t x,uint16_t y)
    148. {
    149.     lcd_register_write(0x004e,x);
    150.     lcd_register_write(0x004f,y);

    151. }

    152. void lcd_clear(uint16_t color)
    153. {
    154.     uint32_t index=0;
    155.     lcd_cursor_set(0,0);
    156.     /* prepare to write GRAM */
    157.     lcd_gram_write_prepare();
    158.     for(index=0;index<76800;index++){
    159.                         LCD_WR_DATA(color);
    160.     }
    161. }

    162. void lcd_point_set(uint16_t x,uint16_t y,uint16_t point)
    163. {
    164.     if ((x > 240)||(y > 320)){
    165.         return;
    166.     }
    167.     lcd_cursor_set(x,y);
    168.     lcd_gram_write_prepare();
    169.     lcd_gram_write(point);
    170. }

    复制代码


    2.2、main.c
    1. int main(void)
    2. {
    3.         uint8_t i=0;
    4. #if defined(__CC_ARM)
    5.     rt_kprintf("using armcc, version: %d\n", __ARMCC_VERSION);
    6. #elif defined(__clang__)
    7.     rt_kprintf("using armclang, version: %d\n", __ARMCC_VERSION);
    8. #elif defined(__ICCARM__)
    9.     rt_kprintf("using iccarm, version: %d\n", __VER__);
    10. #elif defined(__GNUC__)
    11.     rt_kprintf("using gcc, version: %d.%d\n", __GNUC__, __GNUC_MINOR__);
    12. #endif

    13.     //rt_pin_mode(LEDB_PIN, PIN_MODE_OUTPUT);  /* Set GPIO as Output */

    14. #ifdef RT_USING_SDIO
    15.     rt_thread_mdelay(2000);
    16.     if (dfs_mount("sd", "/", "elm", 0, NULL) == 0)
    17.     {
    18.         rt_kprintf("sd mounted to /\n");
    19.     }
    20.     else
    21.     {
    22.         rt_kprintf("sd mount to / failed\n");
    23.     }
    24. #endif

    25.                
    26.                 init_lcd();
    27.        
    28.     while (1)
    29.     {
    30.                         lcd_clear(WHITE);
    31.                         rt_thread_mdelay(1000);
    32.                         lcd_clear(BLUE);
    33.                         rt_thread_mdelay(1000);
    34.     }
    35. }
    复制代码


    三、运行情况


    显示屏可以刷屏显示,这刷新速度也只能够演示下硬件接口没有问题。
    200.gif
    哎...今天够累的,签到来了~
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    昨天 21:42
  • 签到天数: 1489 天

    [LV.10]以坛为家III

    203

    主题

    2万

    帖子

    64

    超级版主

    Rank: 8Rank: 8

    积分
    93455
    最后登录
    2024-5-13
    发表于 2023-2-17 11:03:33 | 显示全部楼层
    直接上硬件SPI啊
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2024-3-20 09:36
  • 签到天数: 451 天

    [LV.9]以坛为家II

    3

    主题

    1147

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    2340
    最后登录
    2024-5-12
    发表于 2023-2-17 11:06:07 | 显示全部楼层
    楼主要充分利用高科技呀!
    录视频,然后再5倍速播放呀
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2024-5-5 08:01
  • 签到天数: 1319 天

    [LV.10]以坛为家III

    124

    主题

    2833

    帖子

    31

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    7578
    最后登录
    2024-5-5
     楼主| 发表于 2023-2-17 11:14:43 | 显示全部楼层
    stm1024 发表于 2023-2-17 11:03
    直接上硬件SPI啊

    是啊,测试下逻辑对不对
    哎...今天够累的,签到来了~
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2024-5-5 08:01
  • 签到天数: 1319 天

    [LV.10]以坛为家III

    124

    主题

    2833

    帖子

    31

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    7578
    最后登录
    2024-5-5
     楼主| 发表于 2023-2-17 11:15:13 | 显示全部楼层
    codingtuzi 发表于 2023-2-17 11:06
    楼主要充分利用高科技呀!
    录视频,然后再5倍速播放呀

    这个可以有
    哎...今天够累的,签到来了~
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    2

    主题

    8

    帖子

    0

    注册会员

    Rank: 2

    积分
    92
    最后登录
    2023-9-5
    发表于 2023-8-16 18:07:14 | 显示全部楼层
    有没有大佬试过用8080协议连接lcd屏呢?
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2024-5-5 08:01
  • 签到天数: 1319 天

    [LV.10]以坛为家III

    124

    主题

    2833

    帖子

    31

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    7578
    最后登录
    2024-5-5
     楼主| 发表于 2023-8-22 16:30:36 | 显示全部楼层
    我这个屏是8080接口,使用SPI转并口驱动的
    哎...今天够累的,签到来了~
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2024-5-14 12:08 , Processed in 0.135439 second(s), 26 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

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