add ch32v307 risc-v support,IDE is MounRiver Studio
This commit is contained in:
233
board/TencentOS_Tiny_CH32V307_EVB/User/lcd_init.c
Normal file
233
board/TencentOS_Tiny_CH32V307_EVB/User/lcd_init.c
Normal file
@@ -0,0 +1,233 @@
|
||||
#include "lcd_init.h"
|
||||
#include "debug.h"
|
||||
|
||||
void LCD_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE, ENABLE);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(GPIOE,GPIO_Pin_0|GPIO_Pin_1,1);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_3;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(GPIOD,GPIO_Pin_0,0);
|
||||
GPIO_WriteBit(GPIOD,GPIO_Pin_1|GPIO_Pin_3,1);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
<20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>LCD<43><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>뺯<EFBFBD><EBBAAF>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>dat Ҫд<D2AA><D0B4><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5> <20><>
|
||||
******************************************************************************/
|
||||
void LCD_Writ_Bus(u8 dat)
|
||||
{
|
||||
u8 i;
|
||||
//LCD_CS_Clr();
|
||||
for(i=0;i<8;i++)
|
||||
{
|
||||
LCD_SCLK_Clr();
|
||||
if(dat&0x80)
|
||||
{
|
||||
LCD_MOSI_Set();
|
||||
}
|
||||
else
|
||||
{
|
||||
LCD_MOSI_Clr();
|
||||
}
|
||||
LCD_SCLK_Set();
|
||||
dat<<=1;
|
||||
}
|
||||
//LCD_CS_Set();
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
<20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>LCDд<44><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>dat д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5> <20><>
|
||||
******************************************************************************/
|
||||
void LCD_WR_DATA8(u8 dat)
|
||||
{
|
||||
LCD_Writ_Bus(dat);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
<20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>LCDд<44><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>dat д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5> <20><>
|
||||
******************************************************************************/
|
||||
void LCD_WR_DATA(u16 dat)
|
||||
{
|
||||
LCD_Writ_Bus(dat>>8);
|
||||
LCD_Writ_Bus(dat);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
<20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>LCDд<44><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>dat д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5> <20><>
|
||||
******************************************************************************/
|
||||
void LCD_WR_REG(u8 dat)
|
||||
{
|
||||
LCD_DC_Clr();//д<><D0B4><EFBFBD><EFBFBD>
|
||||
LCD_Writ_Bus(dat);
|
||||
LCD_DC_Set();//д<><D0B4><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
<20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>x1,x2 <20><><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>ʼ<EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
y1,y2 <20><><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>ʼ<EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
<20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5> <20><>
|
||||
******************************************************************************/
|
||||
void LCD_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2)
|
||||
{
|
||||
if(USE_HORIZONTAL==0)
|
||||
{
|
||||
LCD_WR_REG(0x2a);//<2F>е<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
LCD_WR_DATA(x1);
|
||||
LCD_WR_DATA(x2);
|
||||
LCD_WR_REG(0x2b);//<2F>е<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
LCD_WR_DATA(y1);
|
||||
LCD_WR_DATA(y2);
|
||||
LCD_WR_REG(0x2c);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д
|
||||
}
|
||||
else if(USE_HORIZONTAL==1)
|
||||
{
|
||||
LCD_WR_REG(0x2a);//<2F>е<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
LCD_WR_DATA(x1);
|
||||
LCD_WR_DATA(x2);
|
||||
LCD_WR_REG(0x2b);//<2F>е<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
LCD_WR_DATA(y1+80);
|
||||
LCD_WR_DATA(y2+80);
|
||||
LCD_WR_REG(0x2c);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д
|
||||
}
|
||||
else if(USE_HORIZONTAL==2)
|
||||
{
|
||||
LCD_WR_REG(0x2a);//<2F>е<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
LCD_WR_DATA(x1);
|
||||
LCD_WR_DATA(x2);
|
||||
LCD_WR_REG(0x2b);//<2F>е<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
LCD_WR_DATA(y1);
|
||||
LCD_WR_DATA(y2);
|
||||
LCD_WR_REG(0x2c);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д
|
||||
}
|
||||
else
|
||||
{
|
||||
LCD_WR_REG(0x2a);//<2F>е<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
LCD_WR_DATA(x1+80);
|
||||
LCD_WR_DATA(x2+80);
|
||||
LCD_WR_REG(0x2b);//<2F>е<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
LCD_WR_DATA(y1);
|
||||
LCD_WR_DATA(y2);
|
||||
LCD_WR_REG(0x2c);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д
|
||||
}
|
||||
}
|
||||
|
||||
void LCD_Init(void)
|
||||
{
|
||||
LCD_GPIO_Init();//<2F><>ʼ<EFBFBD><CABC>GPIO
|
||||
|
||||
LCD_RES_Clr();//<2F><>λ
|
||||
Delay_Ms(100);
|
||||
LCD_RES_Set();
|
||||
Delay_Ms(100);
|
||||
|
||||
LCD_BLK_Set();//<2F><EFBFBD><F2BFAAB1><EFBFBD>
|
||||
Delay_Ms(100);
|
||||
|
||||
//************* Start Initial Sequence **********//
|
||||
LCD_WR_REG(0x11); //Sleep out
|
||||
Delay_Ms(120); //Delay 120ms
|
||||
//************* Start Initial Sequence **********//
|
||||
LCD_WR_REG(0x36);
|
||||
if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x00);
|
||||
else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC0);
|
||||
else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x70);
|
||||
else LCD_WR_DATA8(0xA0);
|
||||
|
||||
LCD_WR_REG(0x3A);
|
||||
LCD_WR_DATA8(0x05);
|
||||
|
||||
LCD_WR_REG(0xB2);
|
||||
LCD_WR_DATA8(0x0C);
|
||||
LCD_WR_DATA8(0x0C);
|
||||
LCD_WR_DATA8(0x00);
|
||||
LCD_WR_DATA8(0x33);
|
||||
LCD_WR_DATA8(0x33);
|
||||
|
||||
LCD_WR_REG(0xB7);
|
||||
LCD_WR_DATA8(0x35);
|
||||
|
||||
LCD_WR_REG(0xBB);
|
||||
LCD_WR_DATA8(0x32); //Vcom=1.35V
|
||||
|
||||
LCD_WR_REG(0xC2);
|
||||
LCD_WR_DATA8(0x01);
|
||||
|
||||
LCD_WR_REG(0xC3);
|
||||
LCD_WR_DATA8(0x15); //GVDD=4.8V <20><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
|
||||
|
||||
LCD_WR_REG(0xC4);
|
||||
LCD_WR_DATA8(0x20); //VDV, 0x20:0v
|
||||
|
||||
LCD_WR_REG(0xC6);
|
||||
LCD_WR_DATA8(0x0F); //0x0F:60Hz
|
||||
|
||||
LCD_WR_REG(0xD0);
|
||||
LCD_WR_DATA8(0xA4);
|
||||
LCD_WR_DATA8(0xA1);
|
||||
|
||||
LCD_WR_REG(0xE0);
|
||||
LCD_WR_DATA8(0xD0);
|
||||
LCD_WR_DATA8(0x08);
|
||||
LCD_WR_DATA8(0x0E);
|
||||
LCD_WR_DATA8(0x09);
|
||||
LCD_WR_DATA8(0x09);
|
||||
LCD_WR_DATA8(0x05);
|
||||
LCD_WR_DATA8(0x31);
|
||||
LCD_WR_DATA8(0x33);
|
||||
LCD_WR_DATA8(0x48);
|
||||
LCD_WR_DATA8(0x17);
|
||||
LCD_WR_DATA8(0x14);
|
||||
LCD_WR_DATA8(0x15);
|
||||
LCD_WR_DATA8(0x31);
|
||||
LCD_WR_DATA8(0x34);
|
||||
|
||||
LCD_WR_REG(0xE1);
|
||||
LCD_WR_DATA8(0xD0);
|
||||
LCD_WR_DATA8(0x08);
|
||||
LCD_WR_DATA8(0x0E);
|
||||
LCD_WR_DATA8(0x09);
|
||||
LCD_WR_DATA8(0x09);
|
||||
LCD_WR_DATA8(0x15);
|
||||
LCD_WR_DATA8(0x31);
|
||||
LCD_WR_DATA8(0x33);
|
||||
LCD_WR_DATA8(0x48);
|
||||
LCD_WR_DATA8(0x17);
|
||||
LCD_WR_DATA8(0x14);
|
||||
LCD_WR_DATA8(0x15);
|
||||
LCD_WR_DATA8(0x31);
|
||||
LCD_WR_DATA8(0x34);
|
||||
LCD_WR_REG(0x21);
|
||||
|
||||
LCD_WR_REG(0x29);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user