The ADC0832 voltmeter simulation schematic is as follows
The source program of the microcontroller voltmeter is as follows:
#include #include #define uint unsigned int #define uchar unsigned char sbit CS =P3^4; //Chip select enable terminal sbit DI =P1^1; //Data signal input terminal, select channel control (SIG/DIF and ODD/EVEN) sbit DO =P1^1; //data output terminal sbit CLK =P1^0; //clock pulse sbit S_1 = P2^3; sbit S_2 = P2^4; sbit S_3 = P2^5; sbit S_4 = P2^6; unsigned char wd[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //Segment selection code without decimal point unsigned char yd[]={0x40,0x79,0x024,0x30,0x19,0x12,0x02,0x78,0x00,0x10}; //segment selection code with decimal point // ===========Delay subroutine================== void delay_ms(unsigned int x) { unsigned int i,j; for(i=0;i } /*==============Read ADC0832 function==============*/ /*=============Collect and return=================*/ unsigned int Adc0832(unsigned char channel) //AD conversion, return result { fly i=0; flying j; uint dat=0; //Forward input data uchar ndat=0; //Reverse input data //****************Initialization operation************** if(channel==0)channel=2; //10B对应SGL/DIF=1,ODD/EVEN=0 if(channel==1)channel=3; //11B对应SGL/DIF=1,ODD/EVEN=1 //****************write operation, write channel data to ADC0832************** DI=1; _nop_();_nop_(); //Send start bit, fixed to 1 (1 bit) CS=0;_nop_();_nop_(); //Pull the CS terminal low to enable ADC0832 CLK=1;_nop_();_nop_(); //Pull up the CLK terminal, and the data at the DI terminal will be moved into the multi-channel shift register inside ADC0832 CLK=0;_nop_();_nop_(); //Pull the CLK end low to form a falling edge 1, and the first cycle begins CLK=1; //Pull up the CLK terminal. In the first clock cycle, DI is high, indicating the start position. // Then enter two configuration bits for channel selection DI=channel&0x1;_nop_();_nop_(); //Assuming channel 0 is selected, 10&01=0, that is, SGL/DIF=0, which is differential input (2 bits) CLK=0;_nop_();_nop_(); //Pull the CLK end low to form falling edge 2, and the second cycle begins CLK=1; //Pull up the CLK terminal DI=(channel>>1)&0x1;_nop_();_nop_(); //Assuming channel 0 is selected, 01&01=1, ODD/EVEN=1, indicating channel 0 CLK=0; //Pull down the CLK end to form a falling edge 3 DI=1;_nop_();_nop_(); //Control command ends that=0; //****************Read operation, output the AD converted number from DO port**************** for(i=0;i<8;i++) //Output a digit at each falling edge of CLK, output the high digit first { dat|=DO; //Receive data, “|” bit OR, if one of the two bits is 1, the result is 1, otherwise it is 0 CLK=1;_nop_();_nop_(); CLK=0;_nop_();_nop_(); //Form a clock pulse dat<<=1; if(i==7)dat|=DO; } for(i=0;i<8;i++) //Output a digit at each falling edge of CLK, output the low digit first { j=0; j=j|DO; //Receive data CLK=1;_nop_();_nop_(); CLK=0;_nop_();_nop_(); //Form a clock pulse j=j<<7; ndat=ndat|j; if(i<7)ndat>>=1; } //*********************End AD conversion and return the converted number*********************** CS=1; //Pull the CS terminal low CLK=0; //Pull the CLK terminal low DO=1; //Pull the data terminal high and return to the initial state dat<<=8; that|=ndat; return(dat); //Return data } //============Digital tube display function=========================== void display(uchar p) //digital tube display function { uchar S1,S2,S3; S1=p/51; //unit digit S2=(p*10/51)%10; //tenth place S3=(p*100/51)%10; //percentile //units S_1 = 1; //The first digital tube S_2 = 0; S_3 = 0; S_4= 0; P0=yd[S1]; //Select the segment code with decimal point delay_ms(5); //delay S_1 = 0; //Blanking //tenth place S_1 = 0; S_2 = 1; //Get the second digital tube S_3= 0; S_4= 0; P0=wd[S2]; //Select the segment code without decimal point delay_ms(5); S_2 = 0; //Blanking //Percentile S_1 = 0; S_2 = 0; S_3= 1; //Get the third digital tube S_4= 0; P0=wd[S3]; //Select the segment code without decimal point delay_ms(5); S_3= 0; //Blanking } //===========Main function================ int main(void) { while(1) // infinite loop display(Adc0832(0)); //digital tube display //Adc0832(0): Select channel 0, single-ended mode //Call Adc0832(0), SIG/DIF=0, ODD/EVEN=1, indicating that it works in differential input mode, and CH0 is -, CH1 is + ……………………
Previous article:Single chip fully automatic washing machine program + simulation + schematic design debugging and analysis
Next article:Design report of 4-digit addition calculator based on 51 single chip microcomputer
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- VS1053 cannot read or write registers
- Several interesting GIF animations
- Several issues on the second-order low-pass filter circuit of voltage-controlled voltage source
- EEWORLD University Hall----Live Replay: Application of TI Precision ADC in Transmitter
- BQ40Z50-R2 security mode introduction and password modification method
- [NUCLEO-L552ZE Review] Expansion board ws2812 power supply correction
- Don't stop me, I want to do mpy development!
- TPS23861 48V power supply has a small probability of burning out.
- Free resource download | Five trends driving change in power management
- My Journey of MCU Development (Part 2)