c8051f850 ADC Polling Example

Source: Internet
Author: User

There are projects that need to use Silabs's c8051f850. In fact, the most important is to fancy the price, as well as its working temperature. So we need to start learning this film. The simplest ADC routines are as follows:

Initializes the system clock, initializes the IO, and so on. The P1.0 is led output and the P1.2 is the ADC input. The ADC uses VDD and GND as the reference source. and use polling in a way that is not interrupted.

void c8051f850_io_initial (void) {//disable Watchdog with key sequence WDTCN = 0xDE;        WDTCN = 0xAD; Using internal 24.5MHz RC oscillator, and no division Clksel = Clksel_clksl__hfosc |        Clksel_clkdiv__sysclk_div_1; GPIO initial P0mdout = P0mdout_b0__open_drain | P0mdout_b1__open_drain | P0mdout_b2__open_drain | P0mdout_b3__open_drain | P0mdout_b4__push_pull | P0mdout_b5__open_drain | P0mdout_b6__open_drain |        P0mdout_b7__open_drain; P1.0 LED output, P1.2 ADC input p1mdout = P1mdout_b0__push_pull | P1mdout_b1__open_drain | P1mdout_b2__open_drain | P1mdout_b3__open_drain | P1mdout_b4__open_drain | P1mdout_b5__open_drain | P1mdout_b6__open_drain |        P1mdout_b7__open_drain; P1.2 alalog ADC Input p1mdin = P1mdin_b0__digital | P1mdin_b1__digital | P1mdin_b2__analog | P1mdin_b3__digital | P1mdin_b4__digital | P1mdin_b5__digital | P1mdin_b6__digital |        P1mdin_b7__digital; P1skip = p1skip_b0__not_skipped | p1skip_b1__not_skipped | P1skip_b2__skipped | p1skip_b3__not_skipped | p1skip_b4__not_skipped | p1skip_b5__not_skipped | p1skip_b6__not_skipped |        p1skip_b7__not_skipped; CrossBar initial XBR0 = xbr0_urt0e__enabled | xbr0_spi0e__disabled | xbr0_smb0e__disabled | xbr0_cp0e__disabled | xbr0_cp0ae__disabled | xbr0_cp1e__disabled | xbr0_cp1ae__disabled |        xbr0_syscke__disabled; XBR2 = xbr2_weakpud__pull_ups_enabled |        xbr2_xbare__enabled;        ADC initial adc0mx = ADC0MX_ADC0MX__ADC0P10; ADC0CF = (1 << adc0cf_adsc__shift) | Adc0cf_ad8be__normal | adc0cf_adgn__gain_1 |        Adc0cf_adtm__track_normal;    ADC enable and start by writing adbusy Adc0cn0 &= ~adc0cn0_adcm__fmask; Adc0cn0 |= adc0cn0_aden__enabled |        Adc0cn0_adcm__adbusy; Voltage Reference Control REF0CN = Ref0cn_refsl__vdd_pin | REF0CN_IREFLVL__2P4 | Ref0cn_gndsl__gnd_pin |        ref0cn_tempe__temp_disabled; Interrupt, all Interrupt disabled EIE1 = eie1_eadc0__disabled | eie1_ecp0__disabled | Eie1_ecp1__disabled | eie1_emat__disabled | eie1_epca0__disabled | eie1_esmb0__disabled | eie1_et3__disabled | eie1_ewadc0__disabled;}

The following calls are in the main function:

void Main (void) {    c8051f850_io_initial ();        while (1)    {        unsigned long Delay = 60000;        while (delay--);                Adc0cn0_bit. Ad0busy = 1; ADC start by Soft Trigger while         (adc0cn0_bit. Ad0int = = 0); Wait for ADC complate        adc0cn0_bit. Ad0int = 0; Clear ADC Flag                adcvalue = adc0h;        Adcvalue = Adcvalue << 8;        Adcvalue = adc0l;                if (Adcvalue < +)        {            if (LED1) LED1 = 0;            else LED1 = 1;        }        else        {                    }}}    


The above code is written based on IAR for 8051.



c8051f850 ADC Polling Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.