STC12C5A60S2 AD conversion details

Publisher:BlissfulSunriseLatest update time:2019-03-14 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

#includeadc .h>

 

/*

--------------------------------------------------

    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:Interpretation of NEC MCU 0527 Series Programming
Next article:STC89C52RC MCU realizes serial port printing function

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号