📄 disp.c
字号:
#include "Disph.h"
#include "externh.h"
#include "..\..\typedef.h"
#include "..\..\i2ch.h"
const unsigned char LineTable[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
const unsigned char ClrTable[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void Cls(void)
{
for(uc0=0;uc0<MAXROW;uc0++){
for(uc1=0;uc1<LCDWITH;uc1++){
DispBuf[uc0][uc1]=0;
}
}
g.Flag.DispUpData=1;
}
void DispHz(unsigned char x,unsigned char y)
{//在(x,y)处开始显示一个汉字.汉字的内码放在hz[].
unsigned int font;
unsigned char uc0,uc1,uc2;
g.Flag.DispUpData=1;
font=HZSTART;
uc0=0;
while(1){
uc1= I2CRead(font);//*(unsigned char *)font;
font++;
uc2= I2CRead(font);//*(unsigned char *)font;
font++;
if(uc1==hz[0]&&uc2==hz[1]) break;
uc0++;
}
font=(HZZMSTART +uc0*24);
DisplayBmp(font,x,y,HZWITH,HZHIGH);
}
void DispCh(unsigned char x,unsigned char y,unsigned char ch)
{//在(x,y)处开始显示一个字符ch.
unsigned char uc0,uc1;
unsigned int font;
g.Flag.DispUpData=1;
font=CHSTART;// (unsigned char *)&CharTable[0];
uc0=0;
while(1){
uc1= I2CRead(font);//*(unsigned char *)font;
font++;
if(uc1==ch) break;
uc0++;
}
font=(CHZMSTART+uc0*12);
DisplayBmp(font,x,y,CHWITH,CHHIGH);
}
void DispString(unsigned char x,unsigned char y)//,unsigned char *string)
{//在(x,y)处开始显示一个字符串*string.
unsigned char i=0;
if(x>LCDWITH)
return;
if(y>LCDHIGH)
return;
g.Flag.DispUpData=1;
hz[2]=0;
while(string[i]){
if(((char)string[i]&0x80)==0x80){//display hz
hz[0]=(char)string[i++];
hz[1]=(char)string[i++];
hz[2]=0;
if(x+HZWITH>LCDWITH){
x=0;
y+=HZHIGH;
if(y>LCDHIGH)y=0;
}
DispHz(x,y);
x+=HZWITH;
}else{//display char
hz[0]=string[i++];
if(x+CHWITH>LCDWITH){
x=0;
y+=CHHIGH;
if(y+CHHIGH>LCDHIGH)y=0;
}
if(hz[0]!=0x0a){
DispCh(x,y,hz[0]);
x+=CHWITH;
}
}
}
}
void NorArea(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1)
{//把左上角(x0,y0)和右下角(x1,y1)反相显示.
unsigned char x,y,m,m0,m1,temp,temp0;
char *ptr;
g.Flag.DispUpData=1;
temp=0;
for(y=y0;y<=y1;y++){
m=y%8;
temp |=LineTable[m];
if(m==7){
temp0=~temp;
ptr=(char *)&DispBuf[y/8][x0];
for(x=x0;x<=x1;x++,ptr++){
m=*ptr;
m0 =m&temp0;
m1 =~m;
m1 &=temp;
*ptr=m0|m1;
}
temp=0;
}
}
if(temp){
temp0=~temp;
ptr=(char *)&DispBuf[(y-1)/8][x0];
for(x=x0;x<=x1;x++,ptr++){
m=*ptr;
m0 =m&temp0;
m1 =~m;
m1 &=temp;
*ptr=m0|m1;
}
}
}
void ClrArea(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1)
{
unsigned char k,m,from,x,y;
char *ptr;
g.Flag.DispUpData=1;
k=y0/8,m=0xff;
for(y=y0;y<=y1;y++){
if(y/8!=k){//不共一页.
ptr=(char *)&DispBuf[k++][x0];
for(x=x0;x<=x1;x++,ptr++){
from= *ptr;
from &=m;
*ptr=from;
}
m=0xff,y--;
}else{
m &=ClrTable[y%8];
}
}
if(m==0xff)return;
ptr=(char *)&DispBuf[k][x0];
for(x=x0;x<=x1;x++,ptr++){
from= *ptr;
from &=m;
*ptr=from;
}
}
void DisplayBmp(const unsigned int bmpAddr,unsigned char x0,unsigned char y0,unsigned char Xsize,unsigned char Ysize)
{ //(x,y) 显示的起始座标.
//Xsize,Ysize分别是bmp的x,y方向的(点阵)大小.
unsigned char i,j;
unsigned char *pto1,*pto2;
unsigned char m1,m2,m3,m4,m5,m6,m7,m8;
unsigned int addr;
m7=y0%8;
addr=bmpAddr;
if(m7==0){
m1=Ysize/8;
m2=y0/8;
for(i=0;i<=m1;i++){//
pto1=(unsigned char *)&DispBuf[m2+i][x0];
for(j=0;j<Xsize;j++,pto1++){
m4=*pto1;
m4 |= I2CRead(addr++);//*pfrom;
*pto1=m4;
}
}
}else{
m1=0;
for(i=m7;i<8;i++) m1 |=LineTable[i];
m2=~m1;
for(i=0;i<=Ysize/8;i++){
pto1=(unsigned char *)&DispBuf[y0/8+i][x0];
pto2=(unsigned char *)&DispBuf[y0/8+i+1][x0];
for(j=0;j<Xsize;j++){
m3=*(volatile unsigned char *)pto1;
m4=*(volatile unsigned char *)pto2;
m5=I2CRead(addr++);//*(volatile unsigned char *)pfrom++;
m8 =m3&m2;
m6 =m5<<m7;
m6 &=m1;
*pto1++ =m6|m8;
m8 =m4&m1;
m6 =m5>>(8-m7);
m6 &=m2;
*pto2++=m6|m8;
}
if(i>6) break;//overflow page range.
}
}
}
void DisplayLogo(unsigned int ul,unsigned char i)
{
unsigned char uc0,uc1,uc2,uc3;
unsigned int ul0;
unsigned char j;
unsigned int us0;
ul0=ul;
j=0;
ul0+=1;
while(j<i){
ul0+=2;
uc0=I2CRead(ul0++);
uc1=I2CRead(ul0++);
us0=(unsigned int )uc1;
us0 *=uc0;
us0 /=8;
ul0+=us0;//(unsigned int)(uc1*uc0/8);
j++;
}
Cls();
uc0=I2CRead(ul0++);
uc1=I2CRead(ul0++);
uc2=I2CRead(ul0++);
uc3=I2CRead(ul0++);
DisplayBmp(ul0,uc0,uc1,uc2,uc3);
g.Flag.DispUpData=1;
}
void DispChange(void)
{
unsigned char uc0,uc1,uc2;
unsigned char *ptr;
for(uc0=0;uc0<4;uc0++){
LCDWrite(1,0,0);
LCDWrite(1,0,DispPage[uc0]);
ptr=(unsigned char *)&DispBuf[uc0][0];
for(uc1=0;uc1<LCDWITH/2;uc1++){
uc2=*ptr++;
LCDWrite(1,1,uc2);
}
LCDWrite(2,0,0);
LCDWrite(2,0,DispPage[uc0]);
ptr=(unsigned char *)&DispBuf[uc0][uc1];
for(;uc1<LCDWITH;uc1++){
uc2=*ptr++;
LCDWrite(2,1,uc2);
}
}
}
void LCDInit(unsigned char ce)
{
LCDWrite(ce,0,0xe2); //Reset.
LCDWrite(ce,0,0xaf); //Display ON.
LCDWrite(ce,0,0xc0); //start line.
LCDWrite(ce,0,0xb8); //page.
LCDWrite(ce,0,0); //column.
LCDWrite(ce,0,0xa0); //ADC.
LCDWrite(ce,0,0xa9); //duty.
LCDWrite(ce,0,0xa4);
}
void LCDWrite(unsigned char CE,unsigned char Cmd,unsigned char ch)
{
ClrBit(EPort0,E1);
ClrBit(EPort0,E2);
if(CE==1)SetBit(EPort0,E1);
else SetBit(EPort0,E2);
ClrBit(EPort1,RW);
if(Cmd) SetBit(EPort1,A0);
else ClrBit(EPort1,A0);
P1 =ch;
ClrBit(EPort0,E1);
ClrBit(EPort0,E2);
SetBit(EPort1,RW);
}
/*
void LCDBusyTest(void)
{
while(1){
SetBit(EPort0,E1);
ClrBit(EPort0,E2);
SetBit(EPort1,RW);
ClrBit(EPort1,A0);
if((P1&0x80)==0) break;
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -