This paper designs a simple calculator based on AT89S52 microcontroller. Its function is:
(1) The calculator can display at least 8 digits normally.
(2) When the card machine is displayed, 0 is displayed. When pressed for the first time, D1 is displayed; when pressed for the second time, D1D2 is displayed.
(3) The calculator can simply add, subtract, multiply, and divide the integers, and automatically subtract the fractional part when doing the division.
(4) An error message can be displayed when the calculation result exceeds the number of digits that can be displayed.
Overall designThe calculator uses the AT89S52 single-chip microcomputer as the core chip to obtain data by scanning the keyboard. In addition, the data obtained by the CPU is calculated according to the requirements and sent to the display circuit for display.
Block diagram designThe simple calculator based on AT89S52 single-chip microcomputer is composed of power supply circuit, single-chip microcomputer main control circuit, key circuit, display circuit and reset circuit. The block diagram is composed as shown below.
Simple calculator system block diagram based on AT89S52 microcontroller
System design circuit schematicBased on AT89S52 single-chip simple calculator circuit schematic
Program flow chartSince this design is mainly an algorithmic problem, the program is written in C language. The main function initializes the microcontroller and continuously calls the scan function and the arithmetic function. The display function uses a 1ms timer interrupt to update the display data in real time. The flowchart of the simple calculator program based on AT89S52 MCU is shown in the figure below.
Simple calculator program flow chart
Code writing#include P #include》
#define LEDS 8
/*** button program *** / char keyscan ();
/***Display program***/void display();
Char dsp[9]={0,0,12,12,12,12,12,12,12}; //Initialize the display array
/*** Calculation program***/
Void calculate(char k,char c1[8],char c2[8]);
6.5Inch Coaxial Speaker,6.5 Inch Coaxial,6.5Inch Church Speaker,6.5 Inch Coaxial Speaker
Guangzhou BMY Electronic Limited company , https://www.bmy-speakers.com