📄 main.c
字号:
case 0x0202:
key=0x1e;
break;
case 0x0201:
key=0x1f;
break;
case 0x0480:
key=0x20;
break;
case 0x0440:
key=0x21;
break;
case 0x0420:
key=0x22;
break;
case 0x0410:
key=0x23;
break;
case 0x0408:
key=0x24;
break;
case 0x0404:
key=0x25;
break;
case 0x0402:
key=0x26;
break;
case 0x0401:
key=0x27;
break;
case 0x0880:
key=0x28;
break;
case 0x0840:
key=0x29;
break;
case 0x0820:
key=0x2a;
break;
//case 0x0810:
// key=0x2b;
// break;
case 0x0808:
key=0x2c;
break;
//case 0x0804:
// key=0x2d;
// break;
case 0x0802:
key=0x2e;
break;
case 0x0801:
key=0x2f;
break;
}
SCITXBUF=key;
}
/*256色转换成16bit色*/
unsigned int ColorTransfer(unsigned char color256)
{
/*3:3:2->5:6:5 RGB*/
unsigned int r,g,b;
unsigned int color16bit;
r=(color256&0xe0);
g=(color256&0x1c)<<1;
r+=(g&0x38)>>3;
b=(color256&0x03)<<2;
b+=(g&0x07)<<5;
color16bit=(b<<8)+r;
return color16bit;
}
/*在指定位置显示规定颜色和底色的16X16字符*/
void DisplayWord1Func(unsigned int x,unsigned int y,unsigned int bcolor,unsigned int fcolor,unsigned char *fontbuf,unsigned char num)
{
unsigned long position;
unsigned long positionASC,positionHZ;
unsigned int i,j,font,bank,offset,bank1,offset1;
unsigned int *pDram,*pFlash;
unsigned int one,posoffset;
FlashBlockIndex=0; /*从flash字库中提取字符*/
FlashReadOut(2, 2, BUFFER);
position=(unsigned long)(BUFFER[0]&0x00ff);
position<<=15;
i=(BUFFER[1]&0x00ff)<<8;
j=(BUFFER[1]&0xff00)>>8;
position+=i+j-0x8000;
positionASC=position+ASCIIFontAddress;
positionHZ=position+HZFontAddress;
one=0;
for(i=0;i<num;i++)
{
if(fontbuf[i]<0x80) /*16*8 ASC字符*/
{
position=positionASC+((unsigned int)fontbuf[i])*16;
position>>=1;
bank1=position>>15;
offset1=position&0x7fff;
for(j=0;j<8;j++)
{
PBDATDIR=0xff40+bank1;
pFlash=(unsigned int *)(0x8000+offset1);
BUFFER[one+j]=*(pFlash);
offset1++;
if(offset1>=0x8000)
{
bank1++;
offset1-=0x8000;
}
}
one+=8;
}
else /*16*16 汉字*/
{
position=(((unsigned long)fontbuf[i]-0xb0)*94+((unsigned long)fontbuf[i+1]-0xa1))*32;
position+=positionHZ;
position>>=1;
bank1=position>>15;
offset1=position&0x7fff;
for(j=0;j<16;j++)
{
PBDATDIR=0xff40+bank1;
pFlash=(unsigned int *)(0x8000+offset1);
BUFFER[one+j]=*(pFlash);
offset1++;
if(offset1>=0x8000)
{
bank1++;
offset1-=0x8000;
}
}
one+=16;
i++;
}
}
posoffset=0;
for(one=0;one<num;one++) /*在备份显示缓冲区中写入字符数据*/
{
WaitVNDP();
if(fontbuf[one]<0x80)
{
for(i=0;i<8;i++)
{
font=(BUFFER[posoffset+i]&0xff00)>>8;
position=(((unsigned long)(y+2*i))*640)+x+posoffset;
bank=position>>15;
offset=position&0x7fff;
pDram=(unsigned int *)(0x8000+offset);
for(j=0;j<8;j++)
{
if(LCDFreshIndex==0)
PBDATDIR=0xff2c+bank;
else
PBDATDIR=0xff20+bank;
if((font&0x80)==0x80)
*(pDram++)=fcolor;
else
*(pDram++)=bcolor;
font<<=1;
offset++;
if(offset>=0x8000)
{
bank++;
offset=0x0000;
pDram=(unsigned int *)(0x8000);
}
}
font=BUFFER[posoffset+i]&0x00ff;
position=(((unsigned long)(y+2*i+1))*640)+x+posoffset;
bank=position>>15;
offset=position&0x7fff;
pDram=(unsigned int *)(0x8000+offset);
for(j=0;j<8;j++)
{
if(LCDFreshIndex==0)
PBDATDIR=0xff2c+bank;
else
PBDATDIR=0xff20+bank;
if((font&0x80)==0x80)
*(pDram++)=fcolor;
else
*(pDram++)=bcolor;
font<<=1;
offset++;
if(offset>=0x8000)
{
bank++;
offset=0x0000;
pDram=(unsigned int *)(0x8000);
}
}
}
posoffset+=8;
}
else
{
for(i=0;i<16;i++)
{
font=BUFFER[posoffset+i];
position=(((unsigned long)(y+i))*640)+x+posoffset;
bank=position>>15;
offset=position&0x7fff;
pDram=(unsigned int *)(0x8000+offset);
for(j=0;j<16;j++)
{
if(LCDFreshIndex==0)
PBDATDIR=0xff2c+bank;
else
PBDATDIR=0xff20+bank;
if((font&0x8000)==0x8000)
*(pDram++)=fcolor;
else
*(pDram++)=bcolor;
font<<=1;
offset++;
if(offset>=0x8000)
{
bank++;
offset=0x0000;
pDram=(unsigned int *)(0x8000);
}
}
}
posoffset+=16;
one++;
}
}
LCDVramXChange(); /*将备份显示缓冲区变成主显示缓冲区*/
/*当前显示缓冲区切换成备份显示缓冲区*/
/*向原主显示缓冲区写入显示数据,保持主备显示同步*/
posoffset=0;
for(one=0;one<num;one++) /*在备份显示缓冲区中写入字符数据*/
{
WaitVNDP();
if(fontbuf[one]<0x80)
{
for(i=0;i<8;i++)
{
font=(BUFFER[posoffset+i]&0xff00)>>8;
position=(((unsigned long)(y+2*i))*640)+x+posoffset;
bank=position>>15;
offset=position&0x7fff;
pDram=(unsigned int *)(0x8000+offset);
for(j=0;j<8;j++)
{
if(LCDFreshIndex==0)
PBDATDIR=0xff2c+bank;
else
PBDATDIR=0xff20+bank;
if((font&0x80)==0x80)
*(pDram++)=fcolor;
else
*(pDram++)=bcolor;
font<<=1;
offset++;
if(offset>=0x8000)
{
bank++;
offset=0x0000;
pDram=(unsigned int *)(0x8000);
}
}
font=BUFFER[posoffset+i]&0x00ff;
position=(((unsigned long)(y+2*i+1))*640)+x+posoffset;
bank=position>>15;
offset=position&0x7fff;
pDram=(unsigned int *)(0x8000+offset);
for(j=0;j<8;j++)
{
if(LCDFreshIndex==0)
PBDATDIR=0xff2c+bank;
else
PBDATDIR=0xff20+bank;
if((font&0x80)==0x80)
*(pDram++)=fcolor;
else
*(pDram++)=bcolor;
font<<=1;
offset++;
if(offset>=0x8000)
{
bank++;
offset=0x0000;
pDram=(unsigned int *)(0x8000);
}
}
}
posoffset+=8;
}
else
{
for(i=0;i<16;i++)
{
font=BUFFER[posoffset+i];
position=(((unsigned long)(y+i))*640)+x+posoffset;
bank=position>>15;
offset=position&0x7fff;
pDram=(unsigned int *)(0x8000+offset);
for(j=0;j<16;j++)
{
if(LCDFreshIndex==0)
PBDATDIR=0xff2c+bank;
else
PBDATDIR=0xff20+bank;
if((font&0x8000)==0x8000)
*(pDram++)=fcolor;
else
*(pDram++)=bcolor;
font<<=1;
offset++;
if(offset>=0x8000)
{
bank++;
offset=0x0000;
pDram=(unsigned int *)(0x8000);
}
}
}
posoffset+=16;
one++;
}
}
}
unsigned char UARTHandle(void)
{
unsigned int temp1,temp2;
unsigned int temp3,temp4;
switch(UartBuf[0])
{
case CheckLCMStatus: /*检查显示板状态*/
if(SystemInitStatus==OK)
return RUNOK;
else
return RUNERROR;
break;
case DisplayWord1: /*显示字符1*/
temp1=((unsigned int)(UartBuf[5]<<8))+UartBuf[4];
temp2=((unsigned int)(UartBuf[7]<<8))+UartBuf[6];
DisplayWord1Func(temp1,temp2,ColorTransfer(UartBuf[2]),ColorTransfer(UartBuf[3]),&UartBuf[8],UartBuf[1]-9);
break;
case PaintBox: /*画框*/
temp1=((unsigned int)(UartBuf[4]<<8))+UartBuf[3];
temp2=((unsigned int)(UartBuf[6]<<8))+UartBuf[5];
temp3=((unsigned int)(UartBuf[8]<<8))+UartBuf[7];
temp4=((unsigned int)(UartBuf[10]<<8))+UartBuf[9];
PaintBoxFunc(temp1, temp2, temp3-temp1, temp4-temp2,ColorTransfer(UartBuf[2]));
break;
case PaintPicture: /*画图*/
temp1=((unsigned int)(UartBuf[3]<<8))+UartBuf[2];
temp2=((unsigned int)(UartBuf[5]<<8))+UartBuf[4];
PaintPictureFunc(temp1,temp2,UartBuf[6]);
break;
case DisplayWord2: /*显示字符2*/
temp1=((unsigned int)(UartBuf[5]<<8))+UartBuf[4];
temp2=((unsigned int)(UartBuf[7]<<8))+UartBuf[6];
DisplayWord2Func(temp1,temp2,ColorTransfer(UartBuf[2]),ColorTransfer(UartBuf[3]),&UartBuf[8],UartBuf[1]-9);
break;
case StoreBoxRam: /*保存报警框显存数据*/
temp1=((unsigned int)(UartBuf[3]<<8))+UartBuf[2];
temp2=((unsigned int)(UartBuf[5]<<8))+UartBuf[4];
temp3=((unsigned int)(UartBuf[7]<<8))+UartBuf[6];
temp4=((unsigned int)(UartBuf[9]<<8))+UartBuf[8];
StoreBoxRamFunc(temp1, temp2, temp3-temp1, temp4-temp2);
break;
case RefreshBoxRam: /*恢复保存的报警框显存数据*/
temp1=((unsigned int)(UartBuf[3]<<8))+UartBuf[2];
temp2=((unsigned int)(UartBuf[5]<<8))+UartBuf[4];
temp3=((unsigned int)(UartBuf[7]<<8))+UartBuf[6];
temp4=((unsigned int)(UartBuf[9]<<8))+UartBuf[8];
RefreshBoxRamFunc(temp1, temp2, temp3-temp1, temp4-temp2);
break;
case PaintBoxShade: /*画阴影框*/
temp1=((unsigned int)(UartBuf[4]<<8))+UartBuf[3];
temp2=((unsigned int)(UartBuf[6]<<8))+UartBuf[5];
temp3=((unsigned int)(UartBuf[8]<<8))+UartBuf[7];
temp4=((unsigned int)(UartBuf[10]<<8))+UartBuf[9];
PaintBoxShadeFunc(temp1, temp2, temp3, temp4,ColorTransfer(UartBuf[2]));
break;
case ResetBoard: /*显示板复位*/
WDCR=0x0AD; /*开启看门狗52.4mS*/
break;
case DisplayWord3: /*显示字符3*/
temp1=((unsigned int)(UartBuf[5]<<8))+UartBuf[4];
temp2=((unsigned int)(UartBuf[7]<<8))+UartBuf[6];
DisplayWord3Func(temp1,temp2,ColorTransfer(UartBuf[2]),ColorTransfer(UartBuf[3]),&UartBuf[8],UartBuf[1]-9);
break;
case RestoreFile: /*文件数据传输开始*/
if((UartBuf[2]==0x86)&&(UartBuf[3]==0x00))
{
WhoseFile=PicFile;
FileBank=0;
FileAlreadyDone=0;
startFileTrans=1;
}
else if((UartBuf[2]==0x80)&&(UartBuf[3]==0x00))
{
WhoseFile=LibFile;
FileBank=0;
FileAlreadyDone=0;
startFileTrans=1;
}
break;
case AckFileTrans: /*回应USB板文件传输包*/
RestoreFileFunc((UartBuf[1]-3),&UartBuf[2]);
break;
case PaintLogo: /*画厂标*/
PaintLogoFunc();
break;
case DisplayWord4: /*显示字符4*/
break;
default:
break;
}
return RUNOK;
}
void interrupt int1ser( )
{
unsigned char i;
switch(PIVR)
{
case 0x06: /*接收中断*/
i=SCIRXBUF;
OverTimer=0;
Flag2=InReceive;
UartBuf[RecIndex++]=i;
if(RecIndex==2)
FrameLength=i;
if(RecIndex==FrameLength)
{
if((SumParity&0x00ff)==i)
Flag|=RECOK;
else
{
Flag|=RECERROR;
}
}
else
SumParity+=i;
IFR=0x01;
break;
case 0x07: /*发送中断*/
Flag|=SNDOK;
IFR=0x01;
break;
}
asm(" clrc INTM");
return;
}
void interrupt int2ser( )
{
unsigned char i;
switch(PIVR)
{
case 0x27: /*定时器1周期中断*/
Flag1=SCANKEY;
if(Flag2==InReceive)
{
OverTimer++;
if(OverTimer>=2)
{
Flag=0;
Flag2=0;
RecIndex=0;
SumParity=0;
FrameLength=0;
}
}
EVAIFRA &=0x0080;
IFR=0x02;
break;
}
asm(" clrc INTM");
return;
}
void interrupt nothing( )
{
asm(" clrc INTM");
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -