计数器程序

  • 格式:doc
  • 大小:47.50 KB
  • 文档页数:18

计数器C程序#include<reg52.h>#define uint unsigned int#define uchar unsigned charuchar code table[]="E-Counter";uchar code table1[]="By Liu Qimeng";uchar temp,num;uchar numa,numb,numc,numd,nume,numf,numg,total; sbit lcden=P3^4;sbit lcdrs=P3^5;void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void write_com(uchar com){lcdrs=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}void write_data(uchar date) {lcdrs=1;P0=date;delay(5);lcden=1;delay(5);lcden=0;}void init(){lcden=0;write_com(0x38);write_com(0x00);write_com(0x06);write_com(0x01);//显示清屏for(num=0;num<9;num++) {write_com(0x80+0x03);delay(5);write_data(table[num]);delay(5);}write_com(0x80+0x41);delay(5);for(num=0;num<13;num++) {write_data(table1[num]);delay(5);}delay(200);delay(200);delay(200);write_com(0x01);//显示清屏delay(5);write_com(0x80);write_data('A');delay(5);write_com(0x80+0x04); delay(5);write_data('B');delay(5);write_com(0x80+0x08); delay(5);write_data('C');delay(5);write_com(0x80+0x12); delay(5);write_data('D');delay(5);write_com(0x80+0x40); delay(5);write_data('E');delay(5);write_com(0x80+0x44); delay(5);write_data('F');write_com(0x80+0x48);delay(5);write_data('G');delay(5);write_com(0x80+0x52);delay(5);write_data(0xD4);delay(5);}void init2(){write_com(0x01);//显示清屏delay(5);write_com(0x80);delay(5);write_data('A');delay(5);write_com(0x80+0x04);delay(5);write_data('B');write_com(0x80+0x08); delay(5);write_data('C');delay(5);write_com(0x80+0x12); delay(5);write_data('D');delay(5);write_com(0x80+0x40); delay(5);write_data('E');delay(5);write_com(0x80+0x44); delay(5);write_data('F');delay(5);write_com(0x80+0x48); delay(5);write_data('G');delay(5);write_com(0x80+0x52);delay(5);write_data(0xD4);delay(5);}///矩阵键盘函数/////////////////////////////////////////////////////////////////////////////// void keyscan(){uchar temp;P3=0xfe;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){temp=P3;switch(temp){total++;write_com(0x80+0x01);delay(5);write_data(numa);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;case 0xde:numb++;total++;write_com(0x80+0x05);delay(5);write_data(numa);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;total++;write_com(0x80+0x09);delay(5);write_data(numc);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;case 0x7e:numd++;total++;write_com(0x80+0x13);delay(5);write_data(numd);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}P3=0xfd;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){temp=P3;switch(temp){total--;write_com(0x80+0x01);delay(5);write_data(numa);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;case 0xdd:numb--;total--;write_com(0x80+0x05);delay(5);write_data(numa);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;total--;write_com(0x80+0x09);delay(5);write_data(numc);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;case 0x7d:numd--;total--;write_com(0x80+0x13);delay(5);write_data(numd);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}P3=0xfb;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){temp=P3;switch(temp)case 0xeb:nume++;total++;write_com(0x80+0x41);delay(5);write_data(nume);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;case 0xdb:numf++;total++;write_com(0x80+0x45);delay(5);write_data(numf);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;case 0xbb:numg++;total++;write_com(0x80+0x49);delay(5);write_data(numg);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;case 0x7b:init();break;}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}P3=0xf7;temp=P3;temp=temp&0xf0;while(temp!=0xf0){delay(5);temp=P3;temp=temp&0xf0;while(temp!=0xf0){temp=P3;switch(temp){case 0xe7:nume--;total--;write_com(0x80+0x41);delay(5);write_data(nume);delay(5);write_com(0x80+0x53);write_data(total);delay(5);break;case 0xd7:numf--;total--;write_com(0x80+0x45);delay(5);write_data(numf);delay(5);write_com(0x80+0x53);delay(5);write_data(total);delay(5);break;case 0xb7:numg--;total--;write_com(0x80+0x49);delay(5);write_data(numg);delay(5);write_com(0x80+0x53);write_data(total);delay(5);break;case 0x77:init2();break;}while(temp!=0xf0){temp=P3;temp=temp&0xf0;}}}}。