The STC89LE516AD/X2 in the STC series of microcontrollers provides 8-channel 8-bit high-speed A/D converters, located on the P1 port, thus eliminating the trouble of an off-chip ADC. These 8-channel ADCs are voltage input type and can be used for key scanning, battery voltage detection, spectrum detection, etc. The ADC conversion process requires 17 machine cycles. By properly configuring the relevant function registers, its operation can be controlled. The following is an introduction to the relevant function registers.
A/D conversion register summary table:
(1) P1_ADC_EN: Special Function Register
P1.x is used as an A/D conversion input channel to enable the special function register. When the corresponding bit is "1", the corresponding P1.x port is used as an A/D conversion and the internal pull-up resistor is automatically disconnected.
ADC_START is the analog /digital conversion (ADC) start control bit. When it is set to 1, the conversion starts.
ADC_FLAG is the analog/digital conversion end flag. When the A/D conversion is completed, ADC_FLAG=1.
(3) ADC_DATA: A/D conversion result special function register
The calculation formula for analog/digital conversion result is Result = 256 × Vin/Vcc
Vin is the input voltage of the analog input channel, Vcc is the actual working voltage of the microcontroller , and the microcontroller working voltage is used as the analog reference voltage.
Built-in ADC usage routine:
STC_ADC.h:
sfr P1_ADC_EN=0x97;
sfr ADC_CONTR = 0xc5;
sfr ADC_DATA=0xc6;
int GetAD(unsigned char channel) //channel is the channel number to be retrieved (0~7)
{
unsigned char AD_finished=0;
ADC_DATA=0;
ADC_CONTR=channel;
ADC_CONTR|=0x08;
while(!AD_finished)
AD_finished=(ADC_CONTR&0x10);
ADC_CONTR&=0xF7;
return (ADC_DATA);
}
void AD_Init(unsigned char ADin) // ADC initialization, ADin is an eight-bit binary number, corresponding to AD7~0 respectively, and setting 1 means opening this path
{
P1=P1|ADin; //To set the P1.x port for A/D conversion, first set it to high
P1_ADC_EN=ADin;
}
_main.c:
#include
#include
/*
--------------------------------------------------
This program is used to illustrate the use of STC microcontroller ADC
--------------------------------------------------
*/
void delay(unsigned time)
{
while(time--);
}
void main()
{
AD_Init(0x63); //0110,0011, to set the P1.x port for A/D conversion, first set it to high
//0110,0011,P1's P1.0,P1.1,P1.5,P1.6 are set as A/D conversion input pins
//Disconnect the internal pull-up resistors of P1.0, P1.1, P1.5, and P1.6
while(1)
{
P2=GetAD(0);
delay(10000);
P2=GetAD(1);
delay(10000);
P2=GetAD(5);
delay(10000);
P2=GetAD(6);
delay(10000);
}
}
Previous article:Interpretation of NEC MCU 0527 Series Programming
Next article:STC89C52RC MCU realizes serial port printing function
- 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
- 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
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- BQ40Z50-R2 security mode introduction and password modification method
- msp430f1232 minimum system and debugging process
- Smart warehouse based on Gizwits AIoT development platform
- [RT-Thread Reading Notes] Part 2 (5) Interrupt Management and Bidirectional Linked List
- Analysis of the three major architectural elements of RF signal sources
- MSP430 microcontroller and medical reference design
- 1.4 billion Chinese women can't pick out 11 men's soccer teams that can win
- Analysis Method of Transistor Bias Circuit
- Zhengzhou flood: did the disaster recovery mechanism of the communication network work?
- Solving High-Temperature Isolation Design Challenges Using Grade 0 Digital Isolators