The 0-99V digital voltmeter made with STC12C2052AD microcontroller comes from Digital Home_abenyao. I think this circuit is quite useful. The principle is simple. It directly uses the AD with STC12C2052AD microcontroller. The digital tube uses a four-digit common anode digital tube. There is a little jump after the decimal point. The circuit is built on a breadboard. The reference voltage is generated by TL431. The following is a real picture:
Keywords:STC12C2052AD
Reference address:0-99V digital voltmeter made with STC12C2052AD microcontroller
*************************************************** ********************* 0-99V digital voltmeter source program made with STC12C2052AD microcontroller First published by Digital Home. ID: abenyao P1.6 port is 0-5V analog input terminal, P1.5 port is connected to 2.5V reference power supply output by TL431l, 4-bit serial LED digital tube display *************************************************** ************************/ #include//MCU header file #include //51 basic operations (including _nop_ empty function) #define uchar unsigned char #define uint unsigned int #define LEDBus P3 //a3.0-b3.1-c3.2-d3.3-e3.4-f3.5-g3.7-dp1.0 #define ON 1 //define 0 as on #define OFF 0 //define 1 to turn off sbit ge=P1^4; //bit selection sbit shi=P1^3; //Tens bit selection sbit bai=P1^2; //hundreds digit selection sbit qian=P1^1; //Thousands digit selection sbit db=P1^0; char d[5]; uint R,M,N; //If defined as uchar type, it can only display values below 2.5V uchar code LEDTab[]={0xc0,0xf9,0x64,0x70,0x59,0x52,0x42,0xf8,0x40,0x58}; /****************************************************** **************** Function name: millisecond CPU delay function Call: delay (?); Parameter: 1~65535 (parameter cannot be 0) Return value: None Result: The CPU usage delay is the same as the parameter value in milliseconds Note: When applied to 1T MCU, i<600; when applied to 12T MCU, i<125 /****************************************************** *******************/ void delay(uint t) { uint i; //define variables for(;t>0;t--) //If t is greater than 0, t minus 1 (outer loop) for(i=600;i>0;i--); //i is equal to 124, if i is greater than 0, i minus 1 } /****************************************************** ****************** Function name: ADC initialization and 8-bit A/D conversion function Return value: 8-bit ADC data Result: Read the A/D conversion value of the specified ADC interface and return the value Note: Applicable to STC12C2052AD series MCU (must use STC12C2052AD.h header file) *************************************************** *******************/ uchar Read (uchar CHA) { uchar AD_FIN=0; //Store A/D conversion flag; if this variable is defined outside the function, the display of continuously changing analog quantity cannot be obtained /******The following is the ADC initialization program********************************/ CHA &= 0x07; //Select one of the 8 interfaces of ADC (0000 0111 clear the high 5 bits) ADC_CONTR = 0x60; //ADC conversion speed (0XX0 0000, XX controls the speed, please set according to the data sheet) _nop_(); ADC_CONTR |= CHA; //Select the current A/D channel _nop_(); ADC_CONTR |= 0x80; //Start A/D power supply delay(1); //Let the input voltage reach stability (1ms is enough? /******The following is the ADC execution program********************************/ ADC_CONTR |= 0x08; //Start A/D conversion (0000 1000 ADCS = 1) _nop_(); _nop_(); _nop_(); _nop_(); while (AD_FIN ==0){ //Wait for A/D conversion to end AD_FIN = (ADC_CONTR & 0x10); //0001 0000 Test whether A/D conversion is finished } ADC_CONTR &= 0xE7; //1111 0111 clear ADC_FLAG bit, turn off A/D conversion, return (ADC_DATA); //Return A/D conversion result (8 bits) } /****************************************************** ***************** Displays the function conversion function: M = analog sampling value, N = reference voltage source sampling value (2.5V in this example), R = analog input value (to be displayed) N=256*2.5/Vcc; after deformation, Vcc=256*2.5/N; Substitute M=256*R/Vcc; get M=R*N/2.5; after deformation, R=M*2.5/N 1.105 is the voltage divider ratio at the input. *************************************************** ****************/ void transfer(void){ M=Read(6); //P1.6 port analog conversion N=Read(5); //P1.5 port 2.5V reference voltage source sampling (conversion) R=((M*2.5)/N)*1.105*1000; //Convert the input analog quantity and amplify it 1000 times; /***The following is a 3-digit display conversion***/ d[3]=R/1000; R=R%1000; d[2]=R/100; R=R%100; d[1]=R/10; d[0]=R%10; } /**********Display function (not optimized)****************************************************/ void xian_shi (void) { LEDBus=LEDTab[d[0]]; //Send the unit digit to the digital tube for display ge=ON; //Open the unit digit selection delay(2); //1 means display for 1 millisecond, 0 shortens the display time and reduces the brightness by half ge=OFF; //Close the ones digit selection LEDBus=LEDTab[d[1]]; //The ten digit is sent to the digital tube for display shi=ON; //Open the tens digit selection delay(2); //1 means display for 1 millisecond, 0 shortens the display time and reduces the brightness by half shi=OFF; //Disable the tens digit selection LEDBus=LEDTab[d[2]]; //Hundreds digit is sent to digital tube for display bai=ON; //Open the hundreds digit selection db=0; //Display decimal point delay(2); //1 means display for 1 millisecond, 0 shortens the display time and reduces the brightness by half bai=OFF; //Disable hundreds digit selection db=1; //Turn off decimal point display LEDBus=LEDTab[d[3]]; //Thousands digit is sent to digital tube for display qian=ON; //Open the thousands digit selection delay(2); //1 means display for 1 millisecond, 0 shortens the display time and reduces the brightness by half qian=OFF; //Close the thousands digit selection } /****************************************************** ***************** Function name: main function Call: None Parameters: None Return value: None Result: Infinite loop at the beginning of the program Remark: *************************************************** ****************/ void main (void) { P1M0 = 0x60; //P1.0/P1.1: 0000 0011 (high impedance) //Note: When changing the ADC channel, the corresponding IO interface must also be changed to high impedance input. P1M1 = 0x00; //P1.0/P1.1: 0000 0000 while(1){ uchar i; delay(1); i++; if (i==30) { transfer(); i=0; } xian_shi(); //delay(10); } }
Previous article:The unknown mystery of 51 MCU's IO port
Next article:Electronic clock based on AT89C51
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- A New Decision Feedback Equalizer Architecture Based on FPGA
- Reply and give points: 5G is coming, will you change to a 5G mobile phone?
- Application of ultra-high threshold voltage depletion-mode MOSFET DMZ0615E in mobile phone fast charging
- Forum member long521's niece is sick, please help her!
- EEWORLD University ---- Application of Weidmuller products in the semiconductor industry
- How to minimize the cost of low-power AC/DC circuits?
- The water hydrogen engine has officially rolled off the production line. The vehicle can run just by adding water???
- Linear thyristor power supply dimming and EMC issues
- Synopsys IP Resources: A look at the complete Ethernet PHY IP for high-performance computing SoCs
- [National Technology N32 MCU Development Package] --N32G4FR Series