1

Тема: lgt8f328 ADC diff

void setup() {
  Serial.begin(9600);
  ADCSRD |= 1 << REFS2;// REF 4.096
  VCAL = 30;
  ADCSRA |= 1 << ADEN | 1 << ADSC | 1 << ADATE | 0b111;
}

void loop() {  
  ADMUX = 0b11;DAPCR = 0;
  DAPCR |= 1 << DAPEN | 0b11001;
  while((ADCSRA & (1 << ADIF)) == 0);
     int u_data0 = (ADCL|ADCH << 8);
 // Serial.println(u_data0);
  delay(500);
  ADMUX = 0b00;DAPCR = 0;
  DAPCR |= 1 << DAPEN | 0b00111;
  while((ADCSRA & (1 << ADIF)) == 0);
     int u_data1 = (ADCL|ADCH << 8);
 // Serial.println(u_data1);

  Serial.println(float(u_data0-u_data1)/1000);
  Serial.println();
  delay(500);
}