足球补时牌仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg51.h> //51单片机头文件
- #include<intrins.h> //51库函数
- #define uchar unsigned char //宏定义
- #define uint unsigned int
- sbit duan = P2^0;//段选接P2.0引脚
- sbit wei = P2^1; //位选接P2.1引脚
- sbit BUZZ = P2^3;
- char second = 0; //计数,时间(秒钟)
- char minute = 0; //计数,时间(分钟)
- /****
- 共阴级
- table[10]表示不显示
- table[11] 表示“-”
- **************/
- uchar code table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d,
- 0x7d, 0x07, 0x7f, 0x6f, 0x00, 0x40};
- uchar s[8];
- uchar delay = 1;
- uchar n = 0;
- uint th,tl;
- uchar speak = 0; //标识蜂鸣器是否开始发声
- void delayms(uint t) //延时函数
- {
- uint i,j;
- for(i=0;i<t;i++)
- for(j=0;j<110;j++);
- }
- void init()
- {
- EA = 1; //开全局中断
- EX0 = 1;//INT0中断允许
- IT0 = 1;//触发方式为下降沿触发
- EX1 = 1;//INT0中断允许
- IT1 = 1;//触发方式为下降沿触发
- TMOD = 0x19;
- TH0 = 0x4C; //给定初值
- TL0 = 0x00;
- TH1 = 0xff; //给定初值
- TL1 = 0x00;
- ET0 = 1; //定时器中断打开
- ET1 = 1;
- TR0 = 0; //不启动定时器中断
- TR1 = 0; //
- }
- void fun()
- {
- s[0] = table[second%10];
- s[1] = table[second/10];
- s[2] = table[11];
- s[3] = table[11];
- s[4] = table[minute%10];
- if(minute/10!=0) s[5] = table[minute/10];
- else s[5] = table[10];
- }
- void show()
- {
- uchar i;
- uchar temp = 0xdf;
- fun();
- for(i=0;i<6;i++){
- duan = 0;
- wei = 0;
- P0 = 0x00;
- duan = 1;
- P0 = s[i];
- duan = 0;
- P0 = 0xff;
- wei = 1;
- P0 = temp;
- wei = 0;
- temp = _cror_(temp, 1);
- TH1 = 0xff;
- TL1 = 0x00;
- TR1 = 1; //延时
- while(delay<1);
- TR1 = 0;
- delay = 0;
- }
- }
- void main()
- {
- init();
- while(1){
- show();
- if(speak==1){
- duan = 1;
- P0 = table[10];
- duan = 0;
- P0 = 0xff;
- wei = 1;
- P0 = 0x01;
- wei = 0;
- TR1 = 1;
- th = (65535-50000)/256;
- tl = (65536-50000)%256;
- TH1 = th;
- TL1 = tl;
- delayms(10000);
- TR1 = 0;
- speak=0;
- }
- }
- }
- void IN_T0() interrupt 0
- {
- minute++;
- if(minute > 19)
- minute=19;
- }
- void IN_T1() interrupt 2
- {
- TR0 = 1;
- }
- void timer0() interrupt 1
- {
- TH0 = 0x4C; //给定初值
- TL0 = 0x00;
- n++;
- if(n==20){
- n = 0;
- if(minute ==0 && second==0){
- TR0 = 0;
- speak = 1;
- }
- else if(second==0){
- minute --;
- second = 59;
- }
- else{
- second--;
- }
- }
- }
- void timer1() interrupt 3
- {
- if(speak==1)
- {
- BUZZ = ~BUZZ;
- TH1 = th; //给定初值
- TL1 = tl;
- }
- delay=1;
- }
复制代码
所有资料51hei提供下载:
足球补时牌.zip
(71.67 KB, 下载次数: 27)
|