Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
LCD
nuc980
NK-980IOT测评之使用EBI驱动LCD
发布于 2022-03-13 11:38:06 浏览:915
订阅该版
[tocm] # 特征 - 三个独立芯片选择引脚,可设置极性,支持三个设备,时序独立设置 - 数据总线和地址总线分开。 - 每个设备支持1MB空间 - 8/16位数据宽度 - 支持8080模式LCD接口 - 支持PDMA - 支持设置读写空闲时间 - 可选内部HCLK分频得到MCLK或者外部EBI_MCLK - 支持地址总线和数据总线分开 ![image.png](https://oss-club.rt-thread.org/uploads/20220313/0b83133eb6e158ab6f069b56da5d5b10.png.webp) # 配置 - 时钟使能 EBI (CLK_HCLKEN[9]) - 复位模块 EBIRST (SYS_AHBIPRST[3]) - 引脚 ![image.png](https://oss-club.rt-thread.org/uploads/20220313/2701157787e8816f544e4400a01213cb.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220313/bc9c112330be3e4f617a5d49f4bb6fec.png.webp) # 功能 ## 地址映射 三个片选分别对应地址如下: ![image.png](https://oss-club.rt-thread.org/uploads/20220313/6d9eee7aab7b78f3fdb8b5dc2ce4ec5e.png.webp) ## 连接 地址总线和数据总线分开模式 ![image.png](https://oss-club.rt-thread.org/uploads/20220313/ba8c840d9251bd187de1cd757cf2693c.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220313/d2b3d34eee3474aa70ba4a64db5c7901.png.webp) ## 读写时序 ![image.png](https://oss-club.rt-thread.org/uploads/20220313/bb664a83bd671caacdce6b263bfde394.png.webp) tASU:地址建立时间,CS拉低到RD或WR拉低的时间,连续读模式CACCESS=1,tASU不需要. tACC:RD,WD拉低的时间,数据访问时间,即给对方去读数据的时间。 tAHD:数据保持时间,即RD,WR拉高后到CS拉高的时间。 # 寄存器 EBI_CTLx 设置时钟分频,使能EBI功能,总线宽度设置,CS极性等 EBI_TCTLx 设置时序参数 # 使用EBI驱动LCD设计 ## 硬件设计 ### LCD选型 从原理图可以看出CON11为EBI接口,设计时实际就是预留给LCD使用的,可以使用EBI接口,接8080模式16bit的LCD屏。 ![image.png](https://oss-club.rt-thread.org/uploads/20220313/78efe9342a60943ef31e5958ad82262f.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220313/2b005ad2a8d00927fb2432050da2bd3a.png.webp) 对应如下: ![image.png](https://oss-club.rt-thread.org/uploads/20220313/a93b66685b5c32ff3e8bd44f6d738120.png) 从淘宝上挑选了一个便宜的2.4寸支持8080模式的触摸屏。使用的驱动芯片是ST7789V。 ![image.png](https://oss-club.rt-thread.org/uploads/20220313/d603d875bdd884ac1173368ae22eab8b.png.webp) (链接就不上了,可以以图搜图搜索购买同款) ### 原理图和PCB设计 使用KiCAD设计了原理图和PCB ![image.png](https://oss-club.rt-thread.org/uploads/20220313/b8e6859546c82e01ba3b2d7881ae1df1.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220313/f992cefd410fa32d1480fa07f32dfc4b.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220313/94168865124ce3675594c26bc553b7e7.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220313/09d20dda23de620f455f6a34b850891c.png.webp) ### 生产焊接 华秋DFM正好在搞活动,可以减免30打样双面板,所以实际只花了8块钱的运费打样。 三四天就生产完到货了,非常快。 ![image.png](https://oss-club.rt-thread.org/uploads/20220313/26777279a184795860eecd8dbc6193ce.png.webp) 在生产时刚好淘宝下单将BOM表的物料采购下,我手里大部分都有就买了个FFC的座子,和2.54的排母。 ![image.png](https://oss-club.rt-thread.org/uploads/20220313/a1c44ddff7d2a96aec59c9e4bdf64384.png.webp) 打样加上物料30块多点就搞定了。 焊接手工,十来分钟就搞定了。 回来的PCB ![image.png](https://oss-club.rt-thread.org/uploads/20220313/5e3a8aa5078ff77e29730015ce6b221c.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220313/b944aad8acedee82edb9dca5790c87e6.png.webp) 焊接之后,由于手头没有洗板水所以焊接后残留很多松香渣滓,可以买点高浓度酒精97%以上清洗下。 ![image.png](https://oss-club.rt-thread.org/uploads/20220313/ea41d5e829bbbd39a3f043f4fb1cf6d4.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220313/e62b837b59e27e7b987315bf6dce2ccb.png.webp) 插入到开发板 ![image.png](https://oss-club.rt-thread.org/uploads/20220313/04c2a9282db7effacd9ea086af24ec5d.png.webp) ## 原理分析 用的CS0片选,所以地址空间为0x6000_0000 ~ 0x600F_FFFF ![image.png](https://oss-club.rt-thread.org/uploads/20220313/b8469c2f7f7b3b61a8866c6891cecd31.png) 由于RS引脚接到了ADDR10,而且使用的是16bit模式,所以地址中的1<<11位对应ADDR10即RS。 如果是8位模式则一一对应,地址中的1<<10位对应ADDR10即RS 写地址0x60000000 | 1<<11则ADDR10为1,RS=1表示数据 写地址0x60000000 | 0<< 11则ADDR10为0,RS=0表示命令 所以读写命令或者数据只需要读写地址0x60000000 | 1<<11和0x60000000 | 0<< 11即可。 液晶屏的参数如下 ![image.png](https://oss-club.rt-thread.org/uploads/20220313/08892cc520b33c4ba65ec441a2e4d0bd.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220313/9eebb67a50404502fbc79e77e172ab51.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220313/bd3ebbb4d788e4469a1e24cdcd5b41e2.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220313/8230d0ab8ecf4463c2aaecf4a293cb80.png) 根据以上 先确认HCLK时钟分频2^x次得到MCLK,x=0~7最大分频128。 sysGetClock(SYS_HCLK))可以获取HCLK单位为M 分频x则MCLK为x/HCLK uS = 1000*x/HCLK nS nu_clocks可以打印当前时钟配置 ## 代码编写 见lcd.c ``` #include
#include
#include "nuc980.h" #include "nu_ebi.h" #include "nu_sys.h" #include
#include
#define LCD_XSIZE 320 #define LCD_YSIZE 240 #define CMD_ADDR (0x60000000 | 0u<<11) #define DAT_ADDR (0x60000000 | 1u<<11) #define LLCD_WRITE_CMD(cmd) *((volatile uint16_t*)CMD_ADDR)=cmd #define LLCD_WRITE_DATA(dat) *((volatile uint16_t*)DAT_ADDR)=dat #define LLCD_READ_DATA() *((volatile uint16_t*)DAT_ADDR) #define MCLK_DIVSET 5 /* 0~7 75m 26ns */ #define MCLK_DIVVAL 32 /* 1~128分频 */ #define R2R 100 /* >10nS */ #define W2X 100 /* >10nS */ #define TAHD 100 /* >10nS */ #define TACC 3000 /* >355nS */ void lcd_init(void) { uint32_t hclk = sysGetClock(SYS_HCLK); uint32_t r2r; uint32_t w2x; uint32_t tahd; uint32_t tacc; /* 1. 引脚配置 */ /* PA12背光 EBI_ADDR8 */ rt_pin_mode(NU_GET_PININDEX(NU_PA, 12), PIN_MODE_OUTPUT); /* PA11复位 EBI_ADDR9 */ rt_pin_mode(NU_GET_PININDEX(NU_PA, 11), PIN_MODE_OUTPUT); /* PA10 EBI_ADDR10 (LCD_RS) MFP1 PA9 EBI_nCS0 MFP1 PA8 EBI_nRE MFP1 PA7 EBI_nWE MFP1 PC0~PC15 EBI_DATA0~EBI_DATA15 MFP1 */ M32(REG_SYS_GPC_MFPL) = 0x11111111; /*PC0~PC15 MFP1 */ M32(REG_SYS_GPC_MFPH) = 0x11111111; M32(REG_SYS_GPA_MFPL) = (M32(REG_SYS_GPA_MFPL) & 0x0FFFFFFF) | 0x10000000; /* PA7 MFP1 */ M32(REG_SYS_GPA_MFPH) = (M32(REG_SYS_GPA_MFPH) & 0xFFFFF000) | 0x00000111; /* PA8 PA9 PA10 MFP1 */ /* 2. 时钟配置 */ M32(REG_CLK_HCLKEN) |= (1u<<9); /* 使能时钟 */ /* 3. 复位 */ M32(REG_SYS_AHBIPRST) |= (1u<<3); /* 复位EBI */ M32(REG_SYS_AHBIPRST) &= ~(1u<<3); /* 结束复位 */ /* 4. 时序 */ EBI->CTL0 |= 1u<<24; /* EBI write buffer Enabled */ EBI->CTL0 = (EBI->CTL0 & (~(0x07<<8))) | (MCLK_DIVVAL<<8); EBI->CTL0 |= 0u<<4; /* Continuous data access mode tASU cycle is bypass. */ EBI->CTL0 |= 1u<<1; /* 16bit. */ r2r = R2R/(1000*MCLK_DIVVAL/hclk) & 0x0F; if(r2r==0) { r2r=1; } w2x = W2X/(1000*MCLK_DIVVAL/hclk) & 0x0F; if(w2x==0) { w2x=1; } tahd = TAHD/(1000*MCLK_DIVVAL/hclk) & 0x07; if(tahd==0) { tahd=1; } tacc = TACC/(1000*MCLK_DIVVAL/hclk) & 0x1F; if(tacc==0) { tacc=1; } EBI->TCTL0 = (r2r<<24) | (0 <<23) | (0<<22) | (w2x<<12) | ((tahd-1)<<8) | ((tacc-1)<<3); EBI->CTL0 |= 1u<<0; /* EBI function Enabled. */ /* 5. LCD复位 */ rt_pin_write(NU_GET_PININDEX(NU_PA, 11), PIN_LOW); /* 手册P48 延时大于10uS */ rt_thread_mdelay(1); rt_pin_write(NU_GET_PININDEX(NU_PA, 11), PIN_HIGH); /* LCD寄存器初始化 */ rt_thread_mdelay(120); //---------------------------------------------------------------------------------------------------// LLCD_WRITE_CMD (0x11); rt_thread_mdelay(120); //Delay 120ms //------------------------------display and color format setting--------------------------------// LLCD_WRITE_CMD (0x36); LLCD_WRITE_DATA (0x00); LLCD_WRITE_CMD (0x3a); LLCD_WRITE_DATA (0x05); //--------------------------------ST7789V Frame rate setting----------------------------------// LLCD_WRITE_CMD (0xb2); LLCD_WRITE_DATA (0x0c); LLCD_WRITE_DATA (0x0c); LLCD_WRITE_DATA (0x00); LLCD_WRITE_DATA (0x33); LLCD_WRITE_DATA (0x33); LLCD_WRITE_CMD (0xb7); LLCD_WRITE_DATA (0x35); //---------------------------------ST7789V Power setting--------------------------------------// LLCD_WRITE_CMD (0xbb); LLCD_WRITE_DATA (0x28); LLCD_WRITE_CMD (0xc0); LLCD_WRITE_DATA (0x2c); LLCD_WRITE_CMD (0xc2); LLCD_WRITE_DATA (0x01); LLCD_WRITE_CMD (0xc3); LLCD_WRITE_DATA (0x0b); LLCD_WRITE_CMD (0xc4); LLCD_WRITE_DATA (0x20); LLCD_WRITE_CMD (0xc6); LLCD_WRITE_DATA (0x0f); LLCD_WRITE_CMD (0xd0); LLCD_WRITE_DATA (0xa4); LLCD_WRITE_DATA (0xa1); //--------------------------------ST7789V gamma setting---------------------------------------// LLCD_WRITE_CMD (0xe0); LLCD_WRITE_DATA (0xd0); LLCD_WRITE_DATA (0x01); LLCD_WRITE_DATA (0x08); LLCD_WRITE_DATA (0x0f); LLCD_WRITE_DATA (0x11); LLCD_WRITE_DATA (0x2a); LLCD_WRITE_DATA (0x36); LLCD_WRITE_DATA (0x55); LLCD_WRITE_DATA (0x44); LLCD_WRITE_DATA (0x3a); LLCD_WRITE_DATA (0x0b); LLCD_WRITE_DATA (0x06); LLCD_WRITE_DATA (0x11); LLCD_WRITE_DATA (0x20); LLCD_WRITE_CMD (0xe1); LLCD_WRITE_DATA (0xd0); LLCD_WRITE_DATA (0x02); LLCD_WRITE_DATA (0x07); LLCD_WRITE_DATA (0x0a); LLCD_WRITE_DATA (0x0b); LLCD_WRITE_DATA (0x18); LLCD_WRITE_DATA (0x34); LLCD_WRITE_DATA (0x43); LLCD_WRITE_DATA (0x4a); LLCD_WRITE_DATA (0x2b); LLCD_WRITE_DATA (0x1b); LLCD_WRITE_DATA (0x1c); LLCD_WRITE_DATA (0x22); LLCD_WRITE_DATA (0x1f); LLCD_WRITE_CMD (0x29); /* 开背光 */ rt_pin_write(NU_GET_PININDEX(NU_PA, 12), PIN_HIGH); #if 0 /* 逻辑分析仪测试波形使用 */ while(1) { LLCD_WRITE_CMD(0x00); LLCD_WRITE_CMD(0x01); LLCD_WRITE_CMD(0x02); LLCD_WRITE_CMD(0x03); LLCD_WRITE_DATA(0x00); LLCD_WRITE_DATA(0x01); LLCD_WRITE_DATA(0x02); LLCD_WRITE_DATA(0x03); LLCD_READ_DATA(); rt_thread_mdelay(1); } #endif } void lcd_setpoint(uint16_t x ,uint16_t y, uint16_t color) { LLCD_WRITE_CMD(0x2A); LLCD_WRITE_DATA(x>>8); LLCD_WRITE_DATA(x&0XFF); LLCD_WRITE_CMD(0x2B); LLCD_WRITE_DATA(y>>8); LLCD_WRITE_DATA(y&0XFF); LLCD_WRITE_CMD(0x2C); LLCD_WRITE_DATA(color); } void lcd_clear(uint16_t color) { LLCD_WRITE_CMD(0x2A); LLCD_WRITE_DATA(0); LLCD_WRITE_DATA(0); LLCD_WRITE_CMD(0x2B); LLCD_WRITE_DATA(0); LLCD_WRITE_DATA(0); LLCD_WRITE_CMD(0x2C); for(uint32_t i=0;i
0
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
qinyunti
这家伙很懒,什么也没写!
文章
30
回答
1
被采纳
0
关注TA
发私信
相关文章
1
RT-Thread Setings没有BSP_USING_LCD选项?
2
晶联讯19264液晶屏字库,可以读取字母、字符和数字,但是汉字读取显示错误
3
rtt studio裸机例程在调取头文件时编译会报错
4
使用littlevgl2rtt软件包实例运行不成功,emwin正常
5
qemu的LCD可以显示1920*720的分辨率?
6
移植潘多拉板子的lcd驱动到芯片上
7
缺少常用的LCD驱动软件包
8
h750XBH6 LCD rt_malloc 分配内存失败
9
rtthread fsmc驱动LCD代码无错误,且背光显示,但是无现象
10
stm32h743 lcd 驱动出现hardfault 问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
UART
WIZnet_W5500
ota在线升级
freemodbus
PWM
flash
cubemx
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
中断
编译报错
Debug
SFUD
rt_mq_消息队列_msg_queue
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
a1012112796
10
个答案
1
次被采纳
踩姑娘的小蘑菇
4
个答案
1
次被采纳
红枫
4
个答案
1
次被采纳
张世争
4
个答案
1
次被采纳
Ryan_CW
4
个答案
1
次被采纳
本月文章贡献
catcatbing
3
篇文章
5
次点赞
YZRD
2
篇文章
5
次点赞
qq1078249029
2
篇文章
2
次点赞
xnosky
2
篇文章
1
次点赞
Woshizhapuren
1
篇文章
5
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部