⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 这个是我写的一个液晶显示器的驱动程序
💻 C
字号:
#include"include.h"
/*************************************************
  Function:       delay
  Description:    延时一段时间
  Calls:          无
  Input:          无
  Output:         无
  Return:         无
  Others:         
*************************************************/
void delay(void)
{
	uchar i;
	for(i=0;i<10;i++);
}
/*************************************************
  Function:       LCDRESET
  Description:    LCD复位
  Calls:          无
  Input:          无
  Output:         无
  Return:         无
  Others:         
*************************************************/
void  LCDRESET()
{
	LCD_Rest=0;
	delay();
	LCD_Rest=1;	  
}

void Set_Init_L(uchar Control)
{
	delay();
	Left_Instruction = Control;
	delay();
}

void Set_Init_R(uchar Control)
{
    delay();
    Right_Instruction = Control;
    delay();
}

/*************************************************
  Function:       WR_Data_L
  Description:    向液晶屏的写地址写入要显示的内容
  Calls:          无
  Input:          L_R:左右屏的选择,data:要写入的内容
  Output:         无
  Return:         无
  Others:         
*************************************************/
void WR_Data_L(uchar d)
{
	delay();
	Left_Data =d;
	delay();
}

void WR_Data_R(uchar d)
{
    delay();
    Right_Data = d;
    delay();
}

/*************************************************
  Function:       ShowHanzi_L
  Description:    在左屏输出一个汉字
  Calls:          无
  Input:          x,y在屏上输出的坐标,p输出内容的地址指针
  Output:         无
  Return:         无
  Others:         
*************************************************/
void Show_C_L(uchar x,uchar y,uchar *p)
{
	uchar i;
	Set_Init_L(SetXadress(x));
	Set_Init_L(SetYadress(y));
	for(i=0;i<16;i++)
	{
	WR_Data_L(p[i]);
	}
	
	Set_Init_L(SetXadress(x+1));
	Set_Init_L(SetYadress(y));
	for(i=0;i<16;i++)
	{
		WR_Data_L(p[i+16]);  
	}
}

void Show_C_R(uchar x,uchar y,uchar *p)
{
	uchar i;
	Set_Init_R(SetXadress(x));
	Set_Init_R(SetYadress(y));
	for(i=0;i<16;i++)
	{
	WR_Data_R(p[i]);
	}
	
	Set_Init_R(SetXadress(x+1));
	Set_Init_R(SetYadress(y));
	for(i=0;i<16;i++)
	{
		WR_Data_R(p[i+16]);  
	}
}

/*************************************************
  Function:       PrintHanzi
  Description:    输出N个汉字
  Calls:          无
  Input:          x,y在屏上输出的坐标,p输出内容的地址指针
  Output:         无
  Return:         无
  Others:         
*************************************************/
void PrintHanzi(uchar x,uchar y,uchar *p)
{
    uchar i,j;
    uchar num= 0;
    num = (uchar)strlen(p);
    for(j=0;j<num;j+=2)
    {		
		if(y>63)
		{
		    if(y>127)break;
		    
         	for(i = 0;i<22;i++)
	        {
			    if((hanz[i].id[0]==p[j])&&(hanz[i].id[1]==p[j+1]))
			    {
			        Show_C_R(x,(y-64),hanz[i].font);
			        y+=16;
			    }
	        }
		}
		else
		{
		    for(i = 0;i<22;i++)
	        {
			    if((hanz[i].id[0]==p[j])&&(hanz[i].id[1]==p[j+1]))
			    {
			        Show_C_L(x,y,hanz[i].font);
			        y+=16;
			    }
	        }
		}
		   
    }
}
/*************************************************
  Function:       ShowA_L
  Description:    在屏上输出任意字符
  Calls:          无
  Input:          x,y在屏上输出的坐标,p输出内容的地址指针
  Output:         无
  Return:         无
  Others:         
*************************************************/
void Lcd_Print(uchar x,uchar y,char *Str)
{
    unsigned int Num = 0;//输入字符串的字节数
    uchar i;
    Num = (uchar)strlen(Str);
    for(i = 0;i<Num;)
    {	
        if(y>63)//右半屏显示
        {
            if(y>127)break;

            
	        if((Str[i]>=0x21)&&(Str[i]<=0x7f))//要显示的是英文字母或者是特殊符号
		    {
		        Show_E_R(x,(y-64),(Str[i] - 0x21)*16+ASCIICD);
		        y+=8;
		        i++;
		    }
		    else//要显示的是汉字
		    { 	
			    uchar m;//汉字库中汉字数
		        for(m= 0;m<22;m++)
		        {
				    if((hanz[m].id[0]==Str[i])&&(hanz[m].id[1]==Str[i+1]))
				    {
				        Show_C_R(x,(y-64),hanz[m].font);
				    }			        
		        }
		        y+=16;
				i+=2;
		    }
        }
        else//左半屏显示
        {
        	if((Str[i]>=0x21)&&(Str[i]<=0x7f))//要显示的是英文户或者是特殊符号
		    {
		        Show_E_L(x,y,(Str[i] - 0x21)*16+ASCIICD);
		        y+=8;
		        i++;
		    }
		    else//要显示的是汉字
		    { 	
			    uchar m;//汉字库中汉字数
		        for(m= 0;m<22;m++)
		        {
				    if((hanz[m].id[0]==Str[i])&&(hanz[m].id[1]==Str[i+1]))
				    {
				        Show_C_L(x,y,hanz[m].font);
				    }			        
		        }
		        y+=16;
				i+=2;
		    }
        }


    }
}

/*************************************************
  Function:       ShowA_L
  Description:    在左屏上输出单个ASCII码字符
  Calls:          无
  Input:          x,y在屏上输出的坐标,p输出内容的地址指针
  Output:         无
  Return:         无
  Others:         
*************************************************/
void Show_E_L(uchar x,uchar y,uchar *p)
{
	uchar i;
	Set_Init_L(SetXadress(x));
	Set_Init_L(SetYadress(y));
	for(i=0;i<8;i++)
	{
	 	WR_Data_L(p[i]); 
	}
	Set_Init_L(SetXadress(x+1));
	Set_Init_L(SetYadress(y));
	for(i=0;i<8;i++)
	{
		WR_Data_L(p[i+8]);  
	}
}

void Show_E_R(uchar x,uchar y,uchar *p)
{
	uchar i;
	Set_Init_R(SetXadress(x));
	Set_Init_R(SetYadress(y));
	for(i=0;i<8;i++)
	{
        WR_Data_R(p[i]);
	}
	Set_Init_R(SetXadress(x+1));
	Set_Init_R(SetYadress(y));
	for(i=0;i<8;i++)
	{
		WR_Data_R(p[i+8]);  
	}
}
/*************************************************
  Function:       PrintABC
  Description:    输出字符串
  Calls:          无
  Input:          x,y在屏上输出的坐标,p输出内容的地址指针
  Output:         无
  Return:         无
  Others:         
*************************************************/
void PrintABC(uchar x,uchar y,uchar *pAdre)
{
	while(*pAdre!='\0')
	{		
	    if(y>63)
        {
        if(y>127)break;
            Show_E_R(x,(y-64),(*pAdre - 0x21)*16+ASCIICD);
            pAdre++;
            y+=8;
        }
        else
        {
			Show_E_L(x,y,(*pAdre - 0x21)*16+ASCIICD);
			pAdre++;
			y+=8;
		}
	} 
}

/*************************************************
  Function:       ClearScreen_L
  Description:    左半屏清屏
  Calls:          无
  Input:          无
  Output:         无
  Return:         无
  Others:         
*************************************************/

void ClearScreen_L(void)
{
	uchar x,y;
	for(x=0;x<8;x++)
	{
		Set_Init_L(SetXadress(x)); 
		Set_Init_L(SetYadress(0));
		for(y=0;y<64;y++)
		{
			WR_Data_L(0x00); 
		}
	}
}

void ClearScreen_R(void)
{
	uchar x,y;
	for(x=0;x<8;x++)
	{
		Set_Init_R(SetXadress(x)); 
		Set_Init_R(SetYadress(0));
		for(y=0;y<64;y++)
		{
			WR_Data_R(0x00); 
		}
	}
}

void Lcd_Init()
{
	LCDRESET();
	
	Set_Init_L(DISP_ON );
	ClearScreen_L(); 
	Set_Init_L(Startline(0));

	delay();

	Set_Init_R(DISP_ON );
	ClearScreen_R(); 
	Set_Init_R(Startline(0));
}

void main ()
{   
    Lcd_Init();
	PrintHanzi(0, 0,"欢迎使用系统");
	Lcd_Print(2, 0,"hello!asd");
	while(1)
	{
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -