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

📄 lcddrv.c

📁 LPC213x系列微处理器操作SED1335液晶显示屏的驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
#include  "config.h"
#include "RD_LPC2100.h"
#include <stdarg.h>
#include <stdio.h>


#include "ASCII.h"
#include "LCDDRV.h"
#include "bmp1.h"


uchar gCurRow,gCurCol;	// 当前行、列存储,行高16点,列宽8点
uchar const *MenuIndex[5]={Bmp001,Bmp002,Bmp003,Bmp004};
const uchar uPowArr[]  = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar FBpos[] = {6,54,102,150,198};
uchar gCurLayer = 1;

tagCursor gCursor[2] = {
    0,0,1,
    0,0,1
};

typedef struct typFNT_GB16	// 汉字字模显示数据结构
{
	uchar Index[2];
	uchar Msk[32];
};
const struct typFNT_GB16  GB_16[] = {	// 显示为16*16
"中",0x01,0x00,0x01,0x00,0x21,0x08,0x3F,0xFC,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
"文",0x02,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x08,0x20,0x08,0x20,0x08,0x20,0x04,0x40,0x04,0x40,0x02,0x80,0x01,0x00,0x02,0x80,0x04,0x60,0x18,0x1E,0xE0,0x08,0x00,0x00,
"测",0x40,0x02,0x27,0xC2,0x24,0x42,0x84,0x52,0x45,0x52,0x55,0x52,0x15,0x52,0x25,0x52,0x25,0x52,0x25,0x52,0xC5,0x52,0x41,0x02,0x42,0x82,0x42,0x42,0x44,0x4A,0x48,0x04,
"试",0x00,0x20,0x40,0x28,0x20,0x24,0x30,0x24,0x27,0xFE,0x00,0x20,0xE0,0x20,0x27,0xE0,0x21,0x20,0x21,0x10,0x21,0x10,0x21,0x0A,0x29,0xCA,0x36,0x06,0x20,0x02,0x00,0x00,
};


uchar fnGetRow(void)
{
	return gCurRow;
}

uchar fnGetCol(void)
{
	return gCurCol;
}


/*-----------------------------------------------------------------------
delay_us	   :1us延时函数
void delay_us(void)
{
   unsigned char t=2;
   t--;
}
-----------------------------------------------------------------------*/
void delay_us(unsigned int time)
 {     
  do
	{
	time--;
	}	
  while (time>1);
 }		  

/*-----------------------------------------------------------------------
delay_nus          :长延时函数

输入参数: t        :延时时间 us
void delay_nus(unsigned int t)
{
    while (t--)
       delay_us();
}
-----------------------------------------------------------------------*/

/*-----------------------------------------------------------------------
delay_ms	   :1ms延时函数

void delay_ms(void)
{
   delay_nus(1000);
}
-----------------------------------------------------------------------*/
/*	    毫秒级延时函数	*/	 
void delay_ms(unsigned int time)
	 {
	  while(time!=0)
	  	  {	
		   delay_us(500);
		   time--;
		  }
	 }




/*-----------------------------------------------------------------------
delay_nms          :长延时函数
输入参数: t        :延时时间 ms
-----------------------------------------------------------------------*/
void delay_nms(unsigned int t)
{
    while (t--)
       delay_ms(t);
}

/**********************************************************
Name:          unsigned char LCDCheckBusy(void) 		  *
Description:   write a Cmd byte to LCD	 	  			  *
Input:         none          	   	   					  *
Output:        0 busy      none-0 idle					  *
Misc:          											  *
**********************************************************/
unsigned char LCDCheckBusy(void)
{
    unsigned char status,i;
    return 1;
    for(i=10;i>0;i--)
	{
		ReadStatus;
		status = LCMCW;
		ReadOK;
		if((status & 0x40) == 0x00)     //D6  1 busy  0 idle
			break;
	}
	return i;	// 若返回零,说明错误

}



/**********************************************************
Name:          void LCDWriteCmd(unsigned char byte)		  *
Description:   write a Cmd byte to LCD	 	  			  *
Input:         Command (Byte)	   	   					  *
Output:        none	   									  *
Misc:          											  *
**********************************************************/
void LCDWriteCmd(unsigned char byte)
{
    WriteCmd;
    LCMCW = byte;
    WriteOK;
}

/*************************************************************
Name:          void LCDWriteData(unsigned char byte)	  	 *
Description:   write a data byte to LCD	    			  	 *
Input:         unsigned char byte -> data to write on the LCD*
Output:        none			 	  	 	  	 	   	  	     *
Misc:          												 *
*************************************************************/
void LCDWriteData(unsigned char byte)
{
   if (LCDCheckBusy()!=0)
   {
        WriteData;
        LCMDW = byte;
        WriteOK;
   }
   
}

/***********************************************************
Name:       unsigned char LCDReadData(void)				   *
Description:   read a data byte from LCD				   *
Input:         none	  	   		   	   					   *
Output:        unsigned char byte -> Data read from the LCD*
Misc:          				 	  	 	  	   			   *
***********************************************************/
unsigned char LCDReadData(void)
{
   unsigned char byte =0;

   if (LCDCheckBusy()!=0)
   {
    ReadData;
    byte = LCMDW;
    ReadOK;
   } 
    return byte;
}

/***********************************************************
Name:       unsigned char LCDReadStatus(void)				   *
Description:   read a data byte from LCD				   *
Input:         none	  	   		   	   					   *
Output:        unsigned char byte -> Data read from the LCD*
Misc:          				 	  	 	  	   			   *
***********************************************************/
unsigned char LCDReadStatus(void)
{
   unsigned char byte;

    ReadStatus;
    byte = LCMDW;
    ReadOK;
    
    return byte;
}



/**********************************************************
Name:  void ClrSCR(void)								  *
Description:   Clear Screen layer 						  *
Input:         1--Clear Text Screen layer 1				  *
               2--Clear Graphic Screen layer 2			  *
Output:        none										  *
Misc:          											  *
**********************************************************/
void ClrSCR(char Layer)
{
   unsigned int i,EndPosition;
	unsigned char data,Position_H = 0;
	if(Layer == 1)
	{
	   Position_H = 0x00;
		  EndPosition = 9600;
	}	  
	else if (Layer == 2)
	{
	   Position_H = 0x26;
		  EndPosition = 9600; 
	}
   LCDWriteCmd(LC_CSRW);         					    // CURSOR WRITE COMMAND
   LCDWriteData(0x00);        						// Cursor position low byte  
   LCDWriteData(Position_H);        				// Cursor position high byte
   LCDWriteCmd(LC_MWRITE);       						// LCD WRITE MEMORY
   //DATAOUT = 0x00;
   //A0_L;                      						// A0 -> 0
   CDL;
   
   if (Layer == 1)
   {
        //LCMDW = 0x20;
        LCMDW = 0x00;
        //data = 0;
   }
   else
   {
        LCMDW = 0x00;
        //data = 0;
   }
   
   
   for (i=0;i<EndPosition;i++)
   {
      
      /*LCDWriteData(data);*/
      
      //WR_L;                   			   			// WR -> 0
      WRL;
      CDL;
      //WDR();
      //WR_H;
      WRH;
      CDL;
   }

   LCDWriteCmd(LC_CSRW);         						// CURSOR WRITE COMMAND
   LCDWriteData(0x00);        						// Cursor position low byte
   LCDWriteData(Position_H);        				// Cursor position high byte
}

/**********************************************************
Name:  void LCD_Init(void)								  *
Description:   Initialize a graphic of  X & Y			  *
Input:         #define  GUI_LCM_XMAX  ... 				  *
               #define  GUI_LCM_YMAX  ...				  *
Output:        none					  					  *
Misc:     	   											  *
**********************************************************/
void LCD_Init(void)
{
   unsigned int i,j;
   unsigned char k[16],m;



/*
//LCD Data Bus
   DATAOUT = 0x00;
   DATABUS = 0xff;             					    // PB0-7 as output
   LCD_CS_DDR |= LCD_CS_BIT;
   CS_L;

//LCD control Bus
   LCD_RES_DDR |= LCD_RES_BIT;
   LCD_RD_DDR  |= LCD_RD_BIT;
   LCD_WR_DDR  |= LCD_WR_BIT;

*/

//test
WRL;
WRH;
RDL;
RDH;
CEL;
CEH;
CDL;
CDH;
RESETL;
RESETH;
SetWrite;
LCMDW = 0x69;
LCMDW = 0xa3;

    CEL;
   //WR_H;                                            // WR -> 1
   WRH;
   //RD_H;                							// RD -> 1
   RDH;
   //LCD_A0_DDR |= LCD_A0_BIT;
   //RES_H;
   RESETH;
   
   DIR245H;
   
   //delay_nms(2);
   //RES_L;
   RESETL;               	  	  		   		    // Reset LCD
   /*delay_nms(2);
   delay_nms(2);
   delay_nms(2);
   delay_nms(2);
   delay_nms(2);
   delay_nms(2);*/
   //RES_H;
   RESETH;
   
   /*for (i=0;i<10;i++)
   {
      delay_nms(2);
   }*/

/*------SYSTEM SET COMMAND------*/
   LCDWriteCmd(LC_SYSTEM_SET);                         // SYSTEM SET COMMAND
   LCDWriteData(0x30);              				// P1   -> PRT=0, IV=1, W/S=0, M0-M2=0
   LCDWriteData(0x87);             					// FX   -> WF=1, FX=7
   LCDWriteData(0x07);              				// FY   -> FY=7
   LCDWriteData((GUI_LCM_XMAX/8)-1);    			// C/R  -> Char per line - 1
   LCDWriteData((XTAL / 70 / GUI_LCM_YMAX) / 9);    // TC/R -> ( f_osc / f_frame / [L/F] - 1 ) / 9
   //LCDWriteData((GUI_LCM_XMAX/8)+3);    // TC/R -> ( f_osc / f_frame / [L/F] - 1 ) / 9
   LCDWriteData(GUI_LCM_YMAX);         	 		// L/F  -> Line per graphic screen - 1 (127)
   LCDWriteData(GUI_LCM_XMAX/8);        			// APL  -> Virtual screen low byte ( char per line)
   LCDWriteData(0x00);        						// APH  -> Virtual screen low byte

/*--------SCROLL COMMAND--------*/
   LCDWriteCmd(LC_SCROLL);                             // SCROLL COMMAND
   LCDWriteData(0x00);        						// First Layer Low Byte  (0x0000)
   LCDWriteData(0x00);        						// First Layer Hign Byte
   LCDWriteData(GUI_LCM_YMAX);       				// 128 Line of scroll
   LCDWriteData(0x00);        						// Second Layer Low Byte (0x1000)
   LCDWriteData(0x26);        						// Second Layer Hign Byte
   LCDWriteData(GUI_LCM_YMAX);						// 128 Line of scroll
   LCDWriteData(0x00);        						// Second Layer Low Byte (0x1000)
   LCDWriteData(0x4c);        						// Second Layer Low Byte (0x1000)
   LCDWriteData(0x00);        						// Second Layer Low Byte (0x1000)
   LCDWriteData(0x72);        						// Second Layer Low Byte (0x1000)
   
/*--HORIZONTAL SCROLL POSITION--*/
   LCDWriteCmd(LC_HDOT_SCR);          					// HORIZONTAL SCROLL POSITION
   LCDWriteData(0x00);        						// no scrool offset

/*-------OVERLAY COMMAND--------*/
   LCDWriteCmd(LC_OVLAY);         	  					// OVERLAY COMMAND
   //LCDWriteData(0x03);        						// 2 layer (1-Text 2-Graphic)
   //LCDWriteData(0x0d);        						// 2 layer (1-Text 2-Graphic)
    //LCDWriteData(0x0b);
    LCDWriteData(0x04);

delay_ms(100); 

   LCDWriteCmd(LC_CSRFORM);          					// CURSOR FORMAT COMMAND
   LCDWriteData(0x05);        						// Cursor width (7)
   LCDWriteData(0x86);       						// Cursor Height(7) & Block type

LCDWriteCmd(LC_CSRDIR1); 
LCDWriteCmd(LC_CSRW); 
LCDWriteData(0x00); 
LCDWriteData(0x00); 
LCDWriteCmd(LC_DISP_ON); 
//LCDWriteData(0x16); 
LCDWriteData(0x06); 

LCDWriteCmd(LC_CSRR); 
k[14] = LCDReadData(); 
k[15] = LCDReadData(); 
i=9600; 
m=0x20;
LCDWriteCmd(LC_MWRITE); 
while(i--) { 
//k[i] = 0;
//LCDWriteData((i&0xff)); 
LCDWriteData(0xfa); 
    m++;

    if (m==0xdf)
    {
        m=0x20;
    }
    else if (m==0x80)
    {
        m=0xa0;
    }
}


LCDWriteCmd(LC_CSRW); 
LCDWriteData(0x00); 
LCDWriteData(0x26); 
LCDWriteCmd(LC_CSRR); 
k[14] = LCDReadData(); 
k[15] = LCDReadData(); 
i=9600;

LCDWriteCmd(LC_MWRITE); 
while(i--) { 
//k[i] = 0;
LCDWriteData(0xff); 
} 

LCDWriteCmd(LC_CSRW); 
LCDWriteData(0x00); 
LCDWriteData(0x4c); 
LCDWriteCmd(LC_CSRR); 
k[14] = LCDReadData(); 
k[15] = LCDReadData(); 
i=9600;
LCDWriteCmd(LC_MWRITE); 
while(i--) { 
//k[i] = 0;
LCDWriteData(0xc2); 
} 



LCDWriteCmd(LC_CSRR); 
k[14] = LCDReadData(); 
k[15] = LCDReadData(); 


LCDWriteCmd(LC_CSRW); 
LCDWriteData(0x00); 
LCDWriteData(0x26); 





i=9600;
LCDWriteCmd(LC_MREAD); 
while(i--) { 
k[0] = LCDReadData(); 
} 

LCDWriteCmd(LC_CSRR); 
k[12] = LCDReadData(); 
k[13] = LCDReadData(); 

LCDWriteCmd(LC_CSRW); 
LCDWriteData(0x00); 
LCDWriteData(0x00); 



/*----DISPLAY ON/OFF COMMAND
   LCDWriteCmd(LC_DISP_ON);         					// DISPLAY OFF COMMAND
   //LCDWriteData(0x14);        						// Layer 1 & 2 ON
   LCDWriteData(0x15);        						// Layer 1 & 2 ON
   ClrSCR(1);
   ClrSCR(2);
----*/
/*-----CURSOR FORMAT COMMAND
   LCDWriteCmd(LC_CSRFORM);          					// CURSOR FORMAT COMMAND
   LCDWriteData(0x05);        						// Cursor width (7)
   LCDWriteData(0x86);       						// Cursor Height(7) & Block type
----*/
/*---CURSOR DIRECTION COMMAND
   LCDWriteCmd(LC_CSRDIR1);          					// CURSOR DIRECTION COMMAND (SHIFT RIGHT)
---*/
/*-----CURSOR WRITE COMMAND

⌨️ 快捷键说明

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