📄 dsp281x_lcd.c
字号:
#include "DSP281x_Device.h"
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#include "..\source\hzk\Fonts.h"
#define WAIT_LCD_IDLE delay()
#define LCD_NOP lcd_nop()
#define ASCII_WIDTH 8
#define HZ_WIDTH 16
#define HZ_HEIGHT 16
#define ASCII_HEIGHT 16
#define MaxX 319
#define MaxY 239
#define SizeXpixels 320
#define TRUE 1
#define FALSE 0
extern char * lpstr;
unsigned int const LcdInitSYS[8]={0x30,0x87,0x07,0x27,0x39,0xef,0x28,0x00};
unsigned int const LcdInitSCR[10]={0x00,0x00,0xef,0x00,0x30,0xef,0x00,0x00,0x00,0x00};
unsigned char bmp_atd[] = {
#include "atd_4.txt"
};
unsigned char bmp_dta[] = {
#include "dta_4.txt"
};
unsigned char bmp_swon[] = {
#include "swon_4.txt"
};
unsigned char bmp_swoff[] = {
#include "swoff_4.txt"
};
unsigned char bmp_diode[] = {
#include "diode_4.txt"
};
//unsigned char sineinput[] = {
//#include "sineinput.txt"
//};
//unsigned char DCinput[] = {
//#include "DCinput.txt"
//};
//unsigned char DCsupply[] = {
//#include "DCsupply.txt"
//};
unsigned int _getbit(unsigned int c,unsigned int n)
{
return ((c>>n)&1);
}
unsigned int delay()
{
unsigned int i;
unsigned int j;
for(i=0;i<0x3f;i++)
j=i;
return j;
}
unsigned int lcd_nop()
{
unsigned int i=0;
unsigned int j=0;
for(i=0;i<0xf;i++)
j += i;
return j;
}
void OutLCDCmd(unsigned int data)
{
unsigned char save_reg;
//WAIT_LCD_IDLE;
save_reg = OUTCS1;
OUTCS1=0x7c;
OUTCS1=0x5c;
LCDCMDADD = data;
//LCD_NOP;
OUTCS1=0x54;
LCD_NOP;
OUTCS1=0x5c;
LCD_NOP;
OUTCS1=0x7c;
OUTCS1 = save_reg;
}
unsigned char InLCDData()
{
unsigned char data;
unsigned char save_reg;
//WAIT_LCD_IDLE;
save_reg = OUTCS1;
OUTCS1=0x6c;
LCD_NOP;
OUTCS1=0xd8;
LCD_NOP;
data = KEYADD;
LCD_NOP;
OUTCS1=0x4c;
LCD_NOP;
OUTCS1=0x6c;
OUTCS1 = save_reg;
return data;
}
void OutLCDData(unsigned int data)
{
unsigned char save_reg;
save_reg = OUTCS1;
OUTCS1=0x6c;
OUTCS1=0x4c;
LCDDATAADD = data;
OUTCS1=0x44;
LCD_NOP;
OUTCS1=0x4c;
LCD_NOP;
OUTCS1=0x6c;
OUTCS1 = save_reg;
}
void AdjustContrast(void)
{
unsigned char i;
unsigned char save_reg;
save_reg = OUTCS0;
OUTCS0 = 0xf4;
for(i=0;i<2;i++)
{
OUTCS0 = 0x08;
WAIT_LCD_IDLE;
OUTCS0 = 0xfc;
}
OUTCS0=save_reg;
}
void ClearLCDLay1()
{
unsigned int i=0;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(0X00);
WAIT_LCD_IDLE;
OutLCDData(0X00);
WAIT_LCD_IDLE;
OutLCDCmd(0X4C);
WAIT_LCD_IDLE;
OutLCDCmd(0X42);
WAIT_LCD_IDLE;
for(i=0;i<0x2fff;i++)
{
OutLCDData(0x00);
}
}
void ClearLCDLay2()
{
unsigned int i=0;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(0X00);
WAIT_LCD_IDLE;
OutLCDData(0X30);
WAIT_LCD_IDLE;
OutLCDCmd(0X4C);
WAIT_LCD_IDLE;
OutLCDCmd(0X42);
WAIT_LCD_IDLE;
for(i=0;i<0x2580;i++)
{
OutLCDData(0x0);
WAIT_LCD_IDLE;
}
}
void InitLCD1335()
{
unsigned int i=0;
OutLCDCmd(0x40);
for(i=0;i<8;i++)
OutLCDData(LcdInitSYS[i]);
OutLCDCmd(0x44);
for(i=0;i<10;i++)
OutLCDData(LcdInitSCR[i]);
OutLCDCmd(0x5a);//设置点单元卷动位置
OutLCDData(0x00);
OutLCDCmd(0x5b);//设置显示合成方式
OutLCDData(0x01);
OutLCDCmd(0x58);//设置显示开关
OutLCDData(0x16);
OutLCDCmd(0X4C);
ClearLCDLay1();
ClearLCDLay2();
OutLCDCmd(0x46);//设置指针位置
OutLCDData(0x00);
OutLCDData(0x00);
OutLCDCmd(0x5d);//设置光标形状
OutLCDData(0x01);
OutLCDData(0x86);
OutLCDCmd(0x59);//设置显示开关
OutLCDData(0x17);
}
//-------------在固定位置输出点------
void PutPixelLCD(unsigned int PositionX,unsigned int PositionY,unsigned int Pixel)
{
unsigned int TempValue=0;
unsigned char LCDInfo=0;
// TempValue=PositionX;
// PositionX=320-PositionY-1;
// PositionY=TempValue;
TempValue=40*PositionY+PositionX/8+0x3000;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(TempValue&0xff);
WAIT_LCD_IDLE;
OutLCDData((TempValue>>8)&0xff);
WAIT_LCD_IDLE;
OutLCDCmd(0X4c);
WAIT_LCD_IDLE;
OutLCDCmd(0X43);
WAIT_LCD_IDLE;
LCDInfo = InLCDData();
// LCDInfo=(*(unsigned char *)LCDCMDADD);
// LCDInfo=0;
switch(PositionX%8)
{
case 0:
{
if(Pixel)
LCDInfo=LCDInfo|0x80;
else
LCDInfo=LCDInfo&0x7f;
break;
}
case 1:
{
if(Pixel)
LCDInfo=LCDInfo|0x40;
else
LCDInfo=LCDInfo&0xbf;
break;
}
case 2:
{
if(Pixel)
LCDInfo=LCDInfo|0x20;
else
LCDInfo=LCDInfo&0xdf;
break;
}
case 3:
{
if(Pixel)
LCDInfo=LCDInfo|0x10;
else
LCDInfo=LCDInfo&0xef;
break;
}
case 4:
{
if(Pixel)
LCDInfo=LCDInfo|0x08;
else
LCDInfo=LCDInfo&0xf7;
break;
}
case 5:
{
if(Pixel)
LCDInfo=LCDInfo|0x04;
else
LCDInfo=LCDInfo&0xfb;
break;
}
case 6:
{
if(Pixel)
LCDInfo=LCDInfo|0x02;
else
LCDInfo=LCDInfo&0xfd;
break;
}
case 7:
{
if(Pixel)
LCDInfo=LCDInfo|0x01;
else
LCDInfo=LCDInfo&0xfe;
break;
}
}
TempValue=40*PositionY+PositionX/8+0x3000;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(TempValue&0xff);
WAIT_LCD_IDLE;
OutLCDData((TempValue>>8)&0xff);
WAIT_LCD_IDLE;
OutLCDCmd(0X4c);
WAIT_LCD_IDLE;
OutLCDCmd(0X42);
WAIT_LCD_IDLE;
OutLCDData(LCDInfo);
}
//----------------------
void GetPixelInfo( char * String,unsigned char * PixelInfo,unsigned int StringType)
{
unsigned int i=0,j=0,LibLength=0,code;
if(StringType==0)//8x8点阵 字母
{
for(i=0;i<8;i++)
{
// PixelInfo[i]=LetterCode8x8[i+(String[0]-0x20)*8];
}
}
if(StringType==1)//8x16点阵 字母
{
j = (unsigned int)(String[0]);
for(i=0;i<16;i++)
{
PixelInfo[i]=asc16[j].buf[i];
}
}
if(StringType==2)//16x16点阵 汉字
{//汉字库格式为:字库总长(2字节)+ 汉字内码索引(2字节)+ 32字节的汉字点阵+ ......
LibLength=HZ_NUM;
code = ( (unsigned char)String[0] ) << 8;
code += (unsigned char)String[1];
for(i=0;i<LibLength;i++)
{
if( code == hz16[i].id)
{
for(j=0;j<32;j++)
PixelInfo[j]=hz16[i].buf[j];
}
}
}
}
//-------------显示一段直线-----------
void DisPlayLine(unsigned int StartX,unsigned int StartY,unsigned int Length,unsigned int Direction)
{
unsigned int i=0;
unsigned int j;
if(Direction)//X方向
{
if(Length>320||Length<=0)
Length=0;
for(i=0;i<Length;i++)
PutPixelLCD(StartX+i,StartY,1);
}
else //Y方向
{
if(Length>240||Length<=0)
Length=0;
for(i=0;i<Length;i++)
PutPixelLCD(StartX,StartY+i,1);
}
}
void Clear_Lcd()
{
ClearLCDLay1();
ClearLCDLay2();
DisPlayLine(0,0,320,1);
DisPlayLine(0,0,240,0);
DisPlayLine(0,239,320,1);
DisPlayLine(319,0,240,0);
}
//-------------显示8*8的字符-----------
void Display8Eng(unsigned int StartX,unsigned int StartY, char String,unsigned int BFlag)
{
unsigned int TempValue=0,i=0;
unsigned char PixelInfo[8];
// TempValue=StartX;
// StartX=320-8-StartY;
// StartY=TempValue;
GetPixelInfo(&String,PixelInfo,0);//0--对应8x8点阵
TempValue=40*StartY+StartX/8+0x3000;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(TempValue&0xff);
WAIT_LCD_IDLE;
OutLCDData((TempValue>>8)&0xff);
WAIT_LCD_IDLE;
OutLCDCmd(0X4f);
WAIT_LCD_IDLE;
OutLCDCmd(0X42);
WAIT_LCD_IDLE;
for(i=0;i<8;i++)
{
if(BFlag)
OutLCDData(PixelInfo[i]);
else
OutLCDData(~PixelInfo[i]);
WAIT_LCD_IDLE;
}
}
//-------------显示8*16的字符----------
void DisplayEng(unsigned int StartX,unsigned int StartY, char String,unsigned int BFlag)
{
unsigned int TempValue=0,i=0;
unsigned char PixelInfo[16];
// TempValue=StartX;
// StartX=320-8-StartY;
// StartY=TempValue;
GetPixelInfo(&String,PixelInfo,1);//1--对应8x16点阵
TempValue=40*StartY+StartX/8+0x3000;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(TempValue&0xff);
WAIT_LCD_IDLE;
OutLCDData((TempValue>>8)&0xff);
WAIT_LCD_IDLE;
OutLCDCmd(0X4f);
WAIT_LCD_IDLE;
OutLCDCmd(0X42);
WAIT_LCD_IDLE;
for(i=0;i<16;i++)
{
if(BFlag)
OutLCDData(~PixelInfo[i]);
else
OutLCDData(PixelInfo[i]);
WAIT_LCD_IDLE;
}
}
void LCDPutBlock(unsigned int x, unsigned int y, unsigned char buf[32],unsigned char BFlag)
{
unsigned int TempValue=0,i=0;
TempValue=40*y+x/8+0x3000;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(TempValue&0xff);
WAIT_LCD_IDLE;
OutLCDData((TempValue>>8)&0xff);
WAIT_LCD_IDLE;
OutLCDCmd(0X4f);
WAIT_LCD_IDLE;
OutLCDCmd(0X42);
WAIT_LCD_IDLE;
for(i=0;i<16;i++)
{
if(BFlag)
OutLCDData(~buf[2*i]);
else
OutLCDData(buf[2*i]);
WAIT_LCD_IDLE;
}
TempValue=40*y+(x+8)/8+0x3000;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(TempValue&0xff);
WAIT_LCD_IDLE;
OutLCDData((TempValue>>8)&0xff);
WAIT_LCD_IDLE;
OutLCDCmd(0X4f);
WAIT_LCD_IDLE;
OutLCDCmd(0X42);
WAIT_LCD_IDLE;
for(i=0;i<16;i++)
{
if(BFlag)
OutLCDData(~buf[2*i+1]);
else
OutLCDData(buf[2*i+1]);
WAIT_LCD_IDLE;
}
}
//-------------显示16*16的汉字---------
void DisplayChinese(unsigned int StartX,unsigned int StartY, char *String,unsigned int BFlag)
{
unsigned char PixelInfo[32];
GetPixelInfo(String,PixelInfo,2);//1--对应16x16点阵 汉字
LCDPutBlock(StartX,StartY,PixelInfo,BFlag);
return;
}
/*==========================================================================*/
/* LCDTextOut() -- Display a string */
/*==========================================================================*/
void LCDTextOut(unsigned int x,unsigned int y,unsigned int d,char * c,unsigned int vh)
{
unsigned int HZqw;
unsigned char chtp;
HZqw=0xa1;
if(strlen(c) > 64) c[0]='\0';
while(*c!='\0') {
chtp=(unsigned char)c[0];
if(chtp < HZqw ){
DisplayEng(x,y,chtp,vh);
x+=ASCII_WIDTH;
c++;
}
else {
DisplayChinese(x,y,c,vh);
x+=HZ_WIDTH;
c+=2;
}
}
return;
}
void LCDPutLine(unsigned int x, unsigned int y, unsigned char buf[32],unsigned char BFlag)
{
unsigned int TempValue=0,i=0;
TempValue=40*y+x/8+0x3000;
OutLCDCmd(0X46);
WAIT_LCD_IDLE;
OutLCDData(TempValue&0xff);
WAIT_LCD_IDLE;
OutLCDData((TempValue>>8)&0xff);
WAIT_LCD_IDLE;
OutLCDCmd(0X4f);
WAIT_LCD_IDLE;
OutLCDCmd(0X42);
WAIT_LCD_IDLE;
if(BFlag)
OutLCDData(~buf[0]);
else
OutLCDData(buf[0]);
WAIT_LCD_IDLE;
}
/*==========================================================================*/
/* LCDTextOut() -- Display a string */
/*==========================================================================*/
void LCDBmpOut(unsigned int x,unsigned int y,unsigned char * bmp,unsigned int vh)
{
int i,j;
unsigned char * fp;
fp = bmp;
for(i=0; i<32; i++)
{
for(j=0; j<6; j++)
{
LCDPutLine( (x+ASCII_WIDTH*j) , (y +i),fp, vh);
fp += 1;
}
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -