The following example demonstrates the A/D conversion function of the STC89LE516AD/X2 series microcontroller. The clock is 11.0592MHz, and the conversion result is output to the serial port in hexadecimal format. The output result can be observed using the serial port debugger. (This code is taken from the Hongjing Technology chip manual and can run normally after being debugged by the author).
#include
#include
//Define special function registers related to ADC
sfr P1_ADC_EN = 0x97; //A/D conversion function enable register
sfr ADC_CONTR = 0xC5; //A/D conversion control register
sfr ADC_DA
typedef unsigned char INT8U;
typedef unsigned int INT16U;
void delay(INT8U delay_time) // delay function
{
INT8U n;
INT16U m;
for (n=0;n { for(m=0;m<10000;m++); } } INT8U get_AD_result(INT8U channel) { INT8U AD_finished = 0; //Store A/D conversion flag ADC_DA ADC_CONTR = channel; // Select A/D current channel delay(1); //Make the input voltage stable ADC_CONTR |= 0x08; //0000,1000 Set ADC_START = 1 to start A/D conversion AD_finished = 0; while ( AD_finished == 0 ) // Wait for A/D conversion to finish { AD_finished = (ADC_CONTR & 0x10); //0001,0000, ADC_FLAG ==1 Test A/D conversion completion } ADC_CONTR &= 0xF7; //1111,0111 set ADC_START = 0, turn off A/D conversion, return (ADC_DA } void main() { P1 = P1 | 0x63; // 0110,0011, to set the P1.x port for A/D conversion, first set it to high P1_ADC_EN = 0x63; //0110,0011, P1.0, P1.1, P1.5, P1.6 of P1 are set as A/D conversion input pins // Disconnect the internal pull-up resistors of P1.0 and P1.1 get_AD_result(0); //P1.0 is the current channel of A/D get_AD_result(1); //P1.1 is the current channel of A/D
Previous article:How to generate a baud rate of 115200 using a 51 microcontroller + a 11.0592 crystal oscillator?
Next article:AT89C series microcontroller encryption and decryption principle
- 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
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- TI DSP bootloader and online upgrade
- Questions about creating schematic package in Orcad
- EEWORLD University Hall----Live Replay: Dadatong helps you unlock the new generation of ADAS technology
- What are the six axes in a six-axis robot?
- Three-phase sensorless sine wave BLDC drive (MS39549 and MS39545)
- Pre-registration for the prize live broadcast | TI uses DLP micro-projection technology to design augmented reality smart glasses
- Please recommend some technical public accounts and recent thoughts
- Come here to apply for the DFRobot Xingkong board~
- Which one has a 50 ohm impedance matching circuit? Please refer to it.
- (C-Wireless Charging Electric Car) Shaanxi Province First Prize_Topic C_Xi'an University of Electronic Science and Technology