#include<reg52.h> #include"LCD_driver.h" unsigned char kp,ti,td; unsigned char rx=102; //2V int y,y1,u; int e0,e1,ei; unsigned int ts; int ri[8]={0,0,0,0,0,0,0,0}; uchar sitx; uchar nump=0,numi=0,numd=0; uchar numsit,numc[9],cnt=0; uchar keyv; void dis8(uchar x, uchar sitx ) { LCD_KeilDrawLine(20+sitx, 200, 27+sitx, 200); LCD_KeilDrawLine(20+sitx, 210, 27+sitx, 210); LCD_KeilDrawLine(20+sitx, 220, 27+sitx, 220); LCD_KeilDrawLine(20+sitx, 200, 20+sitx, 210); LCD_KeilDrawLine(20+sitx, 210, 20+sitx, 220); LCD_KeilDrawLine(27+sitx, 200, 27+sitx, 210); LCD_KeilDrawLine(27+sitx, 210, 27+sitx, 220); if (x==2||x==3||x==5||x==6||x==8||x==0) LCD_DrawLine(20+sitx, 200, 27+sitx, 200); if (x==2||x==3||x==4||x==5||x==6||x==8) LCD_DrawLine(20+sitx, 210, 27+sitx, 210); if (x==2||x==3||x==5||x==6||x==7||x==8||x==0) LCD_DrawLine(20+sitx, 220, 27+sitx, 220); if (x==2||x==6||x==8||x==0) LCD_DrawLine(20+sitx, 200, 20+sitx, 210); if (x==4||x==5||x==6||x==8||x==9||x==0) LCD_DrawLine(20+sitx, 210, 20+sitx, 220); if (x==1||x==3||x==4||x==5||x==6||x==7||x==8||x==9||x==0) LCD_DrawLine(27+sitx, 200, 27+sitx, 210); if (x==1||x==2||x==3||x==7||x==8||x==9||x==0) LCD_DrawLine(27+sitx, 210, 27+sitx, 220); } uchar keyscan() { uchar hsm, ljc, keyvalue; P1=0xf0; // | 1111 - 0000 ljc=P1&0xf0; if(ljc!=0xf0) { delayms(10); ljc=P1&0xf0; if(ljc!=0xf0) { hsm=0xfe; while((hsm&0x10)!=0) { P1=hsm; ljc=P1&0xf0; if(ljc!=0xf0) { keyvalue=(~hsm)+((~(ljc|0x0f))); return(keyvalue); } else hsm=(hsm<<1)|0x01; } } } return(0x00); } void main() { LCD_Init(); Pant(colors[4]>>8 , colors[4]); LCD_CS =0; LCD_DrawLine(10, 10, 310, 10); LCD_DrawLine(10, 10, 10, 230); LCD_DrawLine(10, 230, 310, 230); LCD_DrawLine(310, 10, 310, 230); u=0; ei=0; y=0; y1=0; ts=10; // kp=7;ti=12;td=6; while(cnt!=10) { delayms(100); if(keyscan()!=0x00 ) { keyv=keyscan(); switch(keyv) { case 0x11: if (cnt==2) {cnt=0; } if (cnt==5) {cnt=3; } if (cnt==8) {cnt=6; } else {numc[cnt]=1;cnt++; } break; case 0x21: if (cnt==2) {cnt=0; } if (cnt==5) {cnt=3; } if (cnt==8) {cnt=6; } else {numc[cnt]=2; cnt++;} break; case 0x41: if (cnt==2) {cnt=0 ;} if (cnt==5) {cnt=3; } if (cnt==8) {cnt=6; } else {numc[cnt]=3;cnt++; } break; case 0x81: if (cnt==2) {cnt=0; } if (cnt==5) {cnt=3; } if (cnt==8) {cnt=6; } else {numc[cnt]=4; cnt++; } break; case 0x12: if (cnt==2) {cnt=0; } if (cnt==5) {cnt=3; } if (cnt==8) {cnt=6; } else {numc[cnt]=5;cnt++; } break; case 0x22: if (cnt==2) {cnt=0; } if (cnt==5) {cnt=3; } if (cnt==8) {cnt=6; } else {numc[cnt]=6; cnt++;} break; case 0x42: if (cnt==2) {cnt=0; } if (cnt==5) {cnt=3; } if (cnt==8) {cnt=6; } else {numc[cnt]=7; cnt++; } break; case 0x82: if (cnt==2) {cnt=0; } if (cnt==5) {cnt=3; } if (cnt==8) {cnt=6; } else {numc[cnt]=8; cnt++;} break; case 0x14: if (cnt==2) {cnt=0; } if (cnt==5) {cnt=3; } if (cnt==8) {cnt=6; } else {numc[cnt]=9;cnt++; } break; case 0x24: if (cnt==2) {cnt=0; } if (cnt==5) {cnt=3; } if (cnt==8) {cnt=6; } else {numc[cnt]=0; cnt++;} break; case 0x84: cnt=9; break; case 0x18: cnt=0; break; case 0x28: cnt=3; break; case 0x48: cnt=6; break; case 0x88: cnt=10; } nump=numc[0]*10+numc[1]; numi=numc[3]*10+numc[4]; numd=numc[6]*10+numc[7]; dis8(numc[0],0) ; dis8(numc[1],10); dis8(numc[3],30); dis8(numc[4],40); dis8(numc[6],60); dis8(numc[7],70); kp=nump; ti=numi; td=numd; } } while (cnt==10) { e0=rx-y; ei=ei+e0; u=0.18*kp*(e0+ei/ti+td*(e0-e1)/4); // if (u>230) u=230; e1=e0; ri[0]=ri[1]; ri[1]=ri[2]; ri[2]=ri[3]; ri[3]=ri[4]; ri[4]=ri[5]; ri[5]=ri[6]; ri[6]=ri[7]; ri[7]=u; y=0.9*y1+0.1*ri[0]; LCD_DrawLine(ts-4,y1+10 , ts,y+10); y1=y; LCD_DrawPoint(112,ts); // LCD_DrawPoint(y+10,ts); //LCD_DrawPoint(u,ts); if(ts<=306) ts=ts+4; delayms(50); } } |