Application of AD inside STC series microcontroller

Publisher:滁州鱼儿Latest update time:2016-10-04 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Application of AD inside STC series MCU - guluyili - guluyili's blog

 

         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 TA = 0xC6; //A/D conversion result register

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 TA = 0;

         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 TA); // Return A/D conversion result

}

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

Reference address:Application of AD inside STC series microcontroller

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

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号