基于P89V51控制LCD显示屏
单片机源程序如下:
- #include "System.h"
- #include "STRING.h"
- #include "LCD.h"
- #include "I2C.h"
- #include "Relay_Parameter.h"
- #include "Display.h"
- uchar xdata xy1[19][2]={
- {21,30},{22,30},{21,56},{21,82},
- {21,108},{22,108},{23,108},{24,108},{25,108},
- {21,134},{22,134},{23,134},{24,134},{25,134},
- {14,75},{15,75},{16,75},{17,75},{18,75}
- };//光标坐标
- uchar xdata x,y;
- /****键盘控制LCD上的光标左移****/
- void Left_M(uchar JL_or_ceshi)//0为测试界面,1计量界面
- {
- uchar xdata i,a,b;
- if(JL_or_ceshi==1)
- {
- a=14;b=19;
- }
- else
- {
- if((Relay1.delay_type[0]-0x30)==3) {a=0;b=14;}
- else {a=0;b=9;}
- }
- for(i=a;i<b;i++)
- {
- if(x==xy1[i][0]&&y==xy1[i][1])
- {
- LcmClear_1();
- if(i!=a)
- {
- if(xy1[i][0]==21&&xy1[i][1]==82)
- {
- dprintf(xy1[i-1][0],xy1[i-1][1],StrForMixed10,0);
- dprintf(xy1[i-1][0]+1,xy1[i-1][1],StrForMixed10,0);
- dprintf(xy1[i-1][0]+2,xy1[i-1][1],StrForMixed10,0);
- dprintf(xy1[i-1][0]+3,xy1[i-1][1],StrForMixed10,0);
- dprintf(xy1[i-1][0]+4,xy1[i-1][1],StrForMixed10,0);
- dprintf(xy1[i-1][0]+5,xy1[i-1][1],StrForMixed10,0);
- }
- else
- {
- dprintf(xy1[i-1][0],xy1[i-1][1],StrForMixed10,0);
- }
- x=xy1[i-1][0];y=xy1[i-1][1];
- }
- else
- {
- dprintf(xy1[i][0],xy1[i][1],StrForMixed10,0);
- x=xy1[i][0];y=xy1[i][1];
- }
- break;
- }
- }
- }
- /****键盘控制LCD上的光标右移****/
- void Right_M(uchar JL_or_ceshi)//0测试界面,1计量界面
- {
- uchar xdata i,a,b;
- if(JL_or_ceshi==1)
- {
- a=14;b=19;
- }
- else
- {
- if((Relay1.delay_type[0]-0x30)==3) {a=0;b=14;}
- else {a=0;b=9;}
- }
- for(i=a;i<b;i++)
- {
- if(x==xy1[i][0]&&y==xy1[i][1])
- {
- LcmClear_1();
- if(i!=(b-1))
- {
- if(xy1[i][0]==22&&xy1[i][1]==30)
- {
- dprintf(xy1[i+1][0],xy1[i+1][1],StrForMixed10,0);
- dprintf(xy1[i+1][0]+1,xy1[i+1][1],StrForMixed10,0);
- dprintf(xy1[i+1][0]+2,xy1[i+1][1],StrForMixed10,0);
- dprintf(xy1[i+1][0]+3,xy1[i+1][1],StrForMixed10,0);
- dprintf(xy1[i+1][0]+4,xy1[i+1][1],StrForMixed10,0);
- dprintf(xy1[i+1][0]+5,xy1[i+1][1],StrForMixed10,0);
- }
- else
- {
- dprintf(xy1[i+1][0],xy1[i+1][1],StrForMixed10,0);
- }
- x=xy1[i+1][0];y=xy1[i+1][1];
- }
- else
- {
- dprintf(xy1[i][0],xy1[i][1],StrForMixed10,0);
- x=xy1[i][0];y=xy1[i][1];
- }
- break;
- }
- }
- }
- /****向上调LCD上的参数****/
- void Uchange_P(uchar *Ptr,uint t)
- {
- uchar xdata i,c1;
- if(Ptr==Relay1.chud_num)
- {
- for(i=0;i<13;i++) //13为触点类型种数
- {
- if(strcmp(Relay1.chud_num,Relay_CD_numbers[i])==0)
- {
- if(i==12) {strncpy(Relay1.chud_num,Relay_CD_numbers[0],7);}
- else {strncpy(Relay1.chud_num,Relay_CD_numbers[i+1],7);}
- switch(strlen(Relay1.chud_num))
- {
- case 2:
- dddprintf(21,56,Relay1.chud_num,2,1);
- dprintf(23,56,StrForMixed58,1);
- dprintf(25,56,StrForMixed58,1);
- break;
- case 4:
- dddprintf(21,56,Relay1.chud_num,4,1);
- dprintf(25,56,StrForMixed58,1);
- break;
- case 6:
- dddprintf(21,56,Relay1.chud_num,7,1);
- break;
- }
- break;
- }
- }
- }
- else if(Ptr==Relay1.delay_type)
- {
- for(i=0;i<7;i++)
- {
- if(strcmp(Relay1.delay_type,Relay_YS_Type[i])==0)
- {
- if(i==6) {strncpy(Relay1.delay_type,Relay_YS_Type[0],2);}
- else {strncpy(Relay1.delay_type,Relay_YS_Type[i+1],2);}
- dddprintf(21,82,Relay1.delay_type,2,1);
- break;
- }
- }
- }
- else
- {
- c1=Ptr[t];
- switch(c1)
- {
- case 0x39:
- if(Ptr==Relay1.number) {c1=0x2F;}
- else {c1=0x2D;}
- break;
- case 0x2E:
- c1=0x2F;
- break;
- default:
- break;
- }
- if(c1>=0x10)
- {
- WriteCommand(CspDirD);
- Locatexy(x,y,1);
- WriteCommand(mWrite);
- for(i=0;i<16;i++)
- WriteData(ASC_MSK[(c1-0x20+1)*16+i]);
- Ptr[t]=c1+1;
- }
- }
- }
- /*****向下调LCD上的参数****/
- void Dchange_P(uchar *Ptr,uint t)
- {
- uchar xdata i,c1;
- if(Ptr==Relay1.chud_num)
- {
- for(i=0;i<13;i++)
- {
- if(strcmp(Relay1.chud_num,Relay_CD_numbers[i])==0)
- {
- if(i==0) {strncpy(Relay1.chud_num,Relay_CD_numbers[12],7);}
- else {strncpy(Relay1.chud_num,Relay_CD_numbers[i-1],7);}
- switch(strlen(Relay1.chud_num))
- {
- case 2:
- dddprintf(21,56,Relay1.chud_num,2,1);
- dprintf(23,56,StrForMixed58,1);
- dprintf(25,56,StrForMixed58,1);
- break;
- case 4:
- dddprintf(21,56,Relay1.chud_num,4,1);
- dprintf(25,56,StrForMixed58,1);
- break;
- case 6:
- dddprintf(21,56,Relay1.chud_num,7,1);
- break;
- }
- break;
- }
- }
- }
- else if(Ptr==Relay1.delay_type)
- {
- for(i=0;i<7;i++)
- {
- if(strcmp(Relay1.delay_type,Relay_YS_Type[i])==0)
- {
- if(i==0) {strncpy(Relay1.delay_type,Relay_YS_Type[6],2);}
- else {strncpy(Relay1.delay_type,Relay_YS_Type[i-1],2);}
- dddprintf(21,82,Relay1.delay_type,2,1);
- break;
- }
- }
- }
- else
- {
- c1=Ptr[t];
- switch(c1)
- {
- case 0x30:
- if(Ptr==Relay1.number) {c1=0x3A;}
- else {c1=0x2F;}
- break;
- case 0x2E:
- c1=0x3A;
- break;
- default:
- break;
- }
- if(c1>=0x10)
- {
- uint xdata j;
- WriteCommand(CspDirD);
- Locatexy(x,y,1);
- WriteCommand(mWrite);
- for(j=0;j<16;j++)
- WriteData(ASC_MSK[(c1-0x20-1)*16+j]);
- Ptr[t]=c1-1;
- }
- }
- }
- /****移动光标,调大LCD上的参数****/
- void SheZP1()
- {
- if(x==21&&y==30) Uchange_P(Relay1.number,0);
- if(x==22&&y==30) Uchange_P(Relay1.number,1);
- if(x==21&&y==56) Uchange_P(Relay1.chud_num,0);
- if(x==21&&y==82) Uchange_P(Relay1.delay_type,0);
-
- if(x==21&&y==108) Uchange_P(Relay1.time1,0);
- if(x==22&&y==108) Uchange_P(Relay1.time1,1);
- if(x==23&&y==108) Uchange_P(Relay1.time1,2);
- if(x==24&&y==108) Uchange_P(Relay1.time1,3);
- if(x==25&&y==108) Uchange_P(Relay1.time1,4);
-
- if(x==21&&y==134) Uchange_P(Relay1.time2,0);
- if(x==22&&y==134) Uchange_P(Relay1.time2,1);
- if(x==23&&y==134) Uchange_P(Relay1.time2,2);
- if(x==24&&y==134) Uchange_P(Relay1.time2,3);
- if(x==25&&y==134) Uchange_P(Relay1.time2,4);
-
- if(x==14&&y==75) Uchange_P(JL_Time,0);
- if(x==15&&y==75) Uchange_P(JL_Time,1);
- if(x==16&&y==75) Uchange_P(JL_Time,2);
- if(x==17&&y==75) Uchange_P(JL_Time,3);
- if(x==18&&y==75) Uchange_P(JL_Time,4);
- }
- /****移动光标,调小LCD上的参数****/
- void SheZP2()
- {
- if(x==21&&y==30) Dchange_P(Relay1.number,0);
- if(x==22&&y==30) Dchange_P(Relay1.number,1);
- if(x==21&&y==56) Dchange_P(Relay1.chud_num,0);
- if(x==21&&y==82) Dchange_P(Relay1.delay_type,0);
-
- if(x==21&&y==108) Dchange_P(Relay1.time1,0);
- if(x==22&&y==108) Dchange_P(Relay1.time1,1);
- if(x==23&&y==108) Dchange_P(Relay1.time1,2);
- if(x==24&&y==108) Dchange_P(Relay1.time1,3);
- if(x==25&&y==108) Dchange_P(Relay1.time1,4);
-
-
- if(x==21&&y==134) Dchange_P(Relay1.time2,0);
- if(x==22&&y==134) Dchange_P(Relay1.time2,1);
- if(x==23&&y==134) Dchange_P(Relay1.time2,2);
- if(x==24&&y==134) Dchange_P(Relay1.time2,3);
- if(x==25&&y==134) Dchange_P(Relay1.time2,4);
-
- if(x==14&&y==75) Dchange_P(JL_Time,0);
- if(x==15&&y==75) Dchange_P(JL_Time,1);
- if(x==16&&y==75) Dchange_P(JL_Time,2);
- if(x==17&&y==75) Dchange_P(JL_Time,3);
- if(x==18&&y==75) Dchange_P(JL_Time,4);
- }
- /****判断输入的延时形式是否为3,从而决定是否出现“延时时间T2“****/
- void Second_PD()
- {
- if((Relay1.delay_type[0]-0x30)==3)
- {
- switch(strlen(Relay1.chud_num))
- {
- case 2:
- dddprintf(21,56,Relay1.chud_num,2,1);
- dprintf(23,56,StrForMixed58,1);
- dprintf(25,56,StrForMixed58,1);
- break;
- case 4:
- dddprintf(21,56,Relay1.chud_num,4,1);
- dprintf(25,56,StrForMixed58,1);
- break;
- case 6:
- dddprintf(21,56,Relay1.chud_num,7,1);
- break;
- }
-
- //dddprintf(21,56,Relay1.chud_num,7,1);
- dddprintf(21,82,Relay1.delay_type,2,1);
- dddprintf(21,108,Relay1.time1,5,1);
- dprintf(15,108,StrForMixed181,1);
- dprintf(7,134,StrForMixed18,1);
- dprintf(15,134,StrForMixed182,1);
- dddprintf(21,134,Relay1.time2,5,1);
- dprintf(26,134,StrForMixed20,1);
- }
- else
- {
- switch(strlen(Relay1.chud_num))
- {
- case 2:
- dddprintf(21,56,Relay1.chud_num,2,1);
- dprintf(23,56,StrForMixed58,1);
- dprintf(25,56,StrForMixed58,1);
- break;
- case 4:
- dddprintf(21,56,Relay1.chud_num,4,1);
- dprintf(25,56,StrForMixed58,1);
- break;
- case 6:
- dddprintf(21,56,Relay1.chud_num,7,1);
- break;
- }
- //dddprintf(21,56,Relay1.chud_num,7,1);
- dddprintf(21,82,Relay1.delay_type,2,1);
- dddprintf(21,108,Relay1.time1,5,1);
- }
- }
- /****根据输入的产品编号,得到其在EEPROM中存储的位置,
- 并判断该位置上是否存有继电器参数,如果有更新相应的LCD显示****/
- void number_just()
- {
- uchar xdata t,t1;
- uchar xdata ADL,ADH;
- uchar xdata BianH[2];
- t=10*(Relay1.number[0]-0x30)+(Relay1.number[1]-0x30);
- ADL=(t*32)%256;
- ADH=(t*32)/256;
- RW_EEPROM(0,ADH,ADL,BianH,2);
- if(BianH[0]!=0x00&&BianH[1]!=0x00)
- {
- t1=10*(BianH[0]-0x30)+(BianH[1]-0x30);
- if(t1==t)
- {
- RW_EEPROM(0,ADH,ADL,Relay1.number,RelayBits);
- Second_PD();
- RW_EEPROM(1,0x1F,0xE0,Relay1.number,RelayBits);
- }
- }
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
Display.zip
(2.7 KB, 下载次数: 9)
|