1、篮球比赛计时器24S倒时proteus原理图:字模取模方式:源程序:#include#define uchar unsigned char#define uint unsigned int#define port P0 /DB0DB7数据口sbit e=P26;/使能sbit rw=P25;/读写sbit rs=P24;/数据/命令sbit cs2=P22;/片选sbit cs1=P21;sbit busy=P07;/检测忙sbit b1=P10; sbit b2=P11;sbit b3=P14;uchar fuhao; uchar i;uchar k1=0;uchar k2=0;uchar
2、j1=0;uchar j2=0;uchar k3=9;uchar k4=3;uchar k5=2;uchar count,hour,minute,second;uchar time6;uchar code hz32=/*- 文字: 湖 -*/*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/0x10,0x21,0x86,0x60,0x90,0x90,0xFF,0x90,0x90,0x00,0xFE,0x92,0x92,0xFE,0x00,0x00,0x04,0xFC,0x03,0x00,0x1F,0x10,0x10,0x90,0x5F,0x30,0x0F,0x40,0x80,0
3、x7F,0x00,0x00,/*- 文字: 人 -*/*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x3F,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x01,0x06,0x0C,0x18,0x30,0x60,0x20,0x00,/*- 文字: : -*/*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/0x00,0x00,0x00,0x00,0x00,0x00,0x00
4、,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*- 文字: 热 -*/*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/0x44,0xC4,0x44,0xFF,0x24,0x04,0x14,0xA4,0x7F,0xC4,0x84,0x7C,0x84,0x00,0x00,0x00,0xC0,0x62,0x34,0x03,0x14,0x62,0x01,0x08,0x30,0x6
5、0,0x01,0x08,0x33,0x64,0x07,0x00,/*- 文字: 火 -*/*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0xFF,0x02,0x40,0x20,0x18,0x10,0x00,0x00,0x00,0x00,0x80,0x41,0x20,0x10,0x0C,0x03,0x00,0x03,0x04,0x18,0x30,0x60,0x20,0x00,0x00,/*- 文字: 光 -*/*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/0x00,0x40,0x42,0
6、x44,0x5C,0xC8,0x40,0x7F,0x40,0xC0,0x50,0x4E,0x44,0x60,0x40,0x00,0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00,/*- 文字: 一 -*/*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
7、0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*- 文字: 张 -*/*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/0x02,0xF2,0x12,0x12,0x1E,0x00,0x80,0x80,0xFF,0xA0,0x90,0x88,0x86,0x84,0x80,0x00,0x01,0x03,0x41,0x81,0x7F,0x00,0x00,0x40,0xFF,0x40,0x23,0x0C,0x10,0x60,0x20,0x00,/*- 文字: 三 -*/*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -
8、*/0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,/*- 文字: 三 -*/*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,0x00,0x20,0x
9、20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,/*- 文字: 三 -*/*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,/*- 文字: 一 -*/*- 宋体12; 此字体下
10、对应的点阵为:宽x高=16x16 -*/0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,;uchar code sz16=0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/0,00x00,0x10,0x10,0xF8
11、,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/1,10x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/2,20x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,/3,30x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x
12、3F,0x24,0x00,/4,40x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,/5,50x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,/6,60x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,/7,70x00,0x70,0x88,0x08,0x08,0x88,0
13、x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/8,80x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00, /9,90x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,/:,10;/延时子程序void delay(uint n) uint i; for(;n0;n-) for(i=200;i0;i-);void delay1(ui
14、nt i ) while(i-);/判断是否忙子程序void check() rs=0; rw=1; /读 e=1; port=0x00; e=1; while(busy); e=0;/写指令子程序void sendcommand(uchar command) check(); rs=0; /指令 rw=0; /写 e=0; port=command; e=1; /下降沿,启动发送指令 e=0; /写入指令/写数据子程序void writedata(uchar dat) check(); rs=1; /数据 rw=0; port=dat; e=1; /下降沿,启动写数据 e=0;/选屏子程序/
15、选屏幕 0全屏,1左屏,2右屏;void select(uint n) switch(n) case 0:cs1=0;cs2=0;break; /低电平选中 case 1:cs1=0;cs2=1;break; /cs1左屏 case 2:cs1=1;cs2=0;break; /cs2右屏 /设置显示页码子程序void setpage(uchar page) page=page&0x07; /以下两句获取页地址 page=page|0xb8; sendcommand(page); /将页地址进行发送/设置列选择子程序void setcolumn(uchar column) column=colu
16、mn&0x3f; /以下两句获取列地址 column=column|0x40; sendcommand(column); /将列地址进行发送/起始行void setline(uchar line) line=line&0x3f; /以下两句获取行地址 line=line|0xc0; sendcommand(line); /将行地址进行发送/屏幕开关显示 0关,1开;void seton(uint n) n=n|0x3e; sendcommand(n);/清屏 0全屏,1左屏,2右屏;void clear(uint n) uchar i,j; select(n); for(i=0;i8;i+)
17、setpage(i); setcolumn(0); for(j=0;j64;j+) writedata(0); /置0清空 /初始化void init() check(); seton(1); clear(0); setline(0);/显示汉字 16*16显示,设置汉字从第几页,第几行开始显示void show16(uchar page,uchar column,uchar screen,uchar *str) uchar i,j; select(screen); j=0; setpage(page); setcolumn(column); for(i=0;i16;i+) writedata
18、(strj+); setpage(page+1); setcolumn(column); for(i=0;i16;i+) writedata(strj+); /显示数字 8*8显示void show8(uchar page,uchar column,uchar screen,uchar *str) uchar i,j; select(screen); j=0; setpage(page); setcolumn(column); for(i=0;i8;i+) writedata(strj+); setpage(page+1); setcolumn(column); for(i=0;i8;i+)
19、writedata(strj+); void INC1() if(b1=0) delay(100); k1+; if(k1=10) k1=0; k2+; ; if(b3=0) delay(100); j1+; if(j1=10) j1=0; j2+; ;void subb()if(b2=0) delay(1); k3-; if(k3=0) k3=9; k4-; k3-; if(k4=0) k4=9; k5-; k4-; k3-; if(k5=0&k4=0&k3=0) k3=9; k4=3; k5=2; else if(b2=1) k3=9; k4=3; k5=2; void welcome()
20、 /显示第一行 show16(0,0,1,hz0); show16(0,16,1,hz1); show16(0,48,1,hz2); show16(0,0,2,hz3); show16(0,16,2,hz4); show16(6,0,1,hz5); show16(6,16,1,hz6); show16(6,48,1,hz7); show16(6,0,2,hz8); show16(6,16,2,hz9); show16(6,32,2,hz10); show16(6,48,2,hz11); show8(2,0,1,szk2); show8(2,16,1,szk1); show8(2,0,2,szj
21、2); show8(2,16,2,szj1);show8(4,0,1,szk5); show8(4,8,1,szk4); show8(4,16,1,sz10); show8(4,24,1,szk3); /*比赛时间显示控制部分*/初始化程序 void inite() TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; count=20; second=59; minute=11; hour=00; void timer() interrupt 1 /中断函数 TH0=(65536-50000)
22、/256; /给T0赋初值 TL0=(65536-50000)%256; count-; if(count=00) /时间达到一秒钟 count=20; second-; if(second=00) second=60; minute-; if(minute=00) minute=12; hour-; if(hour=00) hour=00; void showtime (void) time0=hour/10; time1=hour%10; time2=minute/10; time3=minute%10; time4=second/10; time5=second%10; show8(4,0,2,sztime0); show8(4,8,2,sztime1); show8(4,16,2,sz10); show8(4,24,2,sztime2); show8(4,32,2,sztime3); show8(4,40,2,sz10); show8(4,48,2,sztime4); show8(4,56,2,sztime5);/*主函数*/void main() init(); inite(); delay(200); /welcome(); while(1) INC1();subb(); welcome(); showtime();
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1