给大家分享一个基于stc15f2k60s2单片机的电子记分牌的制作资料
前几天帮他们写了个记分牌的程序,效果不错。贴出来,需要的拿走。
用了12864串行显示,四段数码管显示
红外遥控器控制
照片。。。弄丢了。。。
单片机源程序如下:
- #include "delay.h"
- #include "GPIO.h"
- #include "Exti.h"
- #include "timer.h"
- #include "lcd12864.h"
- #include "key.h"
- sbit leda=P3^4;
- sbit ledb=P3^3;
- extern unsigned char IrValue[6];
- extern uchar ascore;
- extern uchar bscore;
- extern uchar going_flag=0;
- extern uchar game_time=0;
- extern uchar lcd_flag=0;
- extern uchar teamname=0;
- extern uchar gametime=0;
- extern uchar change_flag=0;
- extern uchar gameover_flag=0;
- extern uchar name[2][4]={' ',' ',' ',' ',' ',' ',' ',' '};
- extern uchar count_down[6]={'0','0','0','0','0','0'};
- extern uchar shuma_numb[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- uchar shuma[4]={0,0,0,0};
- u8 code awin[]={" 甲队 "};
- u8 code bwin[]={" 乙队 "};
- u8 code draw[]={" 平局 "};
- void lcd_show_time()
- {
- uchar k=0;
- lcd_pos(2,2); //设置显示位置为第四行的第一个字符
- while(k<2)
- {
- write_dat(count_down[k]); //显示字符
- k++;
- }
- write_dat(58);
- lcd_pos(2,4); //设置显示位置为第四行的第一个字符
- while(k<4)
- {
- write_dat(count_down[k]); //显示字符
- k++;
- }
- write_dat(58);
- lcd_pos(2,6); //设置显示位置为第四行的第一个字符
- while(k<6)
- {
- write_dat(count_down[k]); //显示字符
- k++;
- }
- }
- void lcd_show_name(uchar u1,uchar u2,uchar u3,uchar u4)
- {
- uchar k=0;
- lcd_pos(u1,u2); //设置显示位置为第四行的第一个字符
- k = 0;
- while(k<4)
- {
- write_dat(name[0][k]); //显示字符
- k++;
- }
- lcd_pos(u3,u4); //设置显示位置为第四行的第一个字符
- k = 0;
- while(k<4)
- {
- write_dat(name[1][k]); //显示字符
- k++;
- }
- }
- void EXTI_config(void)
- {
- EXTI_InitTypeDef EXTI_InitStructure; //结构定义
- EXTI_InitStructure.EXTI_Mode = EXT_MODE_RiseFall; //中断模式, EXT_MODE_RiseFall, EXT_MODE_Fall
- EXTI_InitStructure.EXTI_Polity = PolityHigh; //中断优先级, PolityLow,PolityHigh
- EXTI_InitStructure.EXTI_Interrupt = ENABLE; //中断允许, ENABLE或DISABLE
- Ext_Inilize(EXT_INT0,&EXTI_InitStructure); //初始化INT0 EXT_INT0,EXT_INT1,EXT_INT2,EXT_INT3,EXT_INT4
- }
- void Timer_config(void)
- {
- TIM_InitTypeDef TIM_InitStructure; //????
- TIM_InitStructure.TIM_Mode = TIM_16BitAutoReload; //??????, TIM_16BitAutoReload,TIM_16Bit,TIM_8BitAutoReload,TIM_16BitAutoReloadNoMask
- TIM_InitStructure.TIM_Polity = PolityHigh; //???????, PolityHigh,PolityLow
- TIM_InitStructure.TIM_Interrupt = ENABLE; //??????, ENABLE?DISABLE
- TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_12T; //?????, TIM_CLOCK_1T,TIM_CLOCK_12T,TIM_CLOCK_Ext
- TIM_InitStructure.TIM_ClkOut = DISABLE; //????????, ENABLE?DISABLE
- TIM_InitStructure.TIM_Value = 19200;
- TIM_InitStructure.TIM_Run = ENABLE; //???????????, ENABLE?DISABLE
- Timer_Inilize(Timer0,&TIM_InitStructure); //???Timer0 Timer0,Timer1,Timer2
-
- TIM_InitStructure.TIM_Mode = TIM_16BitAutoReload; //??????, TIM_16BitAutoReload,TIM_16Bit,TIM_8BitAutoReload,TIM_16BitAutoReloadNoMask
- TIM_InitStructure.TIM_Polity = PolityLow; //???????, PolityHigh,PolityLow
- TIM_InitStructure.TIM_Interrupt = ENABLE; //??????, ENABLE?DISABLE
- TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_12T; //?????, TIM_CLOCK_1T,TIM_CLOCK_12T,TIM_CLOCK_Ext
- TIM_InitStructure.TIM_ClkOut = DISABLE; //????????, ENABLE?DISABLE
- TIM_InitStructure.TIM_Value = (65535-5*100);
- TIM_InitStructure.TIM_Run = ENABLE; //???????????, ENABLE?DISABLE
- Timer_Inilize(Timer1,&TIM_InitStructure); //???Timer0 Timer0,Timer1,Timer2
- }
- void main()
- {
- uchar i,j;
- beep=1;
- EXTI_config();
- Timer_config();
- EA=1;
- while(1)
- {
- lcd12864name();
- i=0;
- j=0;
- while(teamname==0)
- {
- if(IrValue[2]==menu)
- {
- IrValue[2]=0x00;
- i++;
- if(i==4)
- {
- i=0;
- j++;
- if(j>1)
- teamname=1;
- }
- }
- else if(IrValue[2]==key2)
- {
- IrValue[2]=0x00;
- if(name[j][i]=='C')
- name[j][i]='A';
- else if(name[j][i]=='B')
- name[j][i]='C';
- else if(name[j][i]=='A')
- name[j][i]='B';
- else name[j][i]=65;
- }
- else if(IrValue[2]==key3)
- {
- IrValue[2]=0x00;
- if(name[j][i]=='E')
- name[j][i]='D';
- else if(name[j][i]=='E')
- name[j][i]='F';
- else if(name[j][i]=='D')
- name[j][i]='E';
- else name[j][i]='D';
- }
- else if(IrValue[2]==key4)
- {
- IrValue[2]=0x00;
- if(name[j][i]=='I')
- name[j][i]='G';
- else if(name[j][i]=='H')
- name[j][i]='I';
- else if(name[j][i]=='G')
- name[j][i]='H';
- else name[j][i]='G';
- }
- else if(IrValue[2]==key5)
- {
- IrValue[2]=0x00;
- if(name[j][i]=='L')
- name[j][i]='J';
- else if(name[j][i]=='K')
- name[j][i]='L';
- else if(name[j][i]=='J')
- name[j][i]='K';
- else name[j][i]='J';
- }
- else if(IrValue[2]==key6)
- {
- IrValue[2]=0x00;
- if(name[j][i]=='O')
- name[j][i]='M';
- else if(name[j][i]=='N')
- name[j][i]='O';
- else if(name[j][i]=='M')
- name[j][i]='N';
- else name[j][i]='M';
- }
- else if(IrValue[2]==key7)
- {
- IrValue[2]=0x00;
- if(name[j][i]=='S')
- name[j][i]='P';
- else if(name[j][i]=='R')
- name[j][i]='S';
- else if(name[j][i]=='Q')
- name[j][i]='R';
- else if(name[j][i]=='P')
- name[j][i]='Q';
- else name[j][i]='P';
- }
- else if(IrValue[2]==key8)
- {
- IrValue[2]=0x00;
- if(name[j][i]=='V')
- name[j][i]='T';
- else if(name[j][i]=='U')
- name[j][i]='V';
- else if(name[j][i]=='T')
- name[j][i]='U';
- else name[j][i]='T';
- }
- else if(IrValue[2]==key9)
- {
- IrValue[2]=0x00;
- if(name[j][i]=='Z')
- name[j][i]='W';
- else if(name[j][i]=='Y')
- name[j][i]='Z';
- else if(name[j][i]=='X')
- name[j][i]='Y';
- else if(name[j][i]=='W')
- name[j][i]='X';
- else name[j][i]='W';
- }
- else if(IrValue[2]==key0)
- {
- IrValue[2]=0x00;
- i=0;
- j++;
- if(j>1)
- teamname=1;
- }
- lcd_show_name(2,2,3,2);
- }
- lcd12864time();
- i=0;
- while(gametime==0)
- {
- if(IrValue[2]==menu)
- {
- IrValue[2]='0';
- gametime=1;
- }
- else if(IrValue[2]==key1)
- {
- IrValue[2]=0x00;
- count_down[i++]='1';
- }
- else if(IrValue[2]==key2)
- {
- IrValue[2]=0x00;
- count_down[i++]='2';
- }
- else if(IrValue[2]==key3)
- {
- IrValue[2]=0x00;
- count_down[i++]='3';
- }
- else if(IrValue[2]==key4)
- {
- IrValue[2]=0x00;
- count_down[i++]='4';
- }
- else if(IrValue[2]==key5)
- {
- IrValue[2]=0x00;
- count_down[i++]='5';
- }
- else if(IrValue[2]==key6)
- {
- IrValue[2]=0x00;
- count_down[i++]='6';
- }
- else if(IrValue[2]==key7)
- {
- IrValue[2]=0x00;
- count_down[i++]='7';
- }
- else if(IrValue[2]==key8)
- {
- IrValue[2]=0x00;
- count_down[i++]='8';
- }
- else if(IrValue[2]==key9)
- {
- IrValue[2]=0x00;
- count_down[i++]='9';
- }
- else if(IrValue[2]==key0)
- {
- IrValue[2]=0x00;
- count_down[i++]='0';
- }
- else if(IrValue[2]==c)//c 清零
- {
- IrValue[2]=0x00;
- for(i=0;i<6;i++)
- count_down[i]=0x30;
- i=0;
- }
- lcd_show_time();
- }
- lcd12864xianshi();
- lcd_show_time();
- lcd_show_name(1,0,1,6);
- while(teamname)
- {
- if(bscore>ascore)
- {
- ledb=0;
- leda=1;
- }
- else if(bscore<ascore)
- {
- ledb=1;
- leda=0;
- }
- else
- {
- ledb=1;
- leda=1;
- }
- if(lcd_flag==1)
- {
- lcd_flag=0;
- lcd_show_time();
- }
- if(gameover_flag==1)
- {
- change_flag=1;
- if(ascore>bscore)
- {
- lcd_pos(3,4); //设置显示位置为第三行的第一个字符
- i = 0;
- while(awin[i]!='\0')
- {
- write_dat(awin[i]); //显示字符
- i++;
- }
- }
- else if(ascore<bscore)
- {
- lcd_pos(3,4); //设置显示位置为第三行的第一个字符
- i = 0;
- while(bwin[i]!='\0')
- {
- write_dat(bwin[i]); //显示字符
- i++;
- }
- }
- else
- {
- lcd_pos(3,4); //设置显示位置为第三行的第一个字符
- i = 0;
- while(draw[i]!='\0')
- {
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
counter.rar
(120.88 KB, 下载次数: 40)
|