51 single chip simple digital multimeter (resistance current voltage measurement) simulation design (proteus simulation + program + report + explanation video)

51 single chip simple digital multimeter (resistance current voltage measurement) simulation design (proteus simulation + program + report + explanation video)

Simulation diagram proteus7.8 and above

Program compiler: keil 4/keil 5

Programming language: C language

Design number: S0041

1. Main functions:

Use the knowledge you have learned to create a simple digital multimeter design for a 51 microcontroller.

Specific functions: The multimeter can switch between measuring voltage values, current values ​​and resistance values, and displays them with four digits. It will alarm when there is a short circuit.

1. Voltage measurement range 0-20V, measurement error is about 0.5V

2. Current measurement range 0-200mA, measurement error is about 5mA

3. The resistance measurement range is 0-1000 ohms, and the error is about 10 ohms.

4. Short circuit alarm: Connect the two points to be measured with wires, and the buzzer will sound.

5. Display the measurement value through the digital tube, and select the measurement type through the switch.

The following is a display diagram of this design information:

2. Simulation

Start simulation

After starting the simulation, you can select the measurement type by turning the toggle switch. The first digit of the digital tube displays A for measuring voltage, B for measuring resistance, and C for measuring current. The last three digits display the measured value. If two measurement contents are selected at the same time, the buzzer will sound.

Voltage gear test:
When the voltage gear switch is turned on during simulation, the simulation results are shown in Figure 3.1. Changing the sliding rheostat is equivalent to changing the different circuits connected by the red and black test leads for voltage measurement (you can press the reset button to reset before re-measurement and then measure). Divide the voltage through R2 and R3. Assuming the measured voltage U, the actual voltage U1=(U/R3)*R2; Note: The measured voltage is greater than 20V, which will burn out the AD converter.
img

Resistance gear test:
When performing resistance gear simulation, first press the reset button to reset, and then perform measurement simulation after the display is cleared. Changing the position of the sliding rheostat during the simulation process is equivalent to changing the different resistance values ​​connected to the red and black test leads. The resistance. As shown in Figure 4.5, assuming the measured voltage is U, then the current in the circuit I=(5-U)/100 and the measured resistance R=U/I=U/((5-U)/100), Note: Resistor If it is too large, the measurement will be inaccurate.
img

Current profile test:
When performing current measurement, first reset the current profile and then perform current profile simulation after the display is cleared. Changing the sliding rheostat is equivalent to changing the different circuits connected by the red and black test leads for current measurement. As shown in Figure 4.4, if the measured voltage is U during measurement, then the current in the circuit is I=(U/5)*1000(MA); Note: If the current is too large, resistor R4 will be burned out;
img

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 (void)
{
    
    
	u8 Mode;
	uchar Read_AD;	//用于读取ADC数据
	uchar VIN;			//电压值变量
	u16 RIN;				//电阻值变量
	u16 IIN;				//电流值变量
	u16 i=0;;
	while (1)      				//主循环
	{
    
    		
		if(Key_V==0)				//电压按键按下
		{
    
    
			Key_V=1;					//清除按下标记
			if((Key_R==0)||(Key_I==0))//电阻电流按键也有按下
			{
    
    
				Key_I=1;
				Key_R=1;
				Key_V=1;
				Mode=4;					//标记为错误模式
			}
			else							//电阻电流键都没有按下
			Mode=1;						//标记为电压模式
		}
		if(Key_R==0)				//同电压键
		{
    
    
			Key_R=1;
			if((Key_V==0)||(Key_I==0))
			{
    
    
				Key_I=1;
				Key_R=1;
				Key_V=1;
				Mode=4;
			}
			else
			Mode=2;
		}
		if(Key_I==0)				//同电压键
		{
    
    
			Key_I=1;
			if((Key_V==0)||(Key_R==0))
			{
    
    
				Key_I=1;
				Key_R=1;
				Key_V=1;
				Mode=4;
			}
			else
			Mode=3;
		}
		if((Key_V==1)&&(Key_R==1)&&(Key_I==1))//都没有按下
		{
    
    
			Mode=0;			//标记为空闲模式
		}
		if(i==0)
		{
    
    
		Read_AD=Adc0832(0);				//读取AD值
		}
		i++;
		if(i>300)
			i=0;
			switch(Mode)
		{
    
    
			case 0:
						//空闲模式
								dis_smg[0]=DisplayOther[2];//关闭数码管显示
								dis_smg[1]=DisplayOther[2];
								dis_smg[2]=DisplayOther[2];
								dis_smg[3]=DisplayOther[2];
									Speak = 0;
			break;
			case 1:
						//电压模式
								VIN=Read_AD*200/255;										//换算出电压值
								dis_smg[0]=DisplayNum[0xa];							//显示电压标志
								dis_smg[1]=DisplayNum[VIN/100%10];			//电压十位
								dis_smg[2]=DisplayNum[VIN/10%10]&0x7f;	//电压个位
								dis_smg[3]=DisplayNum[VIN%10];					//电压十分位
								
								if(VIN > 160)	  //电压档大于16V报警
									Speak = 1;
								else
									Speak = 0;
			break;
			case 2:
						//电阻模式		
								RIN=Read_AD*100/(255-Read_AD);				//换算出电阻值
								dis_smg[0]=DisplayNum[0xb];       		//显示电阻标志
								dis_smg[1]=DisplayNum[RIN/100%10];    //电阻百位
								dis_smg[2]=DisplayNum[RIN/10%10];     //电阻十位
								dis_smg[3]=DisplayNum[RIN%10];        //电阻个位
								if(RIN>=1000)													//超过或等于1000;
								{
    
    
									dis_smg[1]=DisplayOther[2];					//显示"-"
									dis_smg[2]=DisplayOther[2];					//显示"-"
									dis_smg[3]=DisplayOther[2];					//显示"-"
								}
								
								if(RIN > 800)		 //电阻档大于800报警
									Speak = 1;
								else
									Speak = 0;
			break;
			case 3:
						//电流模式		
								IIN=4*Read_AD;//单位mA								//换算出电流值
								dis_smg[0]=DisplayNum[0xc];           //显示电流标志
								if(IIN<=200)													//没有超过范围
								{
    
    
									dis_smg[1]=DisplayNum[IIN/100%10];	//电流百位
									dis_smg[2]=DisplayNum[IIN/10%10]; 	//电流十位
									dis_smg[3]=DisplayNum[IIN%10];    	//电流个位
								}
								else
								{
    
    
									dis_smg[1]=DisplayOther[2];					//显示"-"
									dis_smg[2]=DisplayOther[2];					//显示"-"
									dis_smg[3]=DisplayOther[2];					//显示"-"
								}
								
								if(IIN > 80)	 //电流档大于80报警
									Speak = 1;
								else
									Speak = 0;
			break;
			case 4:
							Speak = 1;
						//错误模式		
							dis_smg[0]=DisplayNum[0xe];					//显示"E"
							dis_smg[1]=DisplayNum[0xe];         //显示"E"
							dis_smg[2]=DisplayNum[0xe];         //显示"E"
							dis_smg[3]=DisplayNum[0xe];         //显示"E"
			break;
			default	:	
			break;
		}
		DisplayScan();		//数码管动态扫描
	}
}

Summary:
Some variables are defined:

Mode is an 8-bit unsigned integer used to store the current mode (0-4).
Read_AD is an 8-bit unsigned integer used to store the read value of the ADC (Analog to Digital Converter).
VIN is a 16-bit unsigned integer used to store voltage values.
RIN is a 16-bit unsigned integer used to store the resistance value.
IIN is a 16-bit unsigned integer used to store the current value.
i is a 16-bit unsigned integer used for counting.
The main loop (while(1)) will keep running unless there is an interruption or exception that stops it.

Inside the loop, the Mode is set based on the state of the key. Three conditional judgment statements are used here:

If Key_V is equal to 0 (indicating that the voltage button is pressed), check whether the other two buttons are also pressed. If so, set Mode to 4 (error mode), otherwise set Mode to 1 (voltage mode).
If Key_R is equal to 0 (indicating that the resistive button is pressed), the same check process, if the other two buttons are not pressed, set Mode to 4, otherwise set Mode to 2 (resistive mode).
If Key_I is equal to 0 (indicating that the current button is pressed), the same check process, if the other two buttons are not pressed, set Mode to 4, otherwise set Mode to 3 (current mode).
If no keys are pressed, set Mode to 0 (idle mode).
The function Adc0832(0) is used when reading the ADC value, which may be a hardware-related function used to read data from the ADC device.

The counter is reset after every 300 read operations so that counting starts over.

Perform different operations according to different Modes:

In idle mode, turn off the display of the digital tube and stop the sound output.
In voltage mode, the voltage is calculated based on the value read from the ADC and displayed on the digital tube. If the voltage is greater than 160V, an alarm sound will sound.
In resistance mode, the resistance is calculated based on the value read from the ADC and displayed on the digital tube. If the resistance is greater than 1000, "-" will be displayed in the hundreds, tens and units digits.

4. Design information content list & download address

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

0. Common usage problems and solutions – a must-read! ! ! !
1. Simulation
2. Code
3. Explanation video 4.
Functional requirements
5. Design report 6.
Software and hardware block diagram
Altium Designer software information
KEIL software information
Proteus software information
Double-click to open more 51 STM32 microcontroller design.url

img

Data download link (clickable):

Guess you like

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