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

📄 lcd_driver.c

📁 基于凌汛科技 CPU的sd卡驱动源代码。
💻 C
字号:
#include "SPCE061A.H"

//Define variables for LCD Commands//
#define  InstructionTemplate 0x0000 //Enable=0; R/W=0(Write); RS=0(Instruction Register)//
#define  DataTemplate 0x2000        //Enable=0; R/W=0(Write); RS=1(Data Register)       //

unsigned int CursorColumn;
unsigned int CursorLine;
unsigned char LEDState;
unsigned int LCDFLDat[16];

extern void Delay4us();

void W_Data(unsigned char WDAT);
void W_Instruction(unsigned int WCMDID);
void ClearDISP();
void ClearLocation();
void PutCursor(unsigned int CursorC,unsigned int CursorL);
void BackspaceControl();
void LCCalc();
void CursorBackHome();
void CursorBack();
void CursorForward();
void DisplayOFF();
void DisplayON();
void InitiateLCD();
void Ena_LED_Red();
void DisEna_LED_Red();
void Ena_LED_Green();
void DisEna_LED_Green();
void PutLine(unsigned char *Line[],unsigned int Length);
//**********************************************************/
void W_Data(unsigned char WDAT)
{	WDAT += DataTemplate;//Prepare//
	*P_IOA_Data=WDAT;//the LEDs will be disenable after this command

	WDAT += 0x8000;//Set Enable=1//
	*P_IOA_Data=WDAT;

	WDAT &= 0x7FFF;//Set Enable=0//
	*P_IOA_Data=WDAT;
	
	CursorColumn+=1;
	
	LCCalc();		//Line & Culumn Control
	
	Delay4us();
}
//**********************************************************//
void W_Instruction(unsigned int WCMDID)
{	WCMDID += InstructionTemplate;//Prepare//
	*P_IOA_Data=WCMDID;//the LEDs will be disenable after this command

	WCMDID += 0x8000;//Set Enable=1//
	*P_IOA_Data=WCMDID;

	WCMDID &= 0x7FFF;//Set Enable=0//
	*P_IOA_Data=WCMDID;
	
	Delay4us();
}
//**********************************************************//
void ClearDISP()//Clear Display//
{	W_Instruction(0x0001);
	
	CursorColumn=0x0000;//Cursor back to home
	CursorLine=0x0000;
}
//**********************************************************//
void ClearLocation()
{	W_Data(0x0020);
}
//**********************************************************//
void PutCursor(unsigned int CursorC,unsigned int CursorL)
{	unsigned int Position;
	Position=CursorC+CursorL;
	Position+=0x0080;
	W_Instruction(Position);
}
//**********************************************************//
void BackspaceControl()
{	CursorBack();
	ClearLocation();
	CursorBack();
}
//**********************************************************//
void LCCalc()//Line & Column Calculation
{	if ((CursorLine==0x0000)&(CursorColumn==0xffff))//1st Line & Left Boundary
		{CursorColumn=0x000f;//2nd Line & Right Boundary
		CursorLine=0x0040;}	
	else if ((CursorLine==0x0000)&(CursorColumn==0x0010))//1st Line & Right Boundary
		{CursorColumn=0x0000;//2nd Line & Left Boundary
		CursorLine=0x0040;}
	else if ((CursorLine==0x0040)&(CursorColumn==0xffff))//2nd Line & Left Boundary
		{CursorColumn=0x000f;//1st Line & Right Boundary
		CursorLine=0x0000;}
	else if ((CursorLine==0x0040)&(CursorColumn==0x0010))//2nd Line & Right Boundary
		{CursorColumn=0x0000;//1st Line & Left Boundary
		CursorLine=0x0000;}
	PutCursor(CursorColumn,CursorLine);
}
//**********************************************************//
void CursorBackHome()//Cursor go home
{	CursorColumn=0x0000;
	CursorLine=0x0000;
	PutCursor(CursorColumn,CursorLine);
}
//**********************************************************//
void CursorBack()
{	CursorColumn-=1;
	LCCalc();
}
//**********************************************************//
void CursorForward()
{	CursorColumn+=1;
	LCCalc();
}
//**********************************************************//
void DisplayOFF()
{	W_Instruction(0x000b);
}
//**********************************************************//
void DisplayON()
{	W_Instruction(0x000f);
}
//**********************************************************//
void InitiateLCD()
{	W_Instruction(0x0038);//Codes need to be transmit//
	W_Instruction(0x0038);
	W_Instruction(0x0038);
	
	W_Instruction(0x0038);//Function Set: 8 bits; 2 lines; 5*8 dots//
	
	W_Instruction(0x0008);//Display ON/OFF Control: Display OFF; Cursor not displayed; Not blink//
	
	W_Instruction(0x0001);//Clear display//
	
	W_Instruction(0x0006);//Entry Mode Set: Increments; No display shift//
	
	W_Instruction(0x000f);//Display ON/OFF Control: Display ON; Display cursor; blink//
	
	CursorColumn=0x0000;
	CursorLine=0x0000;
}
//**********************************************************//
void Ena_LED_Red()//Enable LED Red
{	unsigned int PIOAState;
	PIOAState=*P_IOA_Data;
	PIOAState|=0x0800;
	
	*P_IOA_Data=PIOAState;
	
	LEDState|=0x1100;
}
//**********************************************************//
void DisEna_LED_Red()//Disenable LED Red
{	unsigned int PIOAState;
	PIOAState=*P_IOA_Data;
	PIOAState&=0xf7ff;
	
	*P_IOA_Data=PIOAState;
	
	LEDState&=0x0011;
}
//**********************************************************//
void Ena_LED_Green()//Enable LED Green
{	unsigned int PIOAState;
	PIOAState=*P_IOA_Data;
	PIOAState|=0x1000;
	
	*P_IOA_Data=PIOAState;
	
	LEDState|=0x0011;
}
//**********************************************************//
void DisEna_LED_Green()//Disenable LED Green
{	unsigned int PIOAState;
	PIOAState=*P_IOA_Data;
	PIOAState&=0xefff;
	
	*P_IOA_Data=PIOAState;
	
	LEDState&=0x1100;
}
//**********************************************************//
void PutLine(unsigned char *Line[],unsigned int Length)
{
	unsigned int Dat;
	
	while(Length>0)
	{
		Dat=*Line;
		W_Data(Dat);
		Line++;
		Length--;
		LCCalc();
	}
}

⌨️ 快捷键说明

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