清单
1、RT-Thread Studio
2、Raspberry Pi Pico
3、lcd屏幕(ILI9341)
开始
1、基于开发板建工程
2、在RT-Thread Settings中添加软件包下面
3、添加完成并保存后,打开图中的开关并保存
4、在drv_lcd.c中修改static void LCD_InitReg(void)
/******************************************************************************
function : Initialize the lcd register
parameter:
******************************************************************************/
static void LCD_InitReg(void)
{
LCD_SendCommand(0xCF);
LCD_SendData_8Bit(0x00);
LCD_SendData_8Bit(0xD9); //0xC1
LCD_SendData_8Bit(0X30);
LCD_SendCommand(0xED);
LCD_SendData_8Bit(0x64);
LCD_SendData_8Bit(0x03);
LCD_SendData_8Bit(0X12);
LCD_SendData_8Bit(0X81);
LCD_SendCommand(0xE8);
LCD_SendData_8Bit(0x85);
LCD_SendData_8Bit(0x10);
LCD_SendData_8Bit(0x7A);
LCD_SendCommand(0xCB);
LCD_SendData_8Bit(0x39);
LCD_SendData_8Bit(0x2C);
LCD_SendData_8Bit(0x00);
LCD_SendData_8Bit(0x34);
LCD_SendData_8Bit(0x02);
LCD_SendCommand(0xF7);
LCD_SendData_8Bit(0x20);
LCD_SendCommand(0xEA);
LCD_SendData_8Bit(0x00);
LCD_SendData_8Bit(0x00);
LCD_SendCommand(0xC0); //Power control
LCD_SendData_8Bit(0x1B); //VRH[5:0]
LCD_SendCommand(0xC1); //Power control
LCD_SendData_8Bit(0x12); //SAP[2:0];BT[3:0] 0x01
LCD_SendCommand(0xC5); //VCM control
LCD_SendData_8Bit(0x08); //30
LCD_SendData_8Bit(0x26); //30
LCD_SendCommand(0xC7); //VCM control2
LCD_SendData_8Bit(0XB7);
LCD_SendCommand(0x36); // Memory Access Control
LCD_SendData_8Bit(0x08);
LCD_SendCommand(0x3A);
LCD_SendData_8Bit(0x55);
LCD_SendCommand(0xB1);
LCD_SendData_8Bit(0x00);
LCD_SendData_8Bit(0x1A);
LCD_SendCommand(0xB6); // Display Function Control
LCD_SendData_8Bit(0x0A);
LCD_SendData_8Bit(0xA2);
LCD_SendCommand(0xF2); // 3Gamma Function Disable
LCD_SendData_8Bit(0x00);
LCD_SendCommand(0x26); //Gamma curve selected
LCD_SendData_8Bit(0x01);
LCD_SendCommand(0xE0); //Set Gamma
LCD_SendData_8Bit(0x0F);
LCD_SendData_8Bit(0x1D);
LCD_SendData_8Bit(0x1A);
LCD_SendData_8Bit(0x0A);
LCD_SendData_8Bit(0x0D);
LCD_SendData_8Bit(0x07);
LCD_SendData_8Bit(0x49);
LCD_SendData_8Bit(0X66);
LCD_SendData_8Bit(0x3B);
LCD_SendData_8Bit(0x07);
LCD_SendData_8Bit(0x11);
LCD_SendData_8Bit(0x01);
LCD_SendData_8Bit(0x09);
LCD_SendData_8Bit(0x05);
LCD_SendData_8Bit(0x04);
LCD_SendCommand(0XE1); //Set Gamma
LCD_SendData_8Bit(0x00);
LCD_SendData_8Bit(0x18);
LCD_SendData_8Bit(0x1D);
LCD_SendData_8Bit(0x02);
LCD_SendData_8Bit(0x0F);
LCD_SendData_8Bit(0x04);
LCD_SendData_8Bit(0x36);
LCD_SendData_8Bit(0x13);
LCD_SendData_8Bit(0x4C);
LCD_SendData_8Bit(0x07);
LCD_SendData_8Bit(0x13);
LCD_SendData_8Bit(0x0F);
LCD_SendData_8Bit(0x2E);
LCD_SendData_8Bit(0x2F);
LCD_SendData_8Bit(0x05);
LCD_SendCommand(0x2B);
LCD_SendData_8Bit(0x00);
LCD_SendData_8Bit(0x00);
LCD_SendData_8Bit(0x01);
LCD_SendData_8Bit(0x3f);
LCD_SendCommand(0x2A);
LCD_SendData_8Bit(0x00);
LCD_SendData_8Bit(0x00);
LCD_SendData_8Bit(0x00);
LCD_SendData_8Bit(0xef);
LCD_SendCommand(0x11); //Exit Sleep
rt_thread_mdelay(120);
LCD_SendCommand(0x29); //display on
}
5、在drv_lcd.c中修改static void LCD_SetAttributes(UBYTE Scan_dir)
/********************************************************************************
function: Set the resolution and scanning method of the screen
parameter:
Scan_dir: Scan direction
********************************************************************************/
static void LCD_SetAttributes(UBYTE Scan_dir)
{
// Get the screen scan direction
LCD.SCAN_DIR = Scan_dir;
UBYTE MemoryAccessReg = 0x00;
switch(Scan_dir){
case 0:
LCD.WIDTH=LCD_WIDTH;
LCD.HEIGHT=LCD_HEIGHT;
MemoryAccessReg=((1<<3)|(0<<6)|(0<<7));//BGR==1,MY==0,MX==0,MV==0
break;
case 1:
LCD.WIDTH=LCD_HEIGHT;
LCD.HEIGHT=LCD_WIDTH;
MemoryAccessReg=((1<<3)|(0<<7)|(1<<6)|(1<<5));//BGR==1,MY==1,MX==0,MV==1
break;
case 2:
LCD.WIDTH=LCD_WIDTH;
LCD.HEIGHT=LCD_HEIGHT;
MemoryAccessReg=((1<<3)|(1<<6)|(1<<7));//BGR==1,MY==0,MX==0,MV==0
break;
case 3:
LCD.WIDTH=LCD_HEIGHT;
LCD.HEIGHT=LCD_WIDTH;
MemoryAccessReg=((1<<3)|(1<<7)|(1<<5));//BGR==1,MY==1,MX==0,MV==1
break;
default:break;
}
// Set the read / write scan direction of the frame memory
LCD_SendCommand(0x36); // MX, MY, RGB mode
LCD_SendData_8Bit(MemoryAccessReg); // 0x08 set RGB
}
6、在drv_lcd.h中修改屏幕参数
7、在lv_conf.h中修改屏幕参数
8、在lv_rt_thread_port.c中修改lvgl_thread_init
static void lvgl_thread_entry(void *parameter)
{
#if LV_USE_LOG
lv_log_register_print_cb(lv_rt_log);
#endif /* LV_USE_LOG */
// lv_init();
// lv_port_disp_init();
// lv_port_indev_init();
// lv_user_gui_init();
/* handle the tasks of LVGL */
// while(1)
// {
// lv_task_handler();
// rt_thread_mdelay(LV_DISP_DEF_REFR_PERIOD);
// }
}
static int lvgl_thread_init(void)
{
// rt_err_t err;
//
// err = rt_thread_init(&lvgl_thread, "LVGL", lvgl_thread_entry, RT_NULL,
// &lvgl_thread_stack[0], sizeof(lvgl_thread_stack), PKG_LVGL_THREAD_PRIO, 10);
// if(err != RT_EOK)
// {
// LOG_E("Failed to create LVGL thread");
// return -1;
// }
// rt_thread_startup(&lvgl_thread);
lv_init();
lv_port_disp_init();
lv_port_indev_init();
return 0;
}
INIT_ENV_EXPORT(lvgl_thread_init);
9、确认lv_demo.c中是否加入music示例
10、编译成功后将uf2文件下载到pico中即可
注意
1、硬件连接在lv_lcd.hzhong
2、工程目录
3、pico引脚图
效果