disp.c

来自「DSP2808例程。TMS320F2808DSP的各个模块的应用例程」· C语言 代码 · 共 302 行

C
302
字号
#include "DSP280x_Device.h"     // DSP280x Headerfile Include File
#include "DSP280x_Examples.h"   // DSP280x Examples Include File

#define LCDBUSY	0x80 

//sbit RS    = P2^7; 				//RS = 0:	structrue and LCDstate; RS = 1:	data in or out for LCD
//sbit LCDWR = P2^6;				
//sbit LCDEN = P2^5;
			
//d0~d7  GPIO4~11
//RS 		GPIO12
//R/W		GPIO13
//LCDEN		GPIO34

#define RS_H		GpioDataRegs.GPASET.bit.GPIO12   = 1 
#define RS_L		GpioDataRegs.GPACLEAR.bit.GPIO12 = 1

#define LCDWR_H		GpioDataRegs.GPASET.bit.GPIO13   = 1 
#define LCDWR_L		GpioDataRegs.GPACLEAR.bit.GPIO13 = 1

#define LCDEN_H		GpioDataRegs.GPBSET.bit.GPIO34   = 1 
#define LCDEN_L		GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1

void LcdWriteCommand(unsigned int CMD, unsigned int AttribC);			

unsigned int HC245DataSwitch(unsigned int CMD)
{//unsigned int tmp1,tmp2;
	CMD &= 0x00FF;
	if(CMD & 0x0001)
	{
		CMD |= 0x8000;
	}
	if(CMD & 0x0002)
	{
		CMD |= 0x4000;
	}
	if(CMD & 0x0004)
	{
		CMD |= 0x2000;
	}
	if(CMD & 0x0008)
	{
		CMD |= 0x1000;
	}
	if(CMD & 0x0010)
	{
		CMD |= 0x0800;
	}
	if(CMD & 0x0020)
	{
		CMD |= 0x0400;
	}
	if(CMD & 0x0040)
	{
		CMD |= 0x0200;
	}
	if(CMD & 0x0080)
	{
		CMD |= 0x0100;
	}
	CMD >>=8;
	return (CMD);
}

void wr_lcd(unsigned int CMD)
{unsigned long tmp1,tmp2;
	tmp1 = (unsigned long)(CMD); //HC245DataSwitch
	tmp1 <<= 4;
	tmp2 = GpioDataRegs.GPADAT.all;
	tmp2 &= 0xFFFFF00F;
	tmp1 |=tmp2;
	GpioDataRegs.GPADAT.all = tmp1;
}
//extern unsigned char idata	bMainMenuLevel;


void Delay5Ms(void)
{
	//unsigned int p = 5500;	//Actually, 2.5Ms delay;
	unsigned int p = 4000;
	while(p--);
}




void LCDInit( void ) 
{
   	LcdWriteCommand( 0x38, 0);	//显示模式设置,(不检测忙信号)		
		//Delay5Ms();
		//Delay5Ms();

	LcdWriteCommand( 0x38, 0);	//共三次		
		//Delay5Ms();
		//Delay5Ms();

	LcdWriteCommand( 0x38, 0);
		Delay5Ms();
		Delay5Ms();


	LcdWriteCommand( 0x38, 1);	//显示模式设置,检测忙信号	
	Delay5Ms();		
    LcdWriteCommand( 0x08, 1);	//显示关闭		
	Delay5Ms();
   	LcdWriteCommand( 0x01, 1);	//显示清屏
   	Delay5Ms();		
	LcdWriteCommand( 0x06, 1);	//显示光标移动设置
	Delay5Ms();	
	LcdWriteCommand( 0x0D, 1);	//画面显示
	Delay5Ms();
	//LcdWriteCommand( 0x0D, 1);	//画面,闪烁显示
	//LcdWriteCommand( 0x0E, 1);	//画面,光标	
	//LcdWriteCommand( 0x0F, 1);	//画面,光标,闪烁显示	
}

//********************************************************
//if AttribC = 1, check the BUSY; others, no check BUSY
//********************************************************
void LcdWriteCommand(unsigned int CMD, unsigned int AttribC) 
{
	//RS = 0;
	RS_L;
	//LCDWR = 1;
	LCDWR_H;
	//LCDEN = 1;
	LCDEN_H;
	if(AttribC)
	{
		//while (P2 & LCDBUSY);
		Delay5Ms();
	} 

	//LCDWR = 0;
	LCDWR_L;
	Delay5Ms();
	//P3 = CMD;
	wr_lcd(CMD);

	//LCDEN = 0;
	LCDEN_L;
	Delay5Ms();

	//LCDWR = 1;
	LCDWR_H;
	
}
	
void LcdWriteData( unsigned int dataW )
{
	//unsigned int bTemp;

	//RS = 0;
	RS_L;
	//LCDWR = 1;
	LCDWR_H;
	//LCDEN = 1;
	LCDEN_H;
	//do
	//{
		//bTemp = P2;
		//bTemp &= LCDBUSY;
	//}
	//while (bTemp);

	//LCDWR = 0;
	LCDWR_L;
	//RS = 1;
	RS_H;


	//P3 = dataW;
	wr_lcd(dataW);
	//LCDEN = 0;
	LCDEN_L;
	Delay5Ms();

	//LCDWR = 1;
	LCDWR_H;
}



void LocateXY( unsigned int bRowPosition, unsigned int bColumnPosition)
{
	unsigned int temp;

	temp = bColumnPosition & 0x0f;
	bRowPosition &= 0x1;

	if ( bRowPosition )
	{	temp |= 0x40;	}

	temp |= 0x80;
	LcdWriteCommand(temp,0);
}

void LCDClear(void)
{
   	LcdWriteCommand(0x01,1);	//显示清屏		
}

void DispOneChar(unsigned int bRowPosition, unsigned int bColumnPosition, unsigned int bWriteData)
{
	LocateXY( bRowPosition, bColumnPosition );				
	LcdWriteData( bWriteData );	
	LocateXY( bRowPosition, bColumnPosition );
}

void DispOneByte(unsigned int bRowPosition, unsigned int bColumnPosition, unsigned int bByteToDisp)
{
	if (bByteToDisp > 99)
	{
		DispOneChar(bRowPosition, (bColumnPosition - 2),  ((bByteToDisp / 100) + 0x30));
		bByteToDisp = bByteToDisp % 100;
		//bColumnPosition ++;
	}
	
	if (bByteToDisp > 9)
	{
		DispOneChar(bRowPosition, (bColumnPosition - 1),  ((bByteToDisp / 10) + 0x30));
		bByteToDisp = bByteToDisp % 10;
		//bColumnPosition ++;
	}
	//else
	//{
	//	if (bMainMenuLevel == DATETIMESTATE)
	//	{
	//		DispOneChar(bRowPosition, bColumnPosition,  0x30);
			//bColumnPosition ++;
	//	}
	//}
	
	DispOneChar(bRowPosition, bColumnPosition,  (bByteToDisp + 0x30));
}

void DispOneWord(unsigned int bRowPosition, unsigned int bColumnPosition, unsigned int wWordToDisp)
{
	if (wWordToDisp > 999)
	{
		DispOneChar(bRowPosition, (bColumnPosition - 3),  ((wWordToDisp / 1000) + 0x30));
		wWordToDisp = wWordToDisp % 1000;

		DispOneChar(bRowPosition, (bColumnPosition - 2),  ((wWordToDisp / 100) + 0x30));
		wWordToDisp = wWordToDisp % 100;
		
		DispOneChar(bRowPosition, (bColumnPosition - 1),  ((wWordToDisp / 10) + 0x30));
		wWordToDisp = wWordToDisp % 10;

		DispOneChar(bRowPosition, bColumnPosition,  (wWordToDisp + 0x30));
	}
	else if (wWordToDisp > 99)
	{
		DispOneChar(bRowPosition, (bColumnPosition - 3),  ' ');
		DispOneChar(bRowPosition, (bColumnPosition - 2),  ((wWordToDisp / 100) + 0x30));
		wWordToDisp = wWordToDisp % 100;
		
		DispOneChar(bRowPosition, (bColumnPosition - 1),  ((wWordToDisp / 10) + 0x30));
		wWordToDisp = wWordToDisp % 10;

		DispOneChar(bRowPosition, bColumnPosition,  (wWordToDisp + 0x30));
	}
		else if (wWordToDisp > 9)
	{
		DispOneChar(bRowPosition, (bColumnPosition - 3),  ' ');
		DispOneChar(bRowPosition, (bColumnPosition - 2),  ' ');
		DispOneChar(bRowPosition, (bColumnPosition - 1),  ((wWordToDisp / 10) + 0x30));
		wWordToDisp = wWordToDisp % 10;

		DispOneChar(bRowPosition, bColumnPosition,  (wWordToDisp + 0x30));
	}
		else
	{
		DispOneChar(bRowPosition, (bColumnPosition - 3),  ' ');
		DispOneChar(bRowPosition, (bColumnPosition - 2),  ' ');
		DispOneChar(bRowPosition, (bColumnPosition - 1),  ' ');
		DispOneChar(bRowPosition, bColumnPosition,  (wWordToDisp + 0x30));
	}
}

//=======================================================
//显示字符串
//=======================================================
void DispString(unsigned int bRowPosition, unsigned int bColumnPosition,  unsigned int *bPointOfString) 
{
	unsigned char i = 0;
	do
	{
		DispOneChar(bRowPosition, bColumnPosition ++, bPointOfString[i ++]);
		if ( bColumnPosition == 16 )
		{
			bColumnPosition = 0;
			bRowPosition ^= 1;
		}
	}while (bPointOfString[i] != '\0');
}





⌨️ 快捷键说明

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