📄 lcd.c
字号:
#include "DSP28_Device.h"
extern const unsigned char *ASCIITAB[];
extern const unsigned char *Welcome[];
const unsigned char disline[8] = {0xFF,0x7F,0x3F,0x1F,0x0F,0x07,0x03,0x01};
//LCD初始化
void lcd_init(void)
{
LCD_COM = 0x40;
LCD_DAT = 0x30;
LCD_DAT = 0x87;
LCD_DAT = 0x07;
LCD_DAT = 0x27;
LCD_DAT = 0x46; //2B
LCD_DAT = 0xEF;
LCD_DAT = 0x28;
LCD_DAT = 0x00;
LCD_COM = 0x44;
LCD_DAT = 0x00;
LCD_DAT = 0x00;
LCD_DAT = 0xF0;
LCD_DAT = 0x80;
LCD_DAT = 0x25;
LCD_DAT = 0xF0;
LCD_DAT = 0x00;
LCD_DAT = 0x4B;
LCD_DAT = 0x00;
LCD_DAT = 0x00;
LCD_COM = 0x5A;
LCD_DAT = 0x00;
LCD_COM = 0x5B;
LCD_DAT = 0x0C;
LCD_COM = 0x4C;
LCD_COM = 0x59;
LCD_DAT = 0x04;
}
//清除第一显示缓冲区
void clearscr1(void)
{
Uint16 i;
LCD_COM = 0x46;
LCD_DAT = 0x00;
LCD_DAT = 0x00;
LCD_COM = 0x4C;
LCD_COM = 0x42;
for (i=0;i<12240;i++) LCD_DAT=0x00;
}
//清除第二显示缓冲区
void clearscr2(void)
{
Uint16 i;
LCD_COM = 0x46;
LCD_DAT = 0x00;
LCD_DAT = 0x2A;
LCD_COM = 0x4C;
LCD_COM = 0x42;
for (i=0x2A00;i<0x5400;i++) LCD_DAT=0x00;
}
//清除第三显示缓冲区
void clearscr3(void)
{
Uint16 i;
LCD_COM = 0x46;
LCD_DAT = 0x00;
LCD_DAT = 0x54;
LCD_COM = 0x4C;
LCD_COM = 0x42;
for (i=0x5400;i<0x8000;i++) LCD_DAT=0x00;
}
//设置光标位置
void Set_Graphic_Csr(unsigned char x1,unsigned char y1)
{
Uint16 add;
add = 0;
add += (x1+y1*40);
LCD_COM = 0x46;
LCD_DAT = (unsigned char)(add%256);
LCD_DAT = (unsigned char)(add/256);
}
//画横线
void lineh(Uint16 dotx0, Uint16 dotxt, Uint16 doty)
{
Uint16 add1,add2,ptemp,i;
unsigned char dtemp;
if(dotx0>dotxt)
{
ptemp = dotxt;
dotxt = dotx0;
dotx0 = ptemp;
}
add1 = doty*40 + dotx0/8;
add2 = doty*40 + dotxt/8;
LCD_COM = 0x46;
LCD_DAT = (unsigned char)(add1%256);
LCD_DAT = (unsigned char)(add1/256);
LCD_COM = 0x42;
if(add1 == add2)
{
dtemp = disline[dotx0%8];
dtemp&= !(disline[dotxt%8]);
LCD_DAT = dtemp;
}
else
{
for(i=add1;i<=add2;i++)
{
if(i==add1)
{
dtemp = disline[dotx0%8];
LCD_DAT = dtemp;
LCD_COM = 0x46;
LCD_DAT = (unsigned char)((i+1)%256);
LCD_DAT = (unsigned char)((i+1)/256);
LCD_COM = 0x42;
}
else if(i==add2)
{
dtemp = !(disline[dotxt%8]);
LCD_DAT = dtemp;
}
else
{
dtemp = 0xFF;
LCD_DAT = dtemp;
LCD_COM = 0x46;
LCD_DAT = (unsigned char)((i+1)%256);
LCD_DAT = (unsigned char)((i+1)/256);
LCD_COM = 0x42;
}
}
}
}
//画竖线
void linev(Uint16 dotx, Uint16 doty0, Uint16 dotyt)
{
Uint16 add1,add2,ptemp,i;
unsigned char dtemp,oy;
if(doty0>dotyt)
{
ptemp = dotyt;
dotyt = doty0;
doty0 = ptemp;
}
add1 = doty0*40 + dotx/8;
add2 = dotyt*40 + dotx/8;
oy = 0x80;
dtemp = dotx%8;
for(i=0;i<dtemp;i++) oy>>= 1;
dtemp = oy;
for(i=add1;i<=add2;i++)
{
if(((i-add1)%40)==0)
{
LCD_COM = 0x46;
LCD_DAT = (unsigned char)(i%256);
LCD_DAT = (unsigned char)(i/256);
LCD_COM = 0x42;
LCD_DAT = dtemp;
}
}
}
//显示字符
void ShowChar(unsigned char x1, unsigned char y1, unsigned char asccode)
{
const unsigned char *pasc;
unsigned char ctemp;
Uint16 i,ntemp;
LCD_COM = 0x4F;
Set_Graphic_Csr(x1,y1);
pasc = ASCIITAB[0];
ntemp= 16*(asccode-32)+15;
LCD_COM = 0x42;
for(i=0;i<16;i++)
{
ctemp = pasc[ntemp];
ntemp--;
LCD_DAT = ctemp;
}
}
//显示字符串
void DispString(unsigned char t0x1, unsigned char t0y1, const unsigned char *pstr)
{
unsigned char Tcode;
Uint16 ntemp;
ntemp = 0;
Tcode = pstr[ntemp];
while(Tcode!=0)
{
if(t0x1>39)
{
if(t0y1<232)
{
t0y1++;
t0x1 = 0;
ShowChar(t0x1,t0y1,Tcode);
t0x1++;
}
}
else if(t0y1<=232)
{
ShowChar(t0x1,t0y1,Tcode);
t0x1++;
}
ntemp++;
Tcode = pstr[ntemp];
}
}
//***********************************************************************
//======================================================================
//===================== PAGE 4 =======================================
//=======================================================================
//***********************************************************************
void Smenu(void)
{
//ShowChar(39,0,49);
DispString(14,115,Welcome[0]);
linev(1,1,238);
linev(318,1,238);
lineh(1,319,1);
lineh(1,319,238);
}
//===============================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -