赞
踩
完整版 电路图和程序代码 下载地址
https://pan.baidu.com/s/1UEx-nh1Dg-pAJSUGoDCkaQ?pwd=8888
- #include <at89x51.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define M 10
- char s;
- uchar num = 0;
- char time = 30; /* 抢答时间 */
- char datitime = 30; /* 答题限时时间 */
- uint tt, t1; /* T0,T1定时器定一秒时 */
- bit flag, s_flag = 1, b_flag, fall_flag; /* 标志位 */
- bit K_startcountflag, K_timecountflag; /* 时间调整标志位 */
- sbit K0 = P3 ^ 0;
- sbit beep = P3 ^ 7; /* 蜂鸣器 */
- sbit rled = P3 ^ 1; /* 指示灯 */
- sbit K1 = P1 ^ 0;
- sbit K2 = P1 ^ 1;
- sbit K3 = P1 ^ 2;
- sbit K4 = P1 ^ 3;
- sbit K5 = P1 ^ 4;
- sbit K6 = P1 ^ 5;
- sbit K7 = P1 ^ 6;
- sbit K8 = P1 ^ 7;
- sbit scl = P0 ^ 0;
- sbit sda = P0 ^ 1;
- sbit K_Time = P3 ^ 2; /*复位键 */
- sbit K_startcount = P3 ^ 3; /* 开始抢答时间调整键 */
- sbit add = P3 ^ 4; /* 答题计时时间调整键 */
- sbit sub = P3 ^ 5; /* 答题计时时间调整键 */
- void delay( uchar ms )
- {
- uchar y;
- for (; ms > 0; ms-- )
- for ( y = 120; y > 0; y-- )
- ;
- }
-
-
- uchar code tabledu[] = { 0x3f, 0x06, 0x5b, 0x4f,
- 0x66, 0x6d, 0x7d, 0x07,
- 0x7f, 0x6f, 0x77, 0x7c,
- 0x39, 0x5e, 0x79, 0x71 };
- uchar code tablewe[] = { 0XFE, 0XFD, 0XFB, 0XF7 };
- void T0_Init( void )
- {
- TMOD = 0X01;
- TH0 = (65536 - 2000) / 256;
- TL0 = (65536 - 2000) % 256;
- TH1 = (65536 - 2000) / 256;
- TL1 = (65536 - 2000) % 256;
- ET0 = 1;
- ET1 = 1;
- EA = 1;
- P0 = 0;
- }
-
-
- void Key_Scan( void ) /* 开始键扫描 */
- {
- if ( K0 == 0 )
- {
- delay( 10 );
- if ( K0 == 0 )
- {
- while ( !K0 )
- ;
- TR0 = 1;
- s = time;
- tt = 0;
- flag = 1;
- s_flag = 1;
- b_flag = 1;
- num = 0;
- beep = 1;
- rled = 1;
- fall_flag = 0; /* 清除违规标志位 */
- K_startcountflag = 0;
- K_timecountflag = 0;
- }
- }
- if ( K_Time == 0 )
- {
- delay( 10 );
- if ( K_Time == 0 )
- {
- TR0 = 0;
- TR1 = 1;
- s = time;
- flag = 0;
- s_flag = 1;
- num = 0;
- rled = 1;
- fall_flag = 0; /* 清除违规标志位 */
- K_startcountflag = 0;
- K_timecountflag = 0;
- }
- }
- }
-
-
- void WRITE_A_BYTE( uchar input )
- {
- uchar t;
- for ( t = 8; t != 0; t-- )
- {
- sda = (bit) (input & 0x80);
- delay( M );
- scl = 1;
- delay( M );
- input = input << 1;
- scl = 0;
- delay( M );
- }
- }
-
-
- void Scan( void ) /* 八路热键扫描(哪个键先按下,哪个优先级最高) */
- {
- if ( K1 == 0 )
- {
- delay( 10 );
- if ( K1 == 0 )
- {
- while ( !K1 )
- ;
- num = 1; /* 数码管显示1号"1" */
- TR0 = 0; /* 关闭定时器0,时间停止 */
- TR1 = 1; /* 打开定时器1,使扬声器响一声 */
- s_flag = 0; /* 关闭开始键标志位,使再按其他七个键不会响应 */
- }
- }
- if ( K2 == 0 ) /*下面七个键的处理同上 */
- {
- delay( 10 );
- if ( K2 == 0 )
- {
- while ( !K2 )
- ;
- num = 2;
- TR0 = 0;
- TR1 = 1;
- s_flag = 0; /* 重要 */
- }
- }
- if ( K3 == 0 )
- {
- delay( 10 );
- if ( K3 == 0 )
- {
- while ( !K3 )
- ;
- num = 3;
- TR0 = 0;
- TR1 = 1;
- s_flag = 0;
- }
- }
- if ( K4 == 0 )
- {
- delay( 10 );
- if ( K4 == 0 )
- {
- while ( !K4 )
- ;
- num = 4;
- TR0 = 0;
- TR1 = 1;
- s_flag = 0;
- }
- }
- if ( K5 == 0 )
- {
- delay( 10 );
- if ( K5 == 0 )
- {
- while ( !K5 )
- ;
- num = 5;
- TR0 = 0;
- TR1 = 1;
- s_flag = 0;
- }
- }
- if ( K6 == 0 )
- {
- delay( 10 );
- if ( K6 == 0 )
- {
- while ( !K6 )
- ;
- num = 6;
- TR0 = 0;
- TR1 = 1;
- s_flag = 0;
- }
- }
- if ( K7 == 0 )
- {
- delay( 10 );
- if ( K7 == 0 )
- {
- while ( !K7 )
- ;
- num = 7;
- TR0 = 0;
- TR1 = 1;
- s_flag = 0;
- }
- }
- if ( K8 == 0 )
- {
- delay( 10 );
- if ( K8 == 0 )
- {
- while ( !K8 )
- ;
- num = 8;
- TR0 = 0;
- TR1 = 1;
- s_flag = 0;
- }
- }
- }
-
-
- void display( void )
- {
- if ( flag == 1 ) /* 开始键按下,开始计时抢答 */
- {
- if ( num != 0 ) /* 如果有人抢答,则显示相应的几号 */
- {
- P0 = tabledu[num]; /* 显示几号抢到了 */
- P2 = tablewe[0];
- delay( 2 );
- P0 = 0;
- P2 = 0XFF;
- }else { /* 否则没人抢答,则前面不显示几号 */
- P0 = 0;
- P2 = 0XFF;
- }
- P0 = tabledu[s / 10]; /*下面为显示抢答倒计时 */
- P2 = tablewe[2];
- delay( 2 );
- P0 = 0;
- P2 = 0XFF;
- P0 = tabledu[s % 10];
- P2 = tablewe[3];
- delay( 2 );
- P2 = 0XFF;
- P0 = 0;
- }else { /* 如果开始键没有按下,则显示F FF(若有违规者,则显示违规号码及 FF)或时间调整 */
- if ( fall_flag == 1 ) /* 违规显示 */
- {
- if ( num != 0 )
- {
- P0 = tabledu[num]; /* 显示几号违规了 */
- P2 = tablewe[0];
- delay( 2 );
- P0 = 0;
- P2 = 0XFF;
-
- P0 = tabledu[15]; /*下面显示 FF,表示违规了 */
- P2 = tablewe[2];
- delay( 2 );
- P0 = 0; /* 消隐 */
- P2 = 0XFF;
- P0 = tabledu[15];
- P2 = tablewe[3];
- delay( 2 );
- P0 = 0;
- P2 = 0XFF;
- }else {
- P0 = 0;
- P2 = 0XFF;
- }
- }else { /* 没有人违规才显示调整时间 */
- if ( K_startcountflag == 1 )
- {
- P0 = 0X6D; /* 第一位数码管显示"5(S)"(表示抢答时间调整) */
- P2 = tablewe[0];
- delay( 2 );
- P0 = 0;
- P2 = 0XFF;
- P0 = tabledu[time / 10]; /*下面显示调整的抢答时间 */
- P2 = tablewe[2];
- delay( 2 );
- P0 = 0;
- P2 = 0XFF;
- P0 = tabledu[time % 10];
- P2 = tablewe[3];
- delay( 2 );
- P0 = 0;
- P2 = 0XFF;
- }else { /* 否则显示0 00 */
- P0 = tabledu[0];
- P2 = tablewe[0];
- delay( 2 );
- P0 = 0;
- P0 = tabledu[0];
- P2 = tablewe[2];
- delay( 2 );
- P0 = 0; /* 消隐 */
- P2 = 0XFF;
- P0 = tabledu[0];
- P2 = tablewe[3];
- delay( 2 );
- P0 = 0;
- P2 = 0XFF;
- }
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。