The lcd module of embedded learning: ILI9341

1. To be clear, the command is the same as
Insert picture description herethe address of the register to be written by the command. For example, after writing 2A to the register with address 2A, the column address setting is turned on, and then writing data later is to set the corresponding parameter. Of course, how to identify whether you are entering data or commands? It is controlled by the bus RS.
2. Implementation points:
(1) Seven lowest-level functions:
Insert picture description hereuse the corresponding I port to simulate timing to achieve data or command reading and writing
(2) Initialize the IO port and the initialization of the LCD (provided by the manufacturer)

void LCD_Init(void)

(3) Basic application function (first-level function):

//设置光标位置
void LCD_SetCursor(u16 Xpos, u16 Ypos)
//设置窗口,并自动设置画点坐标到窗口左上角(sx,sy).
void LCD_Set_Window(u16 sx,u16 sy,u16 width,u16 height)
//快速画点,一般用这个(这个很常用,所有显示不都得画点嘛)
void LCD_Fast_DrawPoint(u16 x,u16 y,u16 color)
//读取个某点的颜色值
u16 LCD_ReadPoint(u16 x,u16 y)
//设置光标位置
void LCD_SetCursor(u16 Xpos, u16 Ypos)

LCD_ReadPoint() calls LCD_SetCursor() to set the coordinates of the point to be read, of course, there are also calls in other places.
And this LCD_ReadPoint() also has a way, he regrouped RGB after separating it. Because only RG can be read at one time, B is in another parameter
Insert picture description here(4) The upper call function (secondary function)
a Chinese character display program: use an array to store the corresponding Chinese character index, and then display the corresponding Chinese character according to the index.

void LCD_ShowChinese(u16 x,u16 y,u8 size,u8 mode,u8 *p)
{
    
    
	u8 *array;
	u8 i=0,k=0;
	array =(u8*)malloc(10*sizeof(u8));
	while(*p!='\0')
	{
    
    
		if((cfont16[i].Index[0]==*p)&&(cfont16[i].Index[1]==*(p+1)))
		{
    
    
			array[k]=cfont16[i].number;
			k++;
			p+=2;
		}
		i++;
	}
	num=k;
	for (i=0;i<k;i++)
	printf("%d",array[i]);
  LCD_ShowChinese(x,y,size,mode,array);
}
void LCD_ShowCChar(u16 x,u16 y,u8 size,u8 mode,u8 *array)
{
    
             
	u8 temp,t,t1;
	u8 i=0;
	u16 y0=y;
	u8 *dzk;
	u8 csize=(size/8+((size%8)?1:0))*(size);			//得到字体一个字符对应点阵集所占的字节数	 
	if(size!=12&&size!=16&&size!=24&&size!=32)return;	//不支持的size
	for(i = 0;i<num;i++)
	{
    
    
			dzk=(u8*)asc2_1616[array[i]];
		for(t=0;t<csize;t++)
		{
    
       												   
			temp=dzk[t];			//得到点阵数据                          
			for(t1=0;t1<8;t1++)
			{
    
    
				if(temp&0x80)LCD_Fast_DrawPoint(x,y,POINT_COLOR);
				else if(mode==0)LCD_Fast_DrawPoint(x,y,BACK_COLOR); 
				temp<<=1;
				y++;
				if((y-y0)==size)
				{
    
    
					y=y0;
					x++;
					break;
				}
			}  	 
		} 
		x+=5;
	}
 free(array);
}

Guess you like

Origin blog.csdn.net/weixin_44142774/article/details/106180340