📄 main.c
字号:
#include "fun.h"
#include <ABSACC.H>
/************针对FM1808存储区的变量*******/
data uint BufAddr1; //范围:0X7800~0X7FFF(2KBytes)
//内容:存放从PC主机串口传来的数据
data uint BufCount1; //对从PC主机串口传来的数据计数
data uint BufAddr2; //范围:0X7000~0X7FFF(4KBytes)
//内容:存放点阵显示数据的字库地址
data uint BufCount2; //
data uint BufAddr3; //范围:0X0000~0X6FFF(28KBytes)
//内容:存放点阵显示的数据
data uint BufCount3; //
data uint T0Count; //UART有否超时的定时计数
bdata uchar Flag;
sbit FlagUART = Flag^0; //TRUE有串口中断,FALSE无串口中断
sbit FlagFont = Flag^1; //TRUE显示24*24字体,FALSE显示16*16字体
sbit FlagDisp = Flag^2; //TRUE滚动显示,FALSE只显示一屏
data uint TotalRow; //总共需显示的行数
data uint CurrentRow; //fm1808当前行
data uchar StartRow; //各显示单元的扫描起始行
data union
{ulong addr;
struct
{uchar nonaddr;
uchar p1;
uint p2p0;
}port;
}ziku;
/***************************************************************/
void kmg(void)
{KMG=0;
KMG=1;
}
void delay(uint i)
{while(i!=0)i--;
}
void t0_init(void)
{TMOD&=0xf0;
TMOD|=0x01; //定时器T0,方式1
TL0=0x00;
TH0=0x00;
TCON|=0x10; //TF1TR1TF0TR0IE1IT1IE0IT0;TR0=1
ET0=1;
EA=1;
}
void to_interrupt(void) interrupt 1 using 1
{TH0=0x00;
TL0=0x00;
if(++T0Count>20)
{FlagUART=FALSE;
TR0=0;
ET0=0;
ES=0;
}
}
void uart_init(void)
{PCON=0x00; //SMOD--------GF1GF0PDIDL=00000000;波特率未加倍
TMOD&=0x0f;
TMOD|=0x20; //定时器T1,方式2
TL1=0xfd; //波特率9600
TH1=0xfd;
SCON=0x50; //SM0SM1SM2RENTB8RB8TIRI=01010000B;串口方式1
TCON|=0x40; //TF1TR1TF0TR0IE1IT1IE0IT0;TR1=1
IP=0x10; //--------PSPT1PX1PT0PX0=00010000B;串口中断优先
ES=1;
EA=1;
}
void uart_interrupt(void) interrupt 4 using 2
{if(RI==1)
{if(!FlagUART)
{FlagUART=TRUE;
BufCount1=0;
BufAddr1=BUFHEAD1;
}
P1=CS;
XBYTE[BufAddr1++]=SBUF;
BufCount1++;
T0Count=0;
RI=0;
}
else TI=0;
}
uchar rd_fm1808(uint addr)
{P1=CS;
return(XBYTE[addr]);
}
void wr_fm1808(uint addr,uchar dat)
{P1=CS;
XBYTE[addr]=dat;
}
void blankfm1808(void)
{uint tempw;
tempw=0;
while(tempw<BUFHEAD1)
{wr_fm1808(tempw,0);
tempw++;
}
}
void hanzi_addr(uchar qm,uchar wm)
{ulong offset;
offset=(ulong)(wm-0xa1);
offset+=(ulong)((qm-0xb0)*94);
if(FlagFont)
{offset*=72;
offset+=BIG_FONT_HEAD;
ziku.port.p2p0=(uint)offset;
ziku.port.p1=(uchar)(offset>>16);
ziku.port.p1&=0X0F;
ziku.port.p1|=CS2;
}
else
{offset*=32;
offset+=SMALL_FONT_HEAD;
ziku.port.p2p0=(uint)offset;
ziku.port.p1=(uchar)(offset>>16);
ziku.port.p1&=0X0F;
ziku.port.p1|=CS1;
}
}
void half_addr(uchar qm,uchar wm)
{ulong offset;
offset=wm;
offset=(ulong)(qm-32);
if(FlagFont)
{offset*=72;
ziku.port.p2p0=(uint)offset;
ziku.port.p1=(uchar)(offset>>16);
ziku.port.p1&=0X0F;
ziku.port.p1|=CS2;
}
else
{offset*=32;
ziku.port.p2p0=(uint)offset;
ziku.port.p1=(uchar)(offset>>16);
ziku.port.p1&=0X0F;
ziku.port.p1|=CS1;
}
}
void full01_addr(uchar qm,uchar wm)
{ulong offset;
offset=(ulong)(wm-0xa1);
offset+=(ulong)((qm-0xa1)*94);
if(FlagFont)
{offset*=72;
ziku.port.p2p0=(uint)offset;
ziku.port.p1=(uchar)(offset>>16);
ziku.port.p1&=0X0F;
ziku.port.p1|=CS3;
}
else
{offset*=32;
offset+=FULL01_FONT16_HEAD;
ziku.port.p2p0=(uint)offset;
ziku.port.p1=(uchar)(offset>>16);
ziku.port.p1&=0X0F;
ziku.port.p1|=CS1;
}
}
void full03_addr(uchar qm,uchar wm)
{ulong offset;
offset=(ulong)(wm-0xa0);
offset+=(ulong)((qm-0xa3)*94);
if(FlagFont)
{offset*=72;
offset+=FULL03_FONT24_HEAD;
ziku.port.p2p0=(uint)offset;
ziku.port.p1=(uchar)(offset>>16);
ziku.port.p1&=0X0F;
ziku.port.p1|=CS3;
}
else
{offset*=32;
offset+=FULL03_FONT16_HEAD;
ziku.port.p2p0=(uint)offset;
ziku.port.p1=(uchar)(offset>>16);
ziku.port.p1&=0X0F;
ziku.port.p1|=CS1;
}
}
void wrzikuaddr(void)
{uchar tempb;
uint tempw;
tempw=BufAddr2+BufCount2++;
tempb=ziku.port.p1;
wr_fm1808(tempw,tempb);
tempw=BufAddr2+BufCount2++;
tempb=(uchar)(ziku.port.p2p0>>8);
wr_fm1808(tempw,tempb);
tempw=BufAddr2+BufCount2++;
tempb=(uchar)(ziku.port.p2p0);
wr_fm1808(tempw,tempb);
}
void wrbblank(void)
{uint tempw;
tempw=BufAddr2+BufCount2++;
wr_fm1808(tempw,BBLANKP1);
tempw=BufAddr2+BufCount2++;
wr_fm1808(tempw,BBLANKP2);
tempw=BufAddr2+BufCount2++;
wr_fm1808(tempw,BBLANKP0);
}
void wrsblank(void)
{uint tempw;
tempw=BufAddr2+BufCount2++;
wr_fm1808(tempw,SBLANKP1);
tempw=BufAddr2+BufCount2++;
wr_fm1808(tempw,SBLANKP2);
tempw=BufAddr2+BufCount2++;
wr_fm1808(tempw,SBLANKP0);
}
void code_analyse(void)
{uchar qm,wm;
FlagFont=FALSE; //默认为16*16字体
BufAddr2=BUFHEAD2;
BufCount2=0;
BufAddr1=BUFHEAD1;
while(BufCount1)
{kmg();
if(BufAddr1<(BufAddr2+100))
{break;
}
BufCount1--;
qm=rd_fm1808(BufAddr1++);
if(qm>=32&&qm<=126) //半角标点符号
{switch(qm)
{case ASCII_SF:if(BufCount2==0) //16*16
{wr_fm1808(BufAddr2,SFLAGFONT);
BufCount2++;
}
else if(!FlagFont)
{half_addr(qm,wm);
wrzikuaddr();
if(BufCount2>48)
{BufAddr2+=50;
BufCount2=0;
}
}
else
{while(BufCount2<=30)
{wrbblank();
}
BufAddr2+=50;
BufCount2=0;
}
FlagFont=FALSE;
break;
case ASCII_BF:if(BufCount2==0) //24*24
{wr_fm1808(BufAddr2,BFLAGFONT);
BufCount2++;
}
else if(FlagFont)
{half_addr(qm,wm);
wrzikuaddr();
if(BufCount2>30)
{BufAddr2+=50;
BufCount2=0;
}
}
else
{while(BufCount2<=48)
{wrsblank();
}
BufAddr2+=50;
BufCount2=0;
}
FlagFont=TRUE;
break;
case ASCII_NR:if(BufCount2==0) //换行
{if(FlagFont)
{wr_fm1808(BufAddr2,BFLAGFONT);}
else
{wr_fm1808(BufAddr2,SFLAGFONT);}
BufCount2++;
}
else if(FlagFont)
{while(BufCount2<=30)
{wrbblank();
}
BufAddr2+=50;
BufCount2=0;
}
else
{while(BufCount2<=48)
{wrsblank();
}
BufAddr2+=50;
BufCount2=0;
}
break;
default:if(BufCount2==0)
{if(FlagFont)
{wr_fm1808(BufAddr2,BFLAGFONT);}
else
{wr_fm1808(BufAddr2,SFLAGFONT);}
BufCount2++;
}
half_addr(qm,wm);
wrzikuaddr();
if((FlagFont&&(BufCount2>30))||(!FlagFont&&(BufCount2>48)))
{BufAddr2+=50;
BufCount2=0;
}
break;
}
}
else if((qm<32)||((qm>126)&&(qm<161)))
{continue;}
else
{if(BufCount1--)
{wm=rd_fm1808(BufAddr1++);}
else break;
if((qm>=0xb0&&qm<=0xf7)&&(wm>=0xa0&&wm<=0xfe)) //汉字区位码
{if(BufCount2==0)
{if(FlagFont)
{wr_fm1808(BufAddr2,BFLAGFONT);}
else
{wr_fm1808(BufAddr2,SFLAGFONT);}
BufCount2++;
}
hanzi_addr(qm,wm);
wrzikuaddr();
if((FlagFont&&(BufCount2>30))||(!FlagFont&&(BufCount2>48)))
{BufAddr2+=50;
BufCount2=0;
}
}
else if((qm==0xa1)&&(wm>=0xa1&&wm<=0xfe)) //全角标点01符号
{if(BufCount2==0)
{if(FlagFont)
{wr_fm1808(BufAddr2,BFLAGFONT);}
else
{wr_fm1808(BufAddr2,SFLAGFONT);}
BufCount2++;
}
full01_addr(qm,wm);
wrzikuaddr();
if((FlagFont&&(BufCount2>30))||(!FlagFont&&(BufCount2>48)))
{BufAddr2+=50;
BufCount2=0;
}
}
else if((qm==0xa3)&&(wm>=0xa0&&wm<=0xfe)) //全角标点03符号
{if(BufCount2==0)
{if(FlagFont)
{wr_fm1808(BufAddr2,BFLAGFONT);}
else
{wr_fm1808(BufAddr2,SFLAGFONT);}
BufCount2++;
}
full03_addr(qm,wm);
wrzikuaddr();
if((FlagFont&&(BufCount2>30))||(!FlagFont&&(BufCount2>48)))
{BufAddr2+=50;
BufCount2=0;
}
}
else continue;
}
}
if(BufCount2!=0)
{if(FlagFont)
{while(BufCount2<=30)wrbblank();
}
else
{while(BufCount2<=48)wrsblank();
}
BufAddr2+=50;
BufCount2=0;
}
wr_fm1808(BufAddr2,NFLAGFONT); //结束标记
}
uchar rdzikudat(void)
{P1=ziku.port.p1;
return(XBYTE[ziku.port.p2p0]);
}
void getzikuaddr(void)
{uchar tempb;
uint j,tempw;
tempw=BufAddr2+BufCount2;
tempb=rd_fm1808(tempw);
ziku.port.p1=tempb;
BufCount2++;
tempw=BufAddr2+BufCount2;
tempb=rd_fm1808(tempw);
j=(uint)tempb;
j<<=8;
BufCount2++;
tempw=BufAddr2+BufCount2;
tempb=rd_fm1808(tempw);
j+=(uint)tempb;
ziku.port.p2p0=j;
BufCount2++;
}
void array_addr_dat(void)
{uchar flagfont;
uchar i,tempb;
uint tempw;
uint currentrow;
uint currentline;
BufAddr2=BUFHEAD2;
BufCount2=0;
BufAddr3=BUFHEAD3;
while(1)
{kmg();
tempw=BufAddr2+BufCount2;
flagfont=rd_fm1808(tempw);
BufCount2++;
if(BufAddr3>=BUFHEAD2)
{flagfont=NFLAGFONT;}
if(flagfont==SFLAGFONT)
{for(currentline=0;currentline<32;)
{getzikuaddr();
currentrow=BufAddr3;
for(i=0;i<16;i++)
{tempw=currentrow+currentline;
tempb=rdzikudat();
wr_fm1808(tempw,tempb);
ziku.addr+=1;
tempb=rdzikudat();
tempw=currentrow+currentline+1;
wr_fm1808(tempw,tempb);
ziku.addr++;
currentrow+=32;
}
currentline+=2;
}
BufAddr3+=512;
}
else if(flagfont==BFLAGFONT)
{currentrow=BufAddr3;
for(i=0;i<24;i++)
{wr_fm1808(currentrow,0x00);
currentrow+=32;
}
currentrow=BufAddr3+31;
for(i=0;i<24;i++)
{wr_fm1808(currentrow,0x00);
currentrow+=32;
}
for(currentline=1;currentline<31;)
{getzikuaddr();
currentrow=BufAddr3;
for(i=0;i<24;i++)
{tempw=currentrow+currentline;
tempb=rdzikudat();
wr_fm1808(tempw,tempb);
ziku.addr++;
tempb=rdzikudat();
tempw=currentrow+currentline+1;
wr_fm1808(tempw,tempb);
ziku.addr++;
tempb=rdzikudat();
tempw=currentrow+currentline+2;
wr_fm1808(tempw,tempb);
ziku.addr++;
currentrow+=32;
}
currentline+=3;
}
BufAddr3+=768;
}
else
{BufAddr3/=32;
tempb=(uchar)BufAddr3;
wr_fm1808(TOTALROWL,tempb);
delay(10);
BufAddr3>>=8;
tempb=(uchar)BufAddr3;
wr_fm1808(TOTALROWH,tempb);
break;
}
BufAddr2+=50;
BufCount2=0;
}
}
void wrstartaddr1(void)
{P1=CE1;
XBYTE[STARTROW]=0;
P1=CE2;
XBYTE[STARTROW]=0;
P1=CE3;
XBYTE[STARTROW]=0;
P1=CE4;
XBYTE[STARTROW]=0;
}
void wrstartaddr2(void)
{P1=CE1;
XBYTE[STARTROW]=StartRow;
P1=CE2;
XBYTE[STARTROW]=StartRow;
P1=CE3;
XBYTE[STARTROW]=StartRow;
P1=CE4;
XBYTE[STARTROW]=StartRow;
}
void clear_idt7132(void)
{uint tempw;
for(tempw=0;tempw<2048;tempw++)
{P1=CE1;
XBYTE[tempw]=0xff;
P1=CE2;
XBYTE[tempw]=0xff;
P1=CE3;
XBYTE[tempw]=0xff;
P1=CE4;
XBYTE[tempw]=0xff;
}
}
void fill16rows(uchar chip,uchar fillrow)
{uchar i,j;
uchar tempb;
uint tempw;
for(j=0;(j<16)&&(CurrentRow<TotalRow);j++)
{for(i=0;i<32;i++)
{tempw=CurrentRow*32+i;
tempb=rd_fm1808(tempw);
tempb=~tempb;
tempw=(uint)(fillrow*32+i);
P1=chip;
XBYTE[tempw]=tempb;
}
CurrentRow++;
fillrow++;
}
}
void fillscreen(void)
{clear_idt7132();
CurrentRow=0;
fill16rows(CE1,0);
if(CurrentRow<TotalRow)
fill16rows(CE2,0);
if(CurrentRow<TotalRow)
fill16rows(CE3,0);
if(CurrentRow<TotalRow)
fill16rows(CE4,0);
wrstartaddr1();
}
void fillblankrow(uchar chip,uchar fillrow)
{uchar i;
uint tempw;
for(i=0;i<32;i++)
{tempw=(uint)(fillrow*32+i);
P1=chip;
XBYTE[tempw]=0xff;
}
}
void filldatrow(uchar chip,uint currentrow,uchar fillrow)
{uchar i,tempb;
uint tempw;
for(i=0;i<32;i++)
{tempw=currentrow*32+i;
tempb=rd_fm1808(tempw);
tempb=~tempb;
tempw=(uint)(fillrow*32+i);
P1=chip;
XBYTE[tempw]=tempb;
}
}
void fillonerow(void)
{uint tempw;
uchar fillrow;
fillrow=StartRow+16;
fillrow%=32;
//CE4
if(CurrentRow>=TotalRow)
{fillblankrow(CE4,fillrow);
}
else
{tempw=CurrentRow;
filldatrow(CE4,tempw,fillrow);
}
//CE3
if((CurrentRow<16)||(CurrentRow>=(TotalRow+16)))
{fillblankrow(CE3,fillrow);
}
else
{tempw=CurrentRow-16;
filldatrow(CE3,tempw,fillrow);
}
//CE2
if((CurrentRow<32)||(CurrentRow>=(TotalRow+32)))
{fillblankrow(CE2,fillrow);
}
else
{tempw=CurrentRow-32;
filldatrow(CE2,tempw,fillrow);
}
//CE1
if((CurrentRow<48)||(CurrentRow>=(TotalRow+48)))
{fillblankrow(CE1,fillrow);
}
else
{tempw=CurrentRow-48;
filldatrow(CE1,tempw,fillrow);
}
++CurrentRow;
CurrentRow%=(TotalRow+64);
StartRow++;
StartRow%=32;
wrstartaddr2();
}
void init_display(void)
{uchar tempb;
uint tempw;
clear_idt7132();
tempb=rd_fm1808(TOTALROWH);
tempw=(uint)tempb;
tempw<<=8;
delay(10);
tempb=rd_fm1808(TOTALROWL);
TotalRow=(uint)tempb;
TotalRow&=0x00ff;
TotalRow+=tempw;
StartRow=0;
CurrentRow=0;
if(TotalRow<=MAXROW)
{FlagDisp=FALSE;
fillscreen();
}
else
{FlagDisp=TRUE;
fillonerow();
}
}
void init(void)
{P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
uart_init();
FlagUART=FALSE;
BufAddr1=BUFHEAD1;
init_display();
}
void main(void)
{uint uicount;
ulong ulcount;
uicount=0;
ulcount=0;
delay(1000);
kmg();
init();
kmg();
while(1)
{kmg();
if(FlagUART) //响应到串口中断,表示有PC传新数据过来
{t0_init();
while(FlagUART){kmg();} //接受数据中。。。
kmg();
if(BufCount1>1)
{kmg();
blankfm1808();
kmg();
code_analyse();
kmg();
array_addr_dat();
kmg();
init();
kmg();
}
else
{uart_init();}
}
if((++uicount>5000)&&FlagDisp)
{fillonerow();
uicount=0;
}
else if((++ulcount>10000000)&&(!FlagDisp))
{fillscreen();
ulcount=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -