ATtiny13A ADC query method usage

Publisher:浅唱梦幻Latest update time:2020-07-13 Source: 51heiKeywords:ATtiny13A  ADC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

void adc_init(void)

{

   ADCSRA = 0x00; //Disable ADC

   ADMUX = 0x03;

   ACSR = 0x80; //Disable analog comparator

   ADCSRB = 0x00;

   ADCSRA = 0x83;

}

uint read_adc(void)

{

   uint temp = 0;

   ADCSRA |= (1 << ADSC); // Enable AD conversion, first conversion, result discarded

   while((ADCSRA & (1 << ADIF)) == 0); //Wait for AD conversion to finish

   ADCSRA |= (1 << ADIF); //Write 1 to clear ADIF, as required by the specification

   ADCSRA |= (1 << ADSC); // Enable AD conversion, second conversion, the result is retained

   while((ADCSRA & (1 << ADIF)) == 0); //Wait for AD conversion to finish

   ADCSRA |= (1 << ADIF);

   temp = ADCL;

   temp |= (int)(ADCH << 8);

   

   return temp;

}

Keywords:ATtiny13A  ADC Reference address:ATtiny13A ADC query method usage

Previous article:ATtiny13A ADC interrupt usage
Next article:ATtiny13A EEPROM read and write functions

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号