STC12C5A60S2 AD conversion details

Publisher:数字之舞Latest update time:2019-05-21 Source: eefocusKeywords:STC12C5A60S2  conversion Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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);

 }

}


Keywords:STC12C5A60S2  conversion Reference address:STC12C5A60S2 AD conversion details

Previous article:STC12C5A60S2 MCU realizes ISP automatic download
Next article:STC12C5A60S2 dual serial port communication

Recommended ReadingLatest update time:2024-11-15 08:22

Realization of online measurement of battery internal resistance based on AD630
introduction The internal resistance of a battery is one of the important parameters that reflect the performance of a battery. Through research, it is found that the capacity and health status of a battery are closely related to the internal resistance. Therefore, online monitoring of the battery through the change
[Test Measurement]
Realization of online measurement of battery internal resistance based on AD630
51 MCU selects analog (AD) input interface
Analog input is often encountered in the design of 51 single-chip microcomputers. The following is the source program for the analog (AD) input interface selection. //-----------------------Analog (AD) input interface selection function declaration, variable definition--------------------------------------------------
[Microcontroller]
AD analog-to-digital conversion thermistor
AD conversion thermistor sensor detection AD value software design main.c function /*  Experimental phenomenon: After downloading the program, the first 4 digits of the digital tube display the AD value detected by the thermal sensor 1. MCU-- AD/DAC module pin interpretation     P34-- DI DIN   serial data input
[Microcontroller]
In-depth understanding of ARM architecture (S3C6410) --- ad conversion example
This example converts the collected ad data and displays it on the LCD screen. Here I paste the debugged source code directly.   Ad converter related code:     view plain copy print ?   void  adc_init()    {                        char  preScaler  =  66500000/2500000  -  1;  //PCLK=66M 
[Microcontroller]
Difficulties in high-speed AD testing
The sampling rate of high-precision ADC is not high, and the key to testing is to have a high-precision signal source. High-speed ADC testing is a more challenging task, in which jitter of the sampling clock and high-speed digital interface are two problems that must be faced. Jitter Problem of Sampling Clock As t
[Test Measurement]
Difficulties in high-speed AD testing
ATmega8+PT100 thermistor+AD824S proteus simulation and source program
The simulation schematic diagram of the temperature measurement system with pt100 thermistor + AD824S amplification and ATmega8 microcontroller control is as follows. The source program of ATmega8 microcontroller is as follows: /***************************************************** This program was produced by the
[Microcontroller]
ATmega8+PT100 thermistor+AD824S proteus simulation and source program
Improved design scheme of phase difference measurement system based on AD8302
The AD8302 phase detection chip launched by ADI of the United States can accurately measure the gain, phase difference and frequency of two independent radio frequency (RF), intermediate frequency (IF) or low frequency signals. However, the measurement range of the phase difference of this chip is only 0°~180°. Brief
[Power Management]
Improved design scheme of phase difference measurement system based on AD8302
Mobile phone battery charger program made by STC12C2052AD microcontroller
Mobile phone battery charger program made by STC12C2052AD microcontroller #include STC12c2052ad.h #include intrins.h #define uchar unsigned char #define uint unsigned int #define AD_SPEED 0x60 //0110,0000 1 1 270 clock cycles to convert once,  //Shaozhanyu production Hebei Zhengding welcomes you Changsha Aviation
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号