Design sharing | single chip microcomputer 8-way responder

Specific implementation functions

Specific functions:

(1) Press the "start" button to enter the 20S countdown, and eight contestants can rush to answer;

(2) After the contestant presses the answer key, the nixie tube displays the corresponding contestant number, indicating that the answer is successful;

(3) After the answer is successful, click "start within limited time" to enter the countdown of the answer;

(3) Three seconds before the end of the countdown, the buzzer rings for prompt;

(4) Press the "rush time adjustment" and "limited time adjustment" buttons to adjust the rush time and limited time respectively.

Design Introduction

Introduction to single chip microcomputer

51 single chip is a low-power, high-performance CMOS 8-bit microcontroller with 8k in system programmable Flash memory. On a single chip, it has a smart 8-bit CPU and in system programmable Flash, which makes STC89C51 provide highly flexible and super effective solutions for many embedded control application systems. It has the following standard functions: 8k byte Flash, 512 byte RAM, 32-bit I/O port line, watchdog timer, built-in 4KB EEPROM, MAX810 reset circuit, three 16 bit timers / counters, a 6-vector 2-level interrupt structure, and full duplex serial port. In addition, STC89X51 can be reduced to 0Hz static logic operation, and supports two software selectable power saving modes. In idle mode, the CPU stops working and allows RAM, timer / counter, serial port and interrupt to continue working. In the power down protection mode, the RAM content is saved, the oscillator is frozen, and all the work of the single chip microcomputer stops until the next interrupt or hardware reset. The maximum operating frequency is 35Mhz, 6T/12T optional.

Design ideas

Literature research method: collect and sort out the relevant research data of MCU intelligent Bracelet system, carefully read the literature and prepare for the research;

Investigation and research method: through investigation, analysis and specific trial, it is found that the current situation, existing problems and solutions of single chip microcomputer intelligent Bracelet system;

Comparative analysis method: compare the specific principles of different single-chip microcomputer intelligent Bracelet systems and the performance differences of the same kind of sensors, and analyze the research status and development prospect of single-chip microcomputer intelligent Bracelet system;

Software and hardware design method: realize the specific hardware object through software and hardware design, and finally test whether each function meets the requirements.

Design content

Simulation diagram

This design uses Protues 8.7 software to realize the simulation design, as shown in the figure.

Protues is also one of the commonly used design software in MCU simulation design. By designing the hardware circuit diagram and writing the driver, we can debug the circuit without realizing the hardware. In addition, Protues can also realize PCB design and joint debugging with KEIL in simulation, which is convenient for program debugging, supports a variety of platforms and is simple and convenient to use.

program

This design uses KEIL5 software to realize program design, as shown in the figure. As the first programming language learned during the undergraduate course, C language is one of the most familiar programming languages. Of course, because of its powerful function, C language is the most widely used and popular programming language in the world. In the design of single chip microcomputer, C language has gradually and completely replaced assembly language, because compared with assembly language, C language is very convenient for compilation, operation and debugging, high portability, good readability, and easy to burn and write into hardware system. Therefore, C language is widely used in the design of single chip microcomputer. Keil software, which is compatible with the design of single chip microcomputer, can realize rapid debugging and generate burning files. It is widely used in the writing of C language and the design of single chip microcomputer.

#include<at89x51.h>#define uchar unsigned char#define uint unsigned intchar s;uchar num=0;char time=20;  // Response time char datitime=30// Answer time limit uint, TT, T1// T0, T1 timer bit flag,s_flag=1,b_flag,fall_flag;  // Flag bit K_startcountflag,K_timecountflag;  // Time adjustment flag bit sbit K0=P3^0;sbit beep=P3^7;         // Buzzer sbit rled=P3^1// Indicator light 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 K_ Time=P3^2;  // Answer timing key sbit K_startcount=P3^3;  // Start answering time adjustment key sbit K_timecount=P3^4;  // Answer timing time adjustment key 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) / / start key scanning {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; / / clear the violation flag bits k_startcountflag = 0; k_timecountflag = 0;}}} void scan (void) //Eight way hot key scanning (which key is pressed first, which has the highest priority) {if (K1 = = 0) {delay (10); if (K1 = = 0) {while (! K1); num = 1; / / the nixie tube displays No. 1 "1" Tr0 = 0; / / turn off timer 0 and stop Tr1 = 1; / / turn on timer 1 and make the speaker sound s_flag = 0; / / turn off the start key flag bit so that pressing the other seven keys will not respond}} if(K2==0) / / the processing of the following seven keys is the same as {delay (10); if(K2==0) {while (! K2) ; num = 2; tr0 = 0; Tr1 = 1; s_flag = 0; / / important}} 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) / / press the start key to start timing and answering {if(num!=0) / / if someone answers, the corresponding number is displayed {P0=tabledu[num]; / / the number is displayed and P2 = tablewe [0]; delay (2) ; P0 = 0; P2 = 0xff;} else / / otherwise, no one will rush to answer, and the number {P0 = 0; P2 = 0xff;} P0 = tabledu [S / 10]; / / the following is the countdown to rush to answer P2 = tablewe [2]; delay (2); P0 = 0; P2 = 0xff; P0 = tabledu [S% 10]; P2 = tablewe [3]; delay (2); P2 = 0xff; P0 = 0;} Else / / if the start key is not pressed, f FF (the violation number and FF will be displayed if there are violators) or time adjustment {if(fall_flag==1) / / violation display {if(num!=0) {P0=tabledu[num]; / / display the number of violations P2 = tablewe [0]; delay (2); P0 = 0; P2 = 0xff; P0 = tabledu [15] ; / / FF is displayed below, indicating violation P2 = tablewe [2]; delay (2); P0 = 0; / / blanking P2 = 0xff; P0 = tabledu [15]; P2 = tablewe [3]; delay (2); P0 = 0; P2 = 0xff;} else {P0 = 0; P2 = 0xff;}} else / / the adjustment time is displayed only when no one violates {if (k_startcountflag = = 1) {P0 = 0x6d; / / the first digit of the nixie tube displays "5(S)" (indicating the response time adjustment) P2 = tablewe [0]; delay (2); P0 = 0; P2 = 0xff; P0 = tabledu [time / 10]; / / the adjusted response time P2 = tablewe [2]; delay (2); P0 = 0; P2 = 0xff; P0 = tabledu [time% 10] is displayed below ; P2 = tablewe [3]; delay (2); P0 = 0; P2 = 0xff;} else if (k_timecountflag = = 1) {P0 = 0x07; / / the first digit and the second digit nixie tube display "t" together, indicating that the answer time is adjusted P2 = tablewe [0]; delay (2); P0 = 0; P2 = 0xff; P0 = 0x31; P2 = tablewe [1]; delay (2) ; P0 = 0; P2 = 0xff; P0 = tabledu [datum / 10]; P2 = tablewe [2]; delay (2); P0 = 0; P2 = 0xff; P0 = tabledu [datum% 10]; P2 = tablewe [3]; delay (2); P0 = 0; P2 = 0xff;} else / / otherwise, f FF is displayed {P0 = tabledu [15]; P2 = tablewe [0]; delay (2) ; P0 = 0; P0 = tabledu [15]; P2 = tablewe [2]; delay (2); P0 = 0; / / blanking P2 = 0xff; P0 = tabledu [15]; P2 = tablewe [3]; delay (2); P0 = 0; P2 = 0xff;}}}} void time_scan (void) / / adjust the time key scanning {if(K_startcount==0) / / adjust the response time {delay (10); if(K_startcount==0) {while (! K_startcount); time + +; if (time = = 50) {time = 20;} k_startcountlag = 1; / / position the answer time flag at 1 k_timecountlag = 0; / / turn off the answer time flag at the same time}} if(K_timecount==0) / / adjust the answer time {delay (10); if(K_timecount==0) {while (! K_timecount); datum + +; if (datum = = 60) {datum = 30;} k_timecountflag = 1; k_startcountflag = 0;}}} void main (void) {t0_init(); while (1) {key_scan(); / / start key scanning if ((flag = = 0) & (s_flag = = 1)) / / the time can be adjusted only when the start key is not pressed and no one violates the rules {time_scan();} If ((flag = = 1) & (s_flag = = 0)) / / when the start key is pressed and someone scrambles to answer, the countdown starts {if (k_time = = 0) {delay (10); if (k_time = = 0) {while (! K_time); s = datum; tr0 = 1; TT = 0; Tr1 = 1;}}}} if ((flag = = 0) & (s_flag = = 1)) / / violation {scan(); if(num!=0) / / when the start key is not pressed, someone presses the responder, then set the violation flag bit {fall_flag = 1; RLED = 0;}} if ((flag = = 1) & (s_flag = = 1)) / / if the start key is pressed and no one presses the responder, then perform eight channel responder scanning {scan();} display(); / / displayed on the nixie tube}}} Void timer0 (void) interrupt 1 {Th0 = (65536-2000) / 256; / / 2ms tl0 = (65536-2000)% 256; if (b_flag) / / press the start key, and a beep (for 1 second) indicates that you start to answer {beep = ~ beep;} else beep = 1; if (s < 5) / / when the answer time is fast enough, an alarm will sound every 1 second, and the red light will flash, and three times {if (s% 2 = = 0) {b_flag = 1; RLED = 0;} else {b_flag = 0; RLED = 1;}} TT + +; if (TT = = 500) / / 1 second {TT = 0; s --; b_flag = 0; / / turn off the start key and press the beep for one second. If (s = = - 1) {s = 20; tr0 = 0; flag = 0; / / F FF s_flag = 1; num = 0; RLED = 1;}}}} void Timer1 (void) interrupt 3 / / timer 1 beeps when someone presses the responder (1 second long) {Th1 = (65536-2000) / 256; TL1 = (65536-2000)% 256; beep = ~ beep; T1 + +; if (T1 = = 500) {T1 = 0; Tr1 = 0;}}

For more information, please pay attention to the "Growth Diary of electronic engineers"!

Keywords: Single-Chip Microcomputer

Added by erfaan on Sat, 23 Oct 2021 15:41:24 +0300