#include"STC12C5410AD.h" #define uchar unsigned char unsigned char aa,bb; void delay(uchar dd) { int x,y; for(x=dd;x>0;x--) for(y=100;y>0;y--); } unsigned char Read_ADC(unsigned char adcvcc) { //Set P1.0--P1.1 to a mode suitable for AD conversion ADC_CONTR = ADC_CONTR|0x80; //1000,0000 turns on the A/D conversion power delay(20); //20ms ADC_CONTR = ADC_CONTR&0xE0; //1110,0000 clear ADC_FLAG, ADC_START bit and low 3 bits ADC_CONTR = ADC_CONTR&0xf8|adcvcc; //Set the current channel number delay(10); //Delay to stabilize the input voltage ADC_DATA = 0; //Clear A/D conversion result register ADC_CONTR = ADC_CONTR|0x08; //0000, 1000ADCS = 1, start conversion do { ; } while((ADC_CONTR & 0x10)==0); //0001,0000 wait for the A/D conversion to end ADC_CONTR = ADC_CONTR&0xE7; //1110,0111 clear the ADC_FLAG and ADC_START bits to stop A/D conversion return ADC_DATA; } void main() { //Add the port for setting the ADC, such as)1.0, if P1.1 is set as the ADC port: P1M0 = 0x03; //0000, 0011 is used for the P1.x port of A/D conversion, first set to open drain P1M1 = 0xC3; //0000, 0011P1.0--P1.1 is first set to open drain. Disconnect the internal pull-up resistor bb=0x01; while(1) { aa=Read_ADC(1); //The first A/D conversion channel; if you want to change other channels, just change the substitution channel. P3=aa; //This is to display the A/D data on the LED of the P3 port. } }
Previous article:C51 Functions of ADC0809 Analog-to-Digital Converter
Next article:SRAM external data memory expansion experiment
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- 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
- EEWORLD University Hall ---- FPGA Tips for Ming Deyang
- About GD32E230I2C as a slave
- [Liquid Level Sensor Evaluation] Sensor Performance Comparison (and Final Report)
- Bluetooth Technology Principle
- FIDI: CircuitPython Rapid Prototyping Board
- [Summary] Review and Outlook, Goodbye 2019, Hello 2020!
- The IO port of the microcontroller can generally be set to three states
- Is the solder in the soldering iron toxic?
- What are the benefits of connecting a PNP transistor and a Zener diode in series to control NMOS?
- Recruiting electronics, communications, and computer engineers