Simple calculator digital tube display simulation design of 51 microcontroller (proteus simulation + program + schematic diagram + report + explanation video)


Simple calculator digital tube display simulation design of 51 microcontroller (proteus simulation + program + schematic diagram + report + explanation video)

Simulation diagram proteus7.8 and above

Program compiler: keil 4/keil 5

Programming language: C language

Design number: S0049

1. Main functions:

This design aims to design a simple calculator simulation design based on 51 microcontroller.

Functional requirements: realize the four simple operations of addition, subtraction, multiplication and division with digital tube display

1. Ability to enter correct key values ​​through the matrix keyboard;

2. Able to perform simple four arithmetic operations;

3. Ability to display numerical values ​​correctly using digital tubes;

4. Maximum support is 999*999;

5. Entering numbers can be repeated and the last three digits will be taken.

It should be noted that the 51 microcontroller chip in the simulation is universal. AT89C51 and AT89C52 are specific models of the 51 microcontroller, and the cores are compatible. Regardless of stc or at, the pin functions are the same and the program is the same. The chip can be replaced with 51 microcontroller chips such as STC89C52/STC89C51/AT89C52/AT89C51.

The following is a display diagram of this design information:

2. Simulation

Start simulation

Open the simulation project, double-click the microcontroller in proteus, select the hex file path, and then start simulation. After starting the simulation, the digital tube displays 000000.

Open the simulation project, double-click the microcontroller in proteus, select the hex file path, and then start simulation. After starting the simulation, the digital tube displays 000 000.

img

Due to the limitations of the digital tube display, the arithmetic symbols of addition, subtraction, multiplication and division in this design are displayed according to the punctuation points in the figure below:

img

Addition verification: After inputting 123+456 on the matrix keyboard, press the key = to display the operation result 00579. The clip is shown below:

img

Subtraction verification: After inputting 789-456 on the matrix keyboard, press the key = to display the operation result 000333. The clip is shown below:

img

Multiplication verification: After inputting 999*999 on the matrix keyboard, press the key = to display the operation result 998001. The clip is shown below:

img

Division verification: After inputting 666*3 on the matrix keyboard, press the key = to display the operation result 000222. The clip is shown below:

img

The above addition, subtraction, multiplication and division operations all comply with mathematical operation rules and meet the design requirements.

3. Program code

Use keil4 or keil5 to compile, the code has comments, and you can understand the meaning of the code in conjunction with the report.

img

Main function code

void main()//主函数
{
    
    
	unsigned char i;
	unsigned int m=0;
	while(1)
	{
    
    
		//显示
		if(fuhao<5)
		{
    
    
		P0=smgduan[a%1000/100];smg1=0;delay(100);smg1=1;
		P0=smgduan[a%100/10];smg2=0;delay(100);smg2=1;
		P0=smgduan[a%10];smg3=0;delay(100);smg3=1;	//显示第一个数

		switch(fuhao)//显示运算符号
		{
    
    
			case 1:P0=0x01;break;
			case 2:P0=0x40;break;
			case 3:P0=0x08;break;
			case 4:P0=0x80;break;
			default:P0=0;
		}
		smg4=0;delay(100);smg4=1;

		P0=smgduan[b%1000/100];smg5=0;delay(100);smg5=1; //显示第二个数
		P0=smgduan[b%100/10];smg6=0;delay(100);smg6=1;
		P0=smgduan[b%10];smg7=0;delay(100);smg7=1;
		}
		else//显示结果
		{
    
    
			P0=smgduan[c%1000000/100000];smg2=0;delay(100);smg2=1;
			P0=smgduan[c%100000/10000];smg3=0;delay(100);smg3=1;
			P0=smgduan[c%10000/1000];smg4=0;delay(100);smg4=1;
			P0=smgduan[c%1000/100];smg5=0;delay(100);smg5=1;
			P0=smgduan[c%100/10];smg6=0;delay(100);smg6=1;
			P0=smgduan[c%10];smg7=0;delay(100);smg7=1;
		}
		//==================================================
		i=key_scan();//检测
		if((i>0)&&(i<11))//输入数值
		{
    
    
			if(fuhao==0)//第1个输入
			{
    
    
				a=a*10+i-1;
				if(a>999)
					a=a%1000;				
			}
			else //第2个输入
			{
    
    
				b=b*10+i-1;
				if(b>999)
					b=b%1000;				
			}
		}
		if(i==13)//+	加法
		{
    
    
			fuhao=1;
		}
		if(i==14)//-	  减法
		{
    
    
			fuhao=2;
		}
		if(i==15)//*		乘法
		{
    
    
			fuhao=3;
		}
		if(i==16)// /	   除法
		{
    
    
			fuhao=4;
		}
		if(i==11)//ok		 等于
		{
    
    						
			switch(fuhao)	   //判断按下的运算法则是什么
			{
    
    
				case 1:c=a+b;break;		   //加
				case 2:c=a-b;break;		   //减
				case 3:c=a;c=c*b;break;	   //成
				case 4:c=a/b;			   //除法
			}
			fuhao=5;						
		}
		if(i==12)//清除
		{
    
    			 
			 a=0;
			 b=0;
			 c=0;
			 fuhao=0;
		}
	}
}

4. Schematic diagram

The schematic diagram is drawn with AD, which can be used as a reference for the real thing. The simulation is different from the real thing. If you are inexperienced, don't make it easy.

img

The difference between Proteus simulation and physical works:

1. Running environment: Proteus simulation runs on the computer, while the real thing runs on the hardware circuit board.

2. Debugging method: In Proteus simulation, you can easily perform single-step debugging and observe changes in variable values, while in real objects, you need to debug through a debugger or serial port output.

Circuit connection method: In Proteus simulation, the circuit connection can be modified through software settings, but in the real thing, it needs to be modified through the hardware circuit board and connecting wires.

3. Running speed: Proteus simulation usually runs faster than the real thing, because the simulation is based on computer operation, while the real thing needs to consider factors such as the physical limitations of the circuit board and the response time of the device.

4. Function realization: In Proteus simulation, different functions can be realized through software settings, but in real objects, they need to be realized according to the circuit design and device performance.

5. Design report

6249-word design report

img

6. Design information content list && download link

Material design materials include simulation, program code, explanation videos, functional requirements, design reports, software and hardware design block diagrams, etc.

0. Common usage problems and solutions – a must-read! ! ! !

1. Simulation diagram

2. Program source code

3. Proposal report

4. Schematic diagram

5. Functional requirements

6. Components list

7. Design report

8. Software and hardware flow chart

9. Explanation video

Altium Designer Software Information

filename.bat

KEIL software information

Proteus software information

Microcontroller learning materials

directory listing.txt

Defense skills

Common descriptions for design reports

Double-click the mouse to open and find more 51 STM32 Microcontroller Course Graduation Project.url

img

Data download link:

https://docs.qq.com/doc/DS2RTaGxZUktTRnRE

Guess you like

Origin blog.csdn.net/weixin_52733843/article/details/132796970