Design and simulation of electronic counter based on AT89C51 microcontroller

Click the link to get the Keil source code and Project Backups simulation diagram:
https://download.csdn.net/download/qq_64505944/87770826

Source code acquisition
main content:
Design an electronic timer, the initial display value of the digital tube is “00”, and the electronic stopwatch is incremented by 1 every 1s; when the second counts to 60, it is cleared to 0 and restarts from 00.
basic requirements:
1. Electronic timer circuit design diagram;
2. Electronic timer design source program;
3. Keil runs the source program;
4. Simulation in protus;
5. Run result analysis.
Main references:
[1] Zhang Zhiliang. Single-chip study guide and exercises to answer. Mechanical Industry Press, 2008.
[2] Zhang Wei. The principle and application of single chip microcomputer. Mechanical Industry Press, 2009.
[3] Sun Junyi, Sheng Qiulin, Zhang Feng. The principle and application of single chip microcomputer. Tsinghua University Press. 2010.
[4] Zhang Yigang. The principle and application of single-chip microcomputer. Beijing Higher Education Press, 2010.
[5] Huang Renxin. SCM principle and application technology. Beijing Tsinghua University Press, 2005.

 Completion Deadline: December 11 - December 26
        Instructor's signature:
           Signature of course leader:

Summary
Counting is the simplest and basic operation, and a counter is a logic circuit that realizes this operation. In the digital system, the counter mainly counts the number of pulses to realize the functions of measurement, counting and control, and also has the function of frequency division. The counter is composed of a basic counting unit and some controls, and the counting unit is composed of a The series consists of various types of flip-flops with the function of storing information. These flip-flops include RS flip-flops, T flip-flops, D flip-flops, and JK flip-flops. Counters are widely used in digital systems, such as counting instruction addresses in the controller of an electronic computer, so as to sequentially fetch the next instruction, recording the number of additions and subtractions when performing multiplication and division operations in the arithmetic unit, and for example in digital Counting of pulses in an instrument, etc.
This design is a simple electronic counter, with AT89C51 as the main control chip, its function range is from 0 to 59, and the display digital tube is used to display the count.

Key words: simple electronic counter; AT89C51

Table of contents
Abstract I
catalog II
1. Overview 1
1.1 Course design purpose 1
1.2 Main content of the system 1
2. Overall Design 2
2.1 Design scheme 2
2.2 System function design 2
3. Protues simulation diagram and corresponding partial working principle 3
3.1 Overall simulation diagram 3
3.2 Partial display 3
3.3 Button Control 4
4. Source program 4
5. Result analysis 6
6. Experience 9

1 Overview

1.1 Course design purpose

1. Master the fundamental method of analysis and design of the control system with single-chip microcomputer as the core;
2. The design and implementation method of the control program;
3. Complete a small system design independently, from hardware design to software design, enhance the ability to analyze and solve problems, and lay a good foundation for future graduation design and scientific research work

1.2 Main content of the system

1. Start button, press to start counting and set the initial value;
2. Pause button, press the pause button, stop counting, then press the pause button, start counting;
3. End button, press to end this counting;
4. Every second, the number on the display nixie tube will increase by one, and the number on the nixie tube will return to zero every time it reaches 60

2. Overall design
2.1 Design scheme
This design is a simple counter for accumulative counting, using AT89C51 chip as the core, and 8-digit LED digital tube display. The advantages of this implementation method are simple circuit, reliable performance, strong real-time performance, simple operation and easy programming.
2.2 System function design

Figure 2.1 System function diagram

3. Protues simulation diagram and corresponding partial working principle
3.1 Overall simulation diagram

Figure 3.1 General Simulation Diagram
3.2 Partial display

Figure 3.2 Nixie tube display

3.3 Button Control

4. Source program

#include <reg51.h>
#define uc unsigned char
#define ui unsigned int
uc code table[]={<!-- -->0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //digital font table
uc led_mod[2];//store the number on each bit
#define ledSize 2
ui num;//Number displayed
uc led_point;

//The period is 1s=1ms*1000 a=65536-1000=0xfc18
//ui a = 0xfc18;

//a=(256-100)%6=156 = 0x9c
ui a = 0x9c;
void init(){<!-- -->
num=00;//initial value
//TH0=a/256;
//TL0=a%6;
TH0=0x9c;
TL0=0x9c;

TMOD=0x02;//T0 timing mode 2 0000 0010
TCON=0x10;//TR0=1 start T0
IE=0x82;//EA=1;ET0=1; Enable interrupt Enable T0 interrupt

}
void delayMs(ui ms){<!-- -->//delay function
 ui i;
while(ms--)for(i=0;i<124;i++);
}
P2=~led_point;//Digital low level active Refresh from single digit to thousand digit
P0=led_mod[i];//Model led_point<<=1;
delayMs(10);
}}
//}

void timer0() interrupt 1{<!-- -->//T0 interrupt function
static ui count;
count + + ;
    //TH0=a/256;
//TL0=a%6;
if(count==10000){<!-- -->
count=0;
num++;
num%=60;
}
}

void main(void){<!-- -->
\t
init();//initialization
while(1){<!-- -->
show(num);
}
}

5. Result analysis

5.1 Enter the complete code in the keil software, click to run, the result is as follows:

Figure 5.1

5.2 After the keil source program runs successfully, a hex file is generated, connected to proteus, and simulated.

Figure 5.2

Figure 5.3

5.3 After the connection is completed, click the start button, and the counter will start counting

Figure 5.4

5.5 Click the pause button and the counter pauses counting
5.6 In the pause state, long press the click button, the counter will run normally, release it to pause counting

5.7 The number of the nixie tube will return to zero every time the count reaches 60

5.8 Click the end button to end counting

6. Experience

I learned a lot from this MCU course design. I used some of the things I learned this semester and benefited a lot. I still feel a sense of accomplishment. At the same time, it also improves our ability to consult literature, design manuals, design specifications, and computer graphics. Moreover, through the control of the whole, the choice of parts, and the consideration of details, our abilities have been exercised and our experience has been enriched. This is what we all want to see, and it is also the purpose of our study of electronic technology course design. This design made me deeply realize that what I learned from the microcontroller in the book is really very limited, and the components that the microcontroller is extended to in class and experiments can only be regarded as the tip of the iceberg. It is this exercise that has allowed us to accumulate countless practical experiences, so that our minds are better armed with knowledge, and it will inevitably allow us to show higher resilience, stronger communication and communication skills in future work and study. understanding.