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

📄 disp.c

📁 TDA7540 收音机程序
💻 C
字号:
/***************************************************************************
Project  :   TDA7540 Jig board 
Compiler : ST7 HiCross C (HiWARE)
Module   :  Disp.c
Version  :  V 1.0
Created  : Jan.24th,2005  
Author   :  Jerry HE / ST-ShenZhen
Description
         -  LCD display
Modified
	  -   
***************************************************************************/

#include "system.h"

/*************************************************************************/
//*********   Physical layer of LCD Display *************************************/
/*************************************************************************/
static const unsigned char CommonMessage[] =
{
	' ','T','B','K',' ','F','S','T',' ','J','I','G',' ',     //  0~12
	'S','T',' ','M','I','C','R','O',' ','S','Z','L','A','B', //13~27
	'P','L','U','G',' ','M','O','D','U','L','E'   // 28~38
};

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : LCDTest
Input   :  
Output  : 
Description 
        - Test the LCD (100ms)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LCDTest()
{
	DispBuff[1]='7';
	DispBuff[2]='8';
	DispBuff[3]='9';
	DispBuff[4]='a';
	DispBuff[9]='b';
	DispBuff[10]='c';

	LCDDisplay(BYBYTES_REFRESH,FIRSTLINE,1,4);
	LCDDisplay(BYBYTES_REFRESH,FIRSTLINE,9,2);

	DispBuff[22]='e';
	DispBuff[23]='f';
	DispBuff[24]='g';
	DispBuff[25]='h';
	LCDDisplay(BYBYTES_REFRESH,SECONDLINE,5,5);

}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : Display main
Input   :  
Output  : 
Description 
        - main routine of display 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void Display_Main()
{
}


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : FetchMessage
Input   :  
Output  : 
Description 
        - Fetch the audio message 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void FetchMessage(unsigned char *Msg, unsigned char No, unsigned char Pos)
{
	unsigned char i;
	Msg+=No*8;      //8 character per message
	for(i=0;i<8;i++)
	{
	   DispBuff[i+16+Pos] = *Msg++;//second line
	}
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : DisplayVersion
Input   :  
Output  : 
Description 
        - Display the current software version
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void DisplayVersion()
{
	DispBuff[19] = 'V';
	DispBuff[20] = 'e';
	DispBuff[21] = 'r';
	DispBuff[22] = ' ';

	DispBuff[27] = 'P';
	DispBuff[28] = 'R';
	DispBuff[29] = '1';
}
//here write some other functions

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : LCDInit
Input   :  
Output  : 
Description 
        - Initial the LCD
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LCDInit()
{
	unsigned char i;
	unsigned char *p;
	WAIT_40ms();
	WriteCommToLCD(FUNTIONSET);
	WAIT_100us();
	WriteCommToLCD(FUNTIONSET);
	WAIT_100us();
	while((ReadDataFromLCD()>>7)&0x01);
	WriteCommToLCD(DISPLAYON);
	while((ReadDataFromLCD()>>7)&0x01);
	WriteCommToLCD(LCDCLEAR);
	while((ReadDataFromLCD()>>7)&0x01);
	WriteCommToLCD(INCREMODE);
	SetBit(LCDDisplayFlag,DISPON);
	SetBit(LCDDisplayFlag,INCREASEMODE);
	LCDDisplayWelcome();
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : LCDDisplayWelcome
Input   :  
Output  : 
Description 
        - Display welcome message
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LCDDisplayWelcome()
{
	unsigned char i; 
	unsigned char *p;
	p= CommonMessage;
	DisplayClear(FIRSTLINE);
	DisplayClear(SECONDLINE);
	for(i=0;i<13;i++)
    {
      DispBuff[i+1]=*p++;
    }
	for(i=0;i<14;i++)
	{
      DispBuff[i+17]=*p++;
	}
     LCDDisplay(ALL_REFRESH,0,0,0);
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : LCDDisplay
Input   :   
Output  : 
Description 
        - LCD Display routine
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void LCDDisplay(unsigned char mode,unsigned char Line, unsigned char Location, unsigned char bytes)
{
	unsigned char i;
	switch(mode)
	{
	   case ALL_REFRESH:
	   	//First Refresh the first line//
	   	while((ReadDataFromLCD()>>7)&0x01);
	   	WriteCommToLCD(DDRAMADR);
		while((ReadDataFromLCD()>>7)&0x01);
		 for (i=0;i<16;i++)
    		{
	        	WriteDataToLCD(DispBuff[i]);
    	              while ((ReadDataFromLCD()>>7)&0x01);
              }

		while((ReadDataFromLCD()>>7)&0x01);
		//Refresh the second line//
	   	WriteCommToLCD(0xC0);
		while((ReadDataFromLCD()>>7)&0x01);
		 for (i=0;i<16;i++)
    		{
	        	WriteDataToLCD(DispBuff[i+16]);
    	              while ((ReadDataFromLCD()>>7)&0x01);
              }

	   	break;
	   case BYBYTES_REFRESH:
	   	if (Line==FIRSTLINE)
	   	{
	   	   while((ReadDataFromLCD()>>7)&0x01);
	   	   WriteCommToLCD(DDRAMADR|Location);
		   for(i=Location;i<Location+bytes;i++)
		   {
		   	WriteDataToLCD(DispBuff[i]);
    	              while ((ReadDataFromLCD()>>7)&0x01);

		   }
	   	}
		if(Line==SECONDLINE)
		{
		   while((ReadDataFromLCD()>>7)&0x01);
	   	   WriteCommToLCD(DDRAMADR|0x40|Location); 
		    for(i=Location;i<Location+bytes;i++)
		   {
		   	WriteDataToLCD(DispBuff[i+16]);
    	              while ((ReadDataFromLCD()>>7)&0x01);
		   }
		}
	   	break;
	}
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : WriteCommToLCD
Input   :   LCD command
Output  : 
Description 
        - Send command to LCD module
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void  WriteCommToLCD(char TVAR)
{
	P_LCDRS = 0;
	P_LCDRW =0;
	P_LCDEN = 1;
	NOP;
	DataSendOrgPort(TVAR);
	P_LCDEN = 0;

}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : WriteDataToLCD
Input   :  LCD command
Output  : 
Description 
        - Send data to LCD module
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void  WriteDataToLCD(char TVAR)
{
       P_LCDRS = 1;
	P_LCDRW =0;
	P_LCDEN = 1;
	NOP;
	DataSendOrgPort(TVAR);
	P_LCDEN = 0;
} 

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : ReadDataFromLCD
Input   :  
Output  : 
Description 
        - Read data from LCD module
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
unsigned char ReadDataFromLCD(void)
{
	unsigned char readdata;
	D_LCDDB0 = 0;                 //when read...
       D_LCDDB1 = 0;
       D_LCDDB2 = 0;
       D_LCDDB3 = 0;
       D_LCDDB4 = 0;
       D_LCDDB5 = 0;
	D_LCDDB6 = 0;
       D_LCDDB7 = 0;

	P_LCDDB0 = 1;
	P_LCDDB1 = 1;
	P_LCDDB2 = 1;
	P_LCDDB3 = 1;
	P_LCDDB4 = 1;
	P_LCDDB5 = 1;
	P_LCDDB6 = 1;
	P_LCDDB7 = 1;

	P_LCDRS = 0;
	P_LCDRW = 1;
	NOP;
	P_LCDEN = 1;
	NOP;
	readdata = DataReceOrgPort();
	P_LCDEN = 0;

       D_LCDDB0 = 1;
       D_LCDDB1 = 1;
       D_LCDDB2 = 1;
       D_LCDDB3 = 1;
       D_LCDDB4 = 1;
       D_LCDDB5 = 1;
	D_LCDDB6 = 1;
       D_LCDDB7 = 1;
	   
	return(readdata);
	
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : DataReceOrgPort
Input   :  
Output  : 
Description 
        - Data send out port re-organization
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
unsigned char DataReceOrgPort(void)
{
	UByteField datatemp;
	datatemp.byte = 0xFF;
       if(P_LCDDB0==0)
	   datatemp.field.B0=0;
	if(P_LCDDB1==0)
	   datatemp.field.B1=0;
	if(P_LCDDB2==0)
	   datatemp.field.B2=0;
	if(P_LCDDB3==0)
	   datatemp.field.B3=0;
	if(P_LCDDB4==0)
	   datatemp.field.B4=0;
	if(P_LCDDB5==0)
	   datatemp.field.B5=0;
	if(P_LCDDB6==0)
	   datatemp.field.B6=0;
	if(P_LCDDB7==0)
	   datatemp.field.B7=0;
	return(datatemp.byte);
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : DataSendOrgPort
Input   :   the display data
Output  : 
Description 
        - Data transger to the port
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void DataSendOrgPort(char DATA)
{
	/*detect every bit and set the proper port*/
	if(DATA&0x01)
	{
		P_LCDDB0 = 1;
	}
	else
	{
		P_LCDDB0 = 0;
	}
	if((DATA>>1)&0x01)
	{
		P_LCDDB1 = 1;
	}
	else
	{
		P_LCDDB1 = 0;
	}
	if((DATA>>2)&0x01)
	{
		P_LCDDB2 = 1;
	}
	else
	{
		P_LCDDB2 = 0;
	}
	if((DATA>>3)&0x01)
	{
		P_LCDDB3 = 1;
	}
	else
	{
		P_LCDDB3 = 0;
	}
	if((DATA>>4)&0x01)
	{
		P_LCDDB4 = 1;
	}
	else
	{
		P_LCDDB4 = 0;
	}
	if((DATA>>5)&0x01)
	{
		P_LCDDB5 = 1;
	}
	else
	{
		P_LCDDB5 = 0;
	}
	if((DATA>>6)&0x01)
	{
		P_LCDDB6 = 1;
	}
	else
	{
		P_LCDDB6 = 0;
	}
	if((DATA>>7)&0x01)
	{
		P_LCDDB7 = 1;
	}
	else
	{
		P_LCDDB7 = 0;
	}
}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : DisplayClear
Input   :  Line number 
Output  : 
Description 
        - Clear the display
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void DisplayClear(unsigned char line)
{
	unsigned char i;
	switch(line)
	{
		case FIRSTLINE:
			for(i=0;i<16;i++)
			{
				DispBuff[i]=' ';
			}
			break;
		case SECONDLINE:
			for(i=16;i<32;i++)
			{
				DispBuff[i]=' ';
			}
	}
	LCDDisplay(ALL_REFRESH,0,0,0);
}

/*** (c) 2005  STMicroelectronics ****************** END OF FILE ***/

⌨️ 快捷键说明

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