Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
RT-Thread一般讨论
ILI9481 驱动 320*480
发布于 2013-07-13 09:13:08 浏览:3620
订阅该版
只写了 ili9481_lcd_set_pixel, ili9481_lcd_get_pixel, ili9481_lcd_draw_hline, ili9481_lcd_draw_vline, ili9481_lcd_blit_line 应该够的了吧,参照RADIO上的ILI驱动 能正常显示REALTOUCH的主界面 ```#include
#include "ili9481.h" #include
#define LCD_WIDTH 320 /* Screen Width (in pixels) */ #define LCD_HEIGHT 480 /* Screen Hight (in pixels) */ /* LCD is connected to the FSMC_Bank1_NOR/SRAM1 and NE1 is used as ship select signal */ #define LCD_DATA (*((volatile unsigned short *) 0x60020000)) /* A16 RS = 0 */ #define LCD_CMD (*((volatile unsigned short *) 0x60000000)) /* A16 RS = 1 */ #define Delay1ms(tick) rt_thread_delay(tick * (RT_TICK_PER_SECOND / 1000)) static struct rt_device _lcd_device; rt_inline void lcd_write_cmd (uint16_t reg) { LCD_CMD = reg; } rt_inline void lcd_write_data(uint16_t value) { LCD_DATA = value; } rt_inline uint16_t lcd_read_data(void) { return LCD_DATA; } static uint16_t bgr2rgb(uint16_t c) { u16 r, g, b, rgb; b = (c>>0) & 0x1f; g = (c>>5) & 0x3f; r = (c>>11) & 0x1f; rgb = (b<<11) + (g<<5) + (r<<0); return( rgb ); } #define lcd_read_memory_start() lcd_write_cmd(READ_MEMORY_START) #define lcd_write_memory_start() lcd_write_cmd(WRITE_MEMORY_START) static void lcd_set_cursor(uint16_t x,uint16_t y) { //竖屏 lcd_write_cmd (0x2A);//设定x坐标 lcd_write_data(x>>8); lcd_write_data(0xFF&x); lcd_write_cmd (0x2B);//设定y坐标 lcd_write_data(y>>8); lcd_write_data(0xFF&y); //横屏 // lcd_write_cmd (0x2B);//设定x坐标 // lcd_write_data((LCD_WIDTH - x)>>8); // lcd_write_data(0xFF&(LCD_WIDTH - x)); // lcd_write_cmd (0x2A);//设定y坐标 // lcd_write_data(y>>8); // lcd_write_data(0xFF&y); } static uint16_t lcd_read_gram(uint16_t x,uint16_t y)/* 读取指定地址的GRAM */ { uint16_t val; lcd_set_cursor(x,y); lcd_read_memory_start(); val = lcd_read_data(); // 无效的读取,但必须 val = lcd_read_data(); // 第二次读取有效 return val; } void lcd_clear(uint16_t color) { uint32_t index; lcd_set_cursor(0,0); lcd_write_memory_start(); for (index=0; index < 345600; index++) { lcd_write_data(color); } } #ifdef RT_USING_FINSH #include
FINSH_FUNCTION_EXPORT(lcd_clear, lcd_clear(0xffff)); #endif static void ili9481_lcd_set_pixel(const char* pixel, int x, int y) { lcd_set_cursor(x,y); lcd_write_memory_start(); lcd_write_data(*(uint16_t *)pixel); } static void ili9481_lcd_get_pixel(char* pixel, int x, int y) { *(rt_uint16_t*)pixel = lcd_read_gram(x,y); } static void ili9481_lcd_draw_hline(const char* pixel, int x1, int x2, int y) { int x; x = x1; while (x < x2) { lcd_set_cursor(x,y); lcd_write_memory_start(); lcd_write_data(*(uint16_t *)pixel); x++; } } static void ili9481_lcd_draw_vline(const char* pixel, int x, int y1, int y2) { int y; y = y1; while (y < y2) { lcd_set_cursor(x,y); lcd_write_memory_start(); lcd_write_data(*(uint16_t *)pixel); y++; } } static void ili9481_lcd_blit_line(const char* pixels, int x, int y, rt_size_t size) { rt_uint16_t *ptr; lcd_set_cursor(x,y); lcd_write_memory_start(); ptr = (rt_uint16_t*)pixels; while(size--) { lcd_write_data(*ptr++); } } static const struct rt_device_graphic_ops ili9481_ops = { ili9481_lcd_set_pixel, ili9481_lcd_get_pixel, ili9481_lcd_draw_hline, ili9481_lcd_draw_vline, ili9481_lcd_blit_line }; static rt_err_t lcd_init(rt_device_t dev) { return RT_EOK; } static rt_err_t lcd_open(rt_device_t dev, rt_uint16_t oflag) { return RT_EOK; } static rt_err_t lcd_close(rt_device_t dev) { return RT_EOK; } static rt_err_t lcd_control(rt_device_t dev, rt_uint8_t cmd, void *args) { rt_err_t result = -RT_EIO; switch (cmd) { case RTGRAPHIC_CTRL_GET_INFO: { struct rt_device_graphic_info *info; info = (struct rt_device_graphic_info*) args; RT_ASSERT(info != RT_NULL); info->bits_per_pixel = 16; info->pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P; info->framebuffer = RT_NULL; info->width = LCD_WIDTH; info->height = LCD_HEIGHT; result = RT_EOK; } break; case RTGRAPHIC_CTRL_RECT_UPDATE: /* nothong to be done */ break; default: break; } return result; } static void _lcd_gpio_init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); /* Enable SYSCFG clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); /*reset Pin PB7*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); } static void lcd_fsmc_config(void) { FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef p; /*-- FSMC Configuration ------------------------------------------------------*/ p.FSMC_AddressSetupTime = 3; p.FSMC_AddressHoldTime = 0; p.FSMC_DataSetupTime = 4; p.FSMC_BusTurnAroundDuration = 0; p.FSMC_CLKDivision = 0; p.FSMC_DataLatency = 0; p.FSMC_AccessMode = FSMC_AccessMode_B; FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); /*!< Enable FSMC Bank1_SRAM1 Bank */ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); } static void lcd_initial(void) { lcd_write_cmd (SOFT_RESET); Delay1ms(20); lcd_write_cmd (EXIT_SLEEP_MODE); Delay1ms(20); lcd_write_cmd (ENTER_NORMAL_MODE); lcd_write_cmd (POWER_SETTING); lcd_write_data(0x07); lcd_write_data(0x41); lcd_write_data(0x1d); Delay1ms(20); lcd_write_cmd (VCOM_CONTROL); lcd_write_data(0x00); lcd_write_data(0x1c); lcd_write_data(0x1f); lcd_write_cmd (POWER_SETTING_FOR_NORMAL_MODE); lcd_write_data(0x0001); lcd_write_data(0x0011); lcd_write_cmd (PANEL_DRIVING_SETTING); lcd_write_data(0x00); // 设置扫描模式 lcd_write_data(0x3b); // 设定行数480行 lcd_write_data(0x00); lcd_write_data(0x02); // 5frames lcd_write_data(0x11); lcd_write_cmd (DISPLAY_TIMING_SETTING_FOR_NORMAL_MODE); lcd_write_data(0x10); lcd_write_data(0x0b); lcd_write_data(0x88); lcd_write_cmd (FRAME_RATE_AND_INVERSION_CONTROL); lcd_write_data(0x01); // 100hz lcd_write_cmd (GAMMA_SETTING); lcd_write_data(0x00); lcd_write_data(0x26); lcd_write_data(0x21); lcd_write_data(0x00); lcd_write_data(0x00); lcd_write_data(0x1f); lcd_write_data(0x65); lcd_write_data(0x23); lcd_write_data(0x77); lcd_write_data(0x00); lcd_write_data(0x0f); lcd_write_data(0x00); lcd_write_cmd (SET_ADDRESS_MODE); lcd_write_data(0x0a); lcd_write_cmd (SET_PIXEL_FORMAT); lcd_write_data(0x55); lcd_write_cmd (SET_DISPLAY_ON); lcd_write_cmd (WRITE_MEMORY_START); Delay1ms(20); lcd_clear(0x0000); } void device_code_read(void) { unsigned short id[6]={0,0,0,0,0,0},t; lcd_write_cmd(DEVICE_CODE_READ); id[0] = lcd_read_data(); id[1] = lcd_read_data(); id[2] = lcd_read_data(); id[3] = lcd_read_data(); id[4] = lcd_read_data(); id[5] = lcd_read_data(); for(t=0;t<6;t++) rt_kprintf("LCD Device Code id%d is: 0x%04X ",t,id[t]); } void ili9481_init(void) { _lcd_gpio_init(); GPIO_ResetBits(GPIOB, GPIO_Pin_7); /* RESET LCD */ lcd_fsmc_config(); Delay1ms(20); GPIO_SetBits(GPIOB, GPIO_Pin_7); /* release LCD */ Delay1ms(20); lcd_initial(); device_code_read(); /* register lcd device */ _lcd_device.type = RT_Device_Class_Graphic; _lcd_device.init = lcd_init; _lcd_device.open = lcd_open; _lcd_device.close = lcd_close; _lcd_device.control = lcd_control; _lcd_device.read = RT_NULL; _lcd_device.write = RT_NULL; _lcd_device.user_data = (void *)&ili9481_ops; /* register graphic device driver */ rt_device_register(&_lcd_device, "lcd", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE); } ``` ```#ifndef __ILI9481_H__ #define __ILI9481_H__ #define NOP 0x00 #define SOFT_RESET 0x01 #define GET_RED_CHANNEL 0x06 #define GET_GREEN_CHANNEL 0x07 #define GET_BLUE_CHANNEL 0x08 #define GET_POWER_MODE 0x0A #define GET_ADDRESS_MODE 0x0B #define GET_PIXEL_FORMAT 0x0C #define GET_DISPLAY_MODE 0x0D #define GET_SIGNAL_MODE 0x0E #define GET_DIAGNOSTIC_RESULT 0x0F #define ENTER_SLEEP_MODE 0x10 #define EXIT_SLEEP_MODE 0x11 #define ENTER_PARTIAL_MODE 0x12 #define ENTER_NORMAL_MODE 0x13 #define EXIT_INVERT_MODE 0x20 #define ENTER_INVERT_MODE 0x21 #define SET_GAMMA_CURVE 0x26 #define SET_DISPLAY_OFF 0x28 #define SET_DISPLAY_ON 0x29 #define SET_COLUMN_ADDRESS 0x2A #define SET_PAGE_ADDRESS 0x2B #define WRITE_MEMORY_START 0x2C #define WITE_LUT 0x2D #define READ_MEMORY_START 0x2E #define SET_PARTIAL_AREA 0x30 #define SET_SCROLL_AREA 0x33 #define SET_TEAR_OFF 0x34 #define SET_TEAR_ON 0x35 #define SET_ADDRESS_MODE 0x36 #define SET_SCROLL_START 0x37 #define EXIT_IDLE_MODE 0x38 #define ENTER_IDLE_MODE 0x39 #define SET_PIXEL_FORMAT 0x3A #define WRITE_MEMORY_CONTINUE 0x3C #define READ_MEMORY_CONTINUE 0x3E #define SET_TEAR_SCANLINE 0x44 #define GET_SCANLINE 0x45 #define READ_DDB_START 0xA1 #define READ_DDB_CONTINUE 0xA8 #define COMMAND_ACCESS_PROTECT 0xB0 #define LOW_POWER_MODE_CONTROL 0xB1 #define FRAME_MEMORY_ACCESS_AND_INTERFACE_SETTING 0xB3 #define DISPLAY_MODE_AND_FRAME_MEMORY_WRITE_MODE_SETTING 0xB4 #define DEVICE_CODE_READ 0xBF #define PANEL_DRIVING_SETTING 0xC0 #define DISPLAY_TIMING_SETTING_FOR_NORMAL_MODE 0xC1 #define DISPLAY_TIMING_SETTING_FOR_PARTIAL_MODE 0xC2 #define DISPLAY_TIMING_SETTING_FOR_IDLE_MODE 0xC3 #define FRAME_RATE_AND_INVERSION_CONTROL 0xC5 #define INTERFACE_CONTROL 0xC6 #define GAMMA_SETTING 0xC8 #define POWER_SETTING 0xD0 #define VCOM_CONTROL 0xD1 #define POWER_SETTING_FOR_NORMAL_MODE 0xD2 #define POWER_SETTING_FOR_PARTIAL_MODE 0xD3 #define POWER_SETTING_FOR_IDLE_MODE 0xD4 #define NV_MEMORY_WRITE 0xE0 #define NV_MEMORY_CONTROL 0xE1 #define NV_MEMORY_STATUS 0xE2 #define NV_MEMORY_PROTECTION 0xE3 #define LSI_TEST_REGISTERS 0xB0 void ili9481_init(void); #endif ```
查看更多
3
个回答
默认排序
按发布时间排序
aozima
2013-07-13
调网络不抓包,调I2C等时序不上逻辑分析仪,就像电工不用万用表!多用整理的好的文字,比截图更省流量,还能在整理过程中思考。
欢迎分享。
nongxiaoming
2013-07-15
rt-thread大师兄
不错,手上也有个3.5寸的ILI9481控制器的屏幕,效果很好
撰写答案
登录
注册新账号
关注者
0
被浏览
3.6k
关于作者
hoverxx
这家伙很懒,什么也没写!
提问
7
回答
5
被采纳
0
关注TA
发私信
相关问题
1
有关动态模块加载的一篇论文
2
最近的调程序总结
3
晕掉了,这么久都不见layer2的踪影啊
4
继续K9ii的历程
5
[GUI相关] FreeType 2
6
[GUI相关]嵌入式系统中文输入法的设计
7
20081101 RT-Thread开发者聚会总结
8
嵌入式系统基础
9
linux2.4.19在at91rm9200 上的寄存器设置
10
[转]基于嵌入式Linux的通用触摸屏校准程序
推荐文章
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组件
最新文章
1
【NXP-MCXA153】 定时器驱动移植
2
GD32F450 看门狗驱动适配
3
【NXP-MCXA153】看门狗驱动移植
4
RT-Thread Studio V2.2.9 Release Note
5
CherryUSB的bootuf2配置
热门标签
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在线升级
PWM
freemodbus
flash
cubemx
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
编译报错
Debug
rt_mq_消息队列_msg_queue
SFUD
keil_MDK
msh
ulog
C++_cpp
MicroPython
本月问答贡献
踩姑娘的小蘑菇
7
个答案
2
次被采纳
a1012112796
18
个答案
1
次被采纳
Ryan_CW
5
个答案
1
次被采纳
红枫
4
个答案
1
次被采纳
张世争
4
个答案
1
次被采纳
本月文章贡献
YZRD
3
篇文章
6
次点赞
catcatbing
3
篇文章
6
次点赞
lizimu
2
篇文章
9
次点赞
qq1078249029
2
篇文章
2
次点赞
xnosky
2
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部