功能:1.可以显示双方的分数,具有一分、二分、三分三种按键2.采用数码显示器显示。
3.可选择实现:统计该局各得分情况(三分球多少个,等等)
4.能够显示年月日。
程序:
- #include<reg52.h>
- #define ucharunsigned char
- #define uintunsigned int
- char yue,ri;
- int nian;
- sbit RS=P2^7;
- sbit E=P2^5;
- sbit K8=P3^5;sbitK1=P3^2;
- sbit K2=P3^3;
- sbit K3=P3^7;
- sbit K4=P3^6;
- sbit K5=P3^1;
- sbit K6=P3^0;
- sbit K7=P3^4;
- sbitbeep=P2^0;
- uchar bb,cc;
- uchar codetable1[]={"H.T 000:000 R.T "};
- uchar codetable2[]="2018-12-13";
- void delay(uintz)
- {
- uint x;
- uchar y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- voidwrite_com(uchar com)
- {
- RS=0;
- P0=com;
- delay(5);
- E=1;
- delay(5);
- E=0;
- }
- voidwrite_date(uchar date)
- {
- RS=1;
- P0=date;
- delay(5);
- E=1;
- delay(5);
- E=0;
- }
- void write_yr(ucharadd,uchar data)
- {
- uchar shi,ge;
- shi=data/10;
- ge=data%10;
- write_com(0x80+add);
- write_data(0x30+shi);
- write_data(0x30+ge);
- }
- void write_nian(ucharadd,uint dat)
- {
- uint qian,bai,shi,ge;
- qian=dat/1000;
- bai=dat%1000/100;
- shi=dat%100/10;
- ge=dat%10;
- write_com(0x80+add);
- write_data(0x30+qian);
- write_data(0x30+bai);
- write_data(0x30+shi);
- write_data(0x30+ge);
- }
- voidLCD1602_init()
- {
- uchar i;
- bb=0;
- cc=0; ˉ
- TMOD=0x10;
- TL1=0x00;
- TH1=0x4c;
- EA=1;
- ET1=1;
- TR1=0;
- EX0=1;
- EX1=1;
- IT0=1;
- IT1=1;
- E=0;
- beep=0;
- nian=2018;
- yue=12;
- ri=13;
- write_com(0x38);
- write_com(0x0c);
- write_com(0x06);
- write_com(0x01);
- write_com(0x80);
- for(i=0;i<16;i++)
- {
- write_date(table1);
- }
- write_com(0x80+0x40);
- for(i=0;i<16;i++)
- {
- write_date(table2);
- }
- }
- //·Öêy¸üDÂ×óoˉêy
- voidpoint_lcd(uchar add,uchar dat)
- {
- write_com(0x80+add);
- write_date(0x30+dat/100);
- write_date(0x30+(dat%100)/10);
- write_date(0x30+dat%10);
- write_com(0x80+add);
- }
- //°′¼üé¨Ãè×óoˉêy
- void keyscan()
- {
- if(K3==0)
- {
- while(K3==0);
- bb++;
- point_lcd(0x04,bb);
- if(K3==0)
- {
- while(K3==0);
- delay(20);
- }
- }
- else if(K4==0)
- {
- while(K4==0);
- bb=bb+2;
- point_lcd(0x04,bb);
- if(K4==0)
- {
- while(K4==0);
- delay(20);
- }
- }
- else if(K7==0)
- {
- while(K7==0);
- bb=bb+3;
- point_lcd(0x04,bb);
- if(K7==0)
- {
- while(K7==0);
- delay(20);
- }
- }
- else if(K5==0)
- {
- while(K5==0);
- cc++;
- point_lcd(0x08,cc);
- if(K5==0)
- {
- while(K5==0);
- delay(20);
- }
- }
- else if(K6==0)
- {
- while(K6==0);
- cc=cc+2;
- point_lcd(0x08,cc);
- if(K6==0)
- {
- while(K6==0);
- delay(20);
- }
- }
- else if(K8==0)
- {
- while(K8==0);
- cc=cc+3;
- point_lcd(0x08,cc);
- if(K8==0)
- {
- while(K8==0);
- delay(20);
- }
- }
- }
- //Ö÷oˉêy
- void main()
- {
- LCD1602_init();
- while(1)
- {
- keyscan();
- }
- }
复制代码
|