STC12C5A60S2 ADC query method

Publisher:创新驿站Latest update time:2019-05-22 Source: eefocusKeywords:STC12C5A60S2  ADC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*------------------------------------------------------------------*/
/* --- STC MCU Limited ---------------------------------------------*/
/* --- STC12C5Axx Series MCU A/D Conversion Demo -------------------*/
/* --- Web: www.STCMCU.com -----------------------------------------*/
/* If you want to use the program or the program referenced in the  */
/* article, please specify in which data and procedures from STC    */
/*------------------------------------------------------------------*/


#include "reg51.h"
#include "intrins.h"


#define FOSC    18432000L
#define BAUD    9600


typedef unsigned char BYTE;
typedef unsigned int WORD;


/*Declare SFR associated with the ADC */
sfr ADC_CONTR   =   0xBC;           //ADC control register
sfr ADC_RES     =   0xBD;           //ADC high 8-bit result register
sfr ADC_LOW2    =   0xBE;           //ADC low 2-bit result register
sfr P1ASF       =   0x9D;           //P1 secondary function control register


/*Define ADC operation const for ADC_CONTR*/
#define ADC_POWER   0x80            //ADC power control bit
#define ADC_FLAG    0x10            //ADC complete flag
#define ADC_START   0x08            //ADC start control bit
#define ADC_SPEEDLL 0x00            //420 clocks
#define ADC_SPEEDL  0x20            //280 clocks
#define ADC_SPEEDH  0x40            //140 clocks
#define ADC_SPEEDHH 0x60            //70 clocks


void InitUart();
void InitADC();
void SendData(BYTE dat);
BYTE GetADCResult(BYTE ch);
void Delay(WORD n);
void ShowResult(BYTE ch);


void main()
{
    InitUart();                     //Init UART, use to show ADC result
    InitADC();                      //Init ADC sfr
    while (1)
    {
        ShowResult(0);              //Show Channel0
        ShowResult(1);              //Show Channel1
        ShowResult(2);              //Show Channel2
        ShowResult(3);              //Show Channel3
        ShowResult(4);              //Show Channel4
        ShowResult(5);              //Show Channel5
        ShowResult(6);              //Show Channel6
        ShowResult(7);              //Show Channel7
    }
}


/*----------------------------
Send ADC result to UART
----------------------------*/
void ShowResult(BYTE ch)
{
    SendData(ch);                   //Show Channel NO.
    SendData(GetADCResult(ch));     //Show ADC high 8-bit result


//if you want show 10-bit result, uncomment next line
//    SendData(ADC_LOW2);             //Show ADC low 2-bit result
}


/*----------------------------
Get ADC result
----------------------------*/
BYTE GetADCResult(BYTE ch)
{
    ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ch | ADC_START;
    _nop_();                        //Must wait before inquiry
    _nop_();
    _nop_();
    _nop_();
    while (!(ADC_CONTR & ADC_FLAG));//Wait complete flag
    ADC_CONTR &= ~ADC_FLAG;         //Close ADC


    return ADC_RES;                 //Return ADC result
}


/*----------------------------
Initial UART
----------------------------*/
void InitUart()
{
    SCON = 0x5a;                    //8 bit data ,no parity bit
    TMOD = 0x20;                    //T1 as 8-bit auto reload
    TH1 = TL1 = -(FOSC/12/32/BAUD); //Set Uart baudrate
    TR1 = 1;                        //T1 start running
}


/*----------------------------
Initial ADC sfr
----------------------------*/
void InitADC()
{
    P1ASF = 0xff;                   //Open 8 channels ADC function
    ADC_RES = 0;                    //Clear previous result
    ADC_CONTR = ADC_POWER | ADC_SPEEDLL;
    Delay(2);                       //ADC power-on and delay
}


/*----------------------------
Send one byte data to PC
Input: dat (UART data)
Output:-
----------------------------*/
void SendData(BYTE dat)
{
    while (!TI);                    //Wait for the previous data is sent
    TI = 0;                         //Clear TI flag
    SBUF = dat;                     //Send current data
}


/*----------------------------
Software delay function
----------------------------*/
void Delay(WORD n)
{
    WORD x;


    while (n--)
    {
        x = 5000;
        while (x--);
    }
}

Keywords:STC12C5A60S2  ADC Reference address:STC12C5A60S2 ADC query method

Previous article:Use of printf function in keil2
Next article:STC12C5A60S2 ADC interrupt mode

Recommended ReadingLatest update time:2024-11-16 20:23

pic16 multi-channel adc sampling
#define FUEL 0X23 //Oil sensor 2 fuel an8 00100011     #define TEMP 0x1f //Oil sensor 2 temperature an7 00011111     #define POWER 0X11 //Oil sensor 2 voltage an6 00011011  Related ports are initialized as input unsigned int get_ad(unsigned char n) {     unsigned int value;        ADCON0 = n ;         ADCON1=0XE0;//
[Microcontroller]
5GHz Differential Amplifier Drives Gigasample ADC with Only 60mA Quiescent Current
-- Analog Devices' ADA4960-1 differential amplifier is the industry's first amplifier capable of driving 8-bit linearity, 1 GHz data converter signals.     Beijing, May 28, 2010 - Analog Devices, Inc. (NYSE: ADI), a global leading supplier of high-performance signal processing solutions and a leader in amplifier and
[Analog Electronics]
Teledyne e2v EV10AS940: Revolutionizing Microwave ADCs
EV10AS940In today's rapidly developing technology, high-speed data acquisition and processing capabilities are key to driving innovation. Teledyne e2v's latest masterpiece, the EV10AS940, is an advanced microwave analog-to-digital converter (ADC) that can meet the needs of high-speed data acquisition. This 1
[Analog Electronics]
Teledyne e2v EV10AS940: Revolutionizing Microwave ADCs
Op Amp Design in High-Performance Analog Front Ends
High-speed conversion systems, especially those in the telecommunications field, allow analog-to-digital converter (ADC) input signals to be AC-coupled (by utilizing transformers, capacitors, or a combination of both). But for the test and measurement industry, front-end design is not so simple because in addition to
[Analog Electronics]
STM8 ADC timing diagram
STM8 ADC timing diagram As shown in Figure 149, after the ADC is powered on, the ADC needs a stabilization time tSTAB (equal to the time tCONV for one conversion) before starting accurate conversion. No stabilization delay is required for subsequent conversions, and the ADON bit only needs to be set once. One ADC conv
[Microcontroller]
STM8 ADC timing diagram
How Texas Instruments helps the world's largest radio telescope achieve precision and synchronization
Once we develop high-speed data conversion and time synchronizers, engineers and scientists can build the world’s largest array of radio telescopes, giving the world more deep-space data than ever before. In 2018, Dr. Krzysztof Caputa faced a daunting challenge: The astronomical instrumentation project he led for Ca
[Analog Electronics]
How Texas Instruments helps the world's largest radio telescope achieve precision and synchronization
ADC front-end design popular science post - a preliminary study of ADC sampling front-end model
Preface In actual applications, ADC often fails to achieve the nominal accuracy and suffers from severe waveform distortion. This phenomenon has long troubled our hardware engineers. So, why does this happen in actual ADC applications? Here, I will use an example to discuss with you the problems that ADC may enco
[Analog Electronics]
ADC front-end design popular science post - a preliminary study of ADC sampling front-end model
High integration and low cost demand drive signal chain design
Industry analysts agree that portability, "green" energy saving and the integration of more sensors in terminal devices are system development trends. These trends drive the demand for high channel count, high speed and high performance of analog-to-digital converters (ADCs) and digital-to-analog converters (DACs),
[Medical Electronics]
High integration and low cost demand drive signal chain design
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号