当前位置:网站首页>Simulation of four way responder based on 51 single chip microcomputer
Simulation of four way responder based on 51 single chip microcomputer
2022-07-29 08:11:00 【Half life fireworks I blurred】
When the host presses the start button , Start countdown 60 second , The contestants began to rush to answer , When a contestant vies for answers, other contestants' vies for answers are invalid .
And the countdown stops after the contestants rush to answer .
Because I didn't set a new round of buttons , If you need to use a new round of answering, you can add a button to start a new round of answering
Timer configuration code
#include <REGX52.H>
void Timer0_Init(void)
{
TMOD &= 0xF0; // Configure timer mode
TMOD |= 0x01; // Set the timer 0 Pattern
TL0 = 0x3c; // Set initial value of timing 50ms Create an interrupt
TH0 = 0xb0; // Set initial value of timing
TF0 = 0; // eliminate TF0 sign
TR0 = 1; // Timer 0 Start timing
ET0=1;
EA=1;
PT0=0;
}
The digital tube displays the contestant number code
#include <REGX52.H>
#include "Delay.h" // contain Delay The header file
sbit we1=P2^0;
// Digital tube segment code table
unsigned char Table[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
// Nixie tube display sub function
void Nixie(unsigned int Speed)
{
we1=0;
P0=Table[Speed]; // Segment code output
Delay(1); // Show for a period of time
we1=1;
P0=0x00; // Segment code clear 0, Shadow elimination
}
The main function 、 Interrupt service function 、 Nixie tube display countdown
#include <REGX52.H>
#include "Delay.h"
#include "Timer0.h"
#include "Nixie.h"
unsigned char NixieTable[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};// Common cathode digital tube segment code
sbit we3=P2^2;
sbit we4=P2^3;
unsigned int flag=0,ms=60;//ms Set the initial value of countdown
unsigned int Number=0;
unsigned int x,z,y=0,f=0;
void main()
{
Timer0_Init();
while(1)
{
if(P1_4==0)
{
Delay(20);while(P1_4==0);Delay(20);
y=1;// Countdown start flag bit ,1 Start countdown
flag=1;// Answer the flag bit ,1 Key valid ,0 Invalid key
}
x=ms/10;
z=ms-x*10;// Count down each bit of data into the digital tube display
we3=0;
P0=NixieTable[x]; // Segment code output
Delay(1); // Show for a period of time
we3=1;
P0=0x00; // Segment code clear 0, Shadow elimination
we4=0;
P0=NixieTable[z]; // Segment code output
Delay(1); // Show for a period of time
we4=1;
P0=0x00; // Segment code clear 0, Shadow elimination
if(flag==1)
{
if(P1_0==0)
{
Delay(20);while(P1_0==0);Delay(20);
flag=0;// Make other players unable to answer
Number=1;// Get the contestant number and send it to the nixie tube display
f=1;// The countdown stops
}
if(P1_1==0)
{
Delay(20);while(P1_1==0);Delay(20);
flag=0;
Number=2;
f=1;
}
if(P1_2==0)
{
Delay(20);while(P1_2==0);Delay(20);
flag=0;
Number=3;
f=1;
}
if(P1_3==0)
{
Delay(20);while(P1_3==0);Delay(20);
flag=0;
Number=4;
f=1;
}
}
Nixie(Number);// Nixie tube display function
}
}
void Timer0_Routine() interrupt 1
{
unsigned int T0Count;
TL0 = 0x3c; // Set the initial value of timing to 50ms
TH0 = 0xb0; // Set initial value of timing
T0Count++;
if(T0Count>=20)
{
T0Count=0;
if(f==0)
{
if(y==1)
{
ms--;//1s Subtract one time
if(ms==0)
{
ms=60;
}
}
}
else
{
ms=ms;// The countdown stops after the contestants rush to answer
}
}
}
Simulation graphics
The answering machine made this time is relatively simple , If necessary, you can add code to make the function more comprehensive . If there is enough time in the follow-up, it can be further improved .
Just thought about it, I added a new round of answering buttons
if(P1_5==0)
{
Delay(20);while(P1_5==0);Delay(20);
break;// Jump out when the key is pressed while Main circulation
}
边栏推荐
- Dp4301-sub-1g highly integrated wireless transceiver chip
- 下推分析的限制
- 网络安全之安全基线
- Character shader exercise
- Arduinoide + stm32link burning debugging
- Some thoughts on growing into an architect
- Day 014 二维数组练习
- Intelligent shelf safety monitoring system
- Solve the problem of MSVC2017 compiler with yellow exclamation mark in kits component of QT
- STM32 detection signal frequency
猜你喜欢
Simplefoc parameter adjustment 3-pid parameter setting strategy
Mysql rownum 实现
[cryoelectron microscope | paper reading] a feature guided, focused 3D signal permutation method for subtogram averaging
STM32 serial port garbled
STM32 printf problem summary semihosting microlib understanding
Cs5340 domestic alternative dp5340 multi bit audio a/d converter
UE4 principle and difference between skylight and reflecting sphere
Dynamic Thresholds Buffer Management in a Shared Buffer Packet Switch论文总结
How to connect VMware virtual machine to external network under physical machine win10 system
[cryoelectron microscope | paper reading] emclarity: software for high-resolution cryoelectron tomography and sub fault averaging
随机推荐
Compatible with cc1101/cmt2300-dp4301 sub-1g wireless transceiver chip
Ws2812b color lamp driver based on f407zgt6
Mysql rownum 实现
Day 014 2D array exercise
[noi simulation] computational geometry (convex hull, violence, and search set)
Cv520 domestic replacement of ci521 13.56MHz contactless reader chip
BiSeNet v2
Research on autojs wechat: the final product of wechat automatic information sending robot (effective demonstration)
数字人民币时代隐私更安全
Application of explosion-proof inclination sensor in safe operation of LNG
Dynamic thresholds buffer management in a shared buffer packet switch paper summary
UE4 principle and difference between skylight and reflecting sphere
[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)
NFC two-way communication 13.56MHz contactless reader chip -- si512 replaces pn512
Internet worm
STM32 serial port garbled
The computer system has no standard tcp/ip port processing operations
torch.nn.functional.one_hot()
Qt/PyQt 窗口类型与窗口标志
Some simple uses of crawler requests Library