h>
externvoidcls();
externucharLCD_Initialise();
externucharLCD_Write_Command(ucharcmd);
externucharLCD_Write_Command_P2(ucharcmd,ucharpara1,ucharpara2);
externucharLCD_Write_Data(uchardat);
externvoidSet_LCD_POS(ucharrow,ucharcol);
externvoidLine(ucharx1,uchary1,ucharx2,uchary2,bitMode);
externucharDisplay_Str_at_xy(ucharx,uchary,char*fmt);
externucharcodeLCD_WIDTH;
externucharcodeLCD_HEIGHT;
sbitS1=P1^0;
sbitS2=P1^1;
sbitS3=P1^2;
sbitS4=P1^3;
ucharcodeImageX[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
ucharCurrent_Operation=0;
ucharStatistics_Data[]={20,70,80,40,90,65,30};
voidDraw_Bar_Graph(uchard[])
{
uchari,h;
Line(4,2,4,100,1);
Line(4,100,158,100,1);
Line(4,2,1,10,1);
Line(4,2,7,10,1);
Line(158,100,152,97,1);
Line(158,100,152,103,1);
for(i=0;i〈7;i++)
{
h=100—d[i];
Line(10+i*20,h,10+i*20,100,1);
Line(10+i*20,h,10+i*20+15,h,1);
Line(10+i*20+15,h,10+i*20+15,100,1);
}
}
voidmain()
{
uchari,j,m,c=0;uintk,x;
LCD_Initialise();
Set_LCD_POS(0,0);
cls();
while
(1)
{
if(S1==0)Current_Operation=1;
if(S2==0)Current_Operation=2;
if(S3==0)Current_Operation=3;
if(S4==0)Current_Operation=4;
if(c==Current_Operation)gotodelayx;
c=Current_Operation;
switch(Current_Operation)
{
case1:
case2:
LCD_Write_Command_P2(LC_GRH_STP,0x00,0x00);
for(i=0;i{
Set_LCD_POS(i,0);
LCD_Write_Command(LC_AUT_WR);
for(j=0;j〈LCD_WIDTH;j++)
{
m=ImageX[i*LCD_WIDTH+j];
if(S2==0)m=~m;
LCD_Write_Data(m);
}
LCD_Write_Command(LC_AUT_OVR);
}
break;
case3:
k=0;
while(k!
=LCD_WIDTH*LCD_HEIGHT)
{
LCD_Write_Command_P2(LC_GRH_STP,k%256,k/256);
for(x=0;x〈5000;x++);
k+=LCD_WIDTH;
}
break;
case4:
LCD_Write_Command_P2(LC_GRH_STP,0x00,0x00);
Set_LCD_POS(0,0);
cls();
Draw_Bar_Graph(Statistics_Data);
Display_Str_at_xy(12,110,"statisticsGraph");
break;
}
delayx:
for(x=0;x〈20000;x++);
}
}
#include〈stdarg.h>
#include〈stdio.h>
#include〈math.h〉
#include
#includeh>
#include〈string。
h〉
#includeh〉
sbitRESET=P3^3;
#defineASC_CHR_WIDTH8
#defineASC_CHR_HEIGHT12
#defineHZ_CHR_HEIGHT12
#defineHZ_CHR_WIDTH12
ucharcodeLCD_WIDTH=20;
ucharcodeLCD_HEIGHT=128;
ucharcodeASC_MSK[96*12]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
uchargCurRow,gCurCol;
uchartCurRow,tCurCol;
ucharShowModeSW;
uinttxthome,grhome;
ucharStatus_BIT_01();
ucharStatus_BIT_3();
ucharGetCol();
ucharGetRow();
ucharLCD_Write_Command(ucharcmd);
ucharLCD_Write_Command_P1(ucharcmd,ucharpara1);
ucharLCD_Write_Command_P2(ucharcmd,ucharpara1,ucharpara2);
ucharLCD_Write_Data(uchardat);
ucharLCD_Read_Data();
voidcls();
ucharLCD_Initialise();
voidSet_LCD_POS(ucharrow,ucharcol);
voidcharout(uchar*str);
uchardprintf(ucharx,uchary,uchar*fmt);
voidOutToLCD(ucharDat,ucharx,uchary);
voidLine(ucharx1,uchary1,ucharx2,uchary2,bitMode);
voidPixel(ucharx,uchary,bitMode);
ucharStatus_BIT_01()
{
uchari;
for(i=5;i〉0;i——)
{
if((LCMCW&0x03)==0x03)
break;
}
returni;
}
ucharStatus_BIT_3()
{
uchari;
for(i=5;i〉0;i--)
{
if((LCMCW&0x08)==0x08)
break;
}
returni;
}
ucharLCD_Write_Command_P2(ucharcmd,ucharpara1,ucharpara2)
{
if(Status_BIT_01()==0)return1;
LCMDW=para1;
if(Status_BIT_01()==0)return2;
LCMDW=para2;
if(Status_BIT_01()==0)return3;
LCMDW=cmd;
return0;
}
ucharLCD_Write_Command_P1(ucharcmd,ucharpara1)
{
if(Status_BIT_01()==0)return1;
LCMDW=para1;
if(Status_BIT_01()==0)return2;
LCMDW=cmd;
return0;
}
ucharLCD_Write_Command(ucharcmd)
{
if(Status_BIT_01()==0)return1;
LCMDW=cmd;
return0;
}
ucharLCD_Write_Data(uchardat)
{
if(Status_BIT_3()==0)return1;
LCMDW=dat;
return0;
}
ucharLCD_Read_Data()
{
if(Status_BIT_01()==0)return1;
returnLCMDW;
}
voidSet_LCD_POS(ucharrow,ucharcol)
{
uintPos;
Pos=row*LCD_WIDTH+col;
LCD_Write_Command_P2(LC_ADD_POS,Pos%256,Pos/256);
gCurRow=row;
gCurCol=col;
}
voidcls()
{
uinti;
LCD_Write_Command_P2(LC_ADD_POS,0x00,0x00);
LCD_Write_Command(LC_AUT_WR);
for(i=0;i〈0x2000;i++)
{
Status_BIT_3();
LCD_Write_Data(0x00);
}
LCD_Write_Command(LC_AUT_OVR);
LCD_Write_Command_P2(LC_ADD_POS,0x00,0x00);
gCurRow=0;
gCurCol=0;
}
ucharLCD_Initialise()
{
RESET=0;
RESET=1;
LCD_Write_Command_P2(LC_TXT_STP,0x00,0x00);
LCD_Write_Command_P2(LC_TXT_WID,LCD_WIDTH,0x00);
LCD_Write_Command_P2(LC_GRH_STP,0x00,0x00);
LCD_Write_Command_P2(LC_GRH_WID,LCD_WIDTH,0x00);
LCD_Write_Command_P1(LC_CGR_POS,CGRAMSTART〉>11);
LCD_Write_Command(LC_CUR_SHP|0x01);
LCD_Write_Command(LC_MOD_OR);
LCD_Write_Command(LC_DIS_SW|0x08);
grhome=GRSTART;
txthome=TXTSTART;
return0;
}
ucharDisplay_Str_at_xy(ucharx,uchary,uchar*fmt)
{
charc1,c2,cData;
uchari=0,j,uLen;
uLen=strlen(fmt);
while(i〈uLen)
{
c1=fmt[i];
c2=fmt[i+1];
Set_LCD_POS(y,x/8);
if(c1〉=0)
{
if(c1<0x20)
{
switch(c1)
{
caseCR:
caseLF:
i++;
x=0;
if(y<112)y+=HZ_CHR_HEIGHT;
continue;
caseBS:
i++;
if(y〉ASC_CHR_WIDTH)y—=ASC_CHR_WIDTH;
cData=0x00;
break;
}
}
for(j=0;j〈ASC_CHR_HEIGHT;j++)
{
if(c1>=0x1f)
{
cData=ASC_MSK[(c1—0x1f)*ASC_CHR_HEIGHT+j];
Set_LCD_POS(y+j,x/8);
if((x%8)==0)
{
LCD_Write_Command(LC_AUT_WR);
LCD_Write_Data(cData);
LCD_Write_Command(LC_AUT_OVR);
}
else
OutToLCD(cData,x,y+j);
}
Set_LCD_POS(y+j,x/8);
}
if(c1!
=BS)x+=ASC_CHR_WIDTH;
}
i++;
}
returnuLen;
}
voidOutToLCD(ucharDat,ucharx,uchary)
{
uchardat1,dat2,a,b;
b=x%8;
a=8-b;
Set_LCD_POS(y,x/8);
LCD_Write_Command(LC_AUT_RD);
dat1=LCD_Read_Data();
dat2=LCD_Read_Data();
dat1=(dat1&(0xff〈dat2=(dat1&(0xff>〉b))|(Dat〈LCD_Write_Command(LC_AUT_OVR);
Set_LCD_POS(y,x/8);
LCD_Write_Command(LC_AUT_WR);
LCD_Write_Data(dat1);
LCD_Write_Data(dat2);
LCD_Write_Command(LC_AUT_OVR);
}
voidPixel(ucharx,uchary,bitMode)
{
ucharstart_addr,dat;
start_addr=7—(x%8);
dat=LC_BIT_OP|start_addr;
if(Mode)dat|=0x08;
Set_LCD_POS(y,x/8);
LCD_Write_Command(LC_BIT_OP|dat);
}
voidExchange(uchar*a,uchar*b)
{
uchart;
t=*a;*a=*b;*b=t;
}
voidLine(ucharx1,uchary1,ucharx2,uchary2,bitMode)
{
ucharx,y;
floatk,b;
if(abs(y1—y2)<=abs(x1-x2))
{
k=(float)(y1-y2)/(float)(x2-x1);
b=y1—k*x1;
if(x1〉x2)Exchange(&x1,&x2);
for(x=x1;x<=x2;x++)
{
y=(uchar)(k*x+b);
Pixel(x,y,Mode);
}
}
else
{
k=(float)(x2—x1)/(float)(y2—y1);
b=x1-k*y1;
if(y1〉y2)Exchange(&y1,&y2);
for(y=y1;y〈=y2;y++)
{
x=(uchar)(k*y+b);
Pixel(x,y,Mode);
}
}
}
#includeh>
#include〈intrins.h〉
#include〈stdarg。
h>
#include#include〈math。
h>
#include
#includeh>
#defineuintunsignedint
#defineucharunsignedchar
#defineSTX0x02
#defineETX0x03
#defineEOT0x04
#defineENQ0x05
#defineBS0x08
#defineCR0x0d
#defineLF0x0a
#defineDLE0x10
#defineETB0x17
#defineSPACE0x20
#defineCOMMA0x2c
#defineTRUE1
#defineFALSE0
#defineHIGH1
#defineLOW0
#defineLCMDWXBYTE[0x8000]
#defineLCMCWXBYTE[0x8100]
#defineDISRAM_SIZE0x7fff
#defineTXTSTART0x0000
#defineGRSTART0x6800
#defineCGRAMSTART0x7800
#defineLC_CUR_POS0x21
#defineLC_CGR_POS0x22
#defineLC_ADD_POS0x24
#defineLC_TXT_STP0x40
#defineLC_TXT_WID0x41
#defineLC_GRH_STP0x42
#defineLC_GRH_WID0x43
#defineLC_MOD_OR0x80
#defineLC_MOD_XOR0x81
#defineLC_MOD_AND0x82
#defineLC_MOD_TCH0x83
#defineLC_DIS_SW0x90
#defineLC_CUR_SHP0xa0
#defineLC_AUT_WR0xb0
#defineLC_AUT_RD0xb1
#defineLC_AUT_OVR0xb2
#defineLC_INC_WR0xc0
#defineLC_INC_RD0xc1
#defineLC_DEC_WR0xc2
#defineLC_DEC_RD0xc3
#defineLC_NOC_WR0xc4
#defineLC_NOC_RD0xc5
#defineLC_SCN_RD0xe0
#defineLC_INC_CP0xe8
#defineLC_BIT_OP0xf0