1

Тема: atmega16 ADC

int u;

void setup() {
   Serial.begin(9600);
   ADMUX |= (1<<MUX0)|(1<<REFS0);// ADC1 (PA1) PIN 36 input
   ADCSRA |= (1<<ADEN) | (1<<ADSC) | (1<<ADATE);
   ADCSRA |= (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);// Division Factor 128
}

void loop() {
  while((ADCSRA & (1 << ADIF)) == 0);
   u = (ADCL|ADCH << 8);
   Serial.println(u);
   delay(500);  
}

2

Re: atmega16 ADC

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей

long u;
byte minus;

void setup() {
  lcd.init();                     
  lcd.backlight();// Включаем подсветку дисплея
  
  
   Serial.begin(9600);
   ADMUX |= (1<<MUX4);//|(1<<ADLAR);
   ADMUX |= (1<<REFS0)|(1<<REFS1);
   ADCSRA |= (1<<ADEN) | (1<<ADSC) | (1<<ADATE);
   ADCSRA |= (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);// Division Factor 128
}

void loop() {
  while((ADCSRA & (1 << ADIF)) == 0);
   u = (ADCL|ADCH << 8);
   if((u>>9)==1){minus=1;}else{minus=0;}
   if(minus==1){lcd.setCursor(0, 0);lcd.print("-");lcd.print(2560*(u-511)/511);lcd.print(" mV      ");}
    else{lcd.setCursor(0, 0);lcd.print(2560*u/511);lcd.print(" mV      ");}

   delay(1000);  
}

3

Re: atmega16 ADC

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей

  
long u;

void setup() {
   lcd.init();                     
   lcd.backlight();// Включаем подсветку дисплея
   ADMUX |= (1<<MUX0)|(1<<REFS0)|(1<<REFS1);
   ADCSRA |= (1<<ADEN) | (1<<ADSC) | (1<<ADATE);
   ADCSRA |= (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);// Division Factor 128
}

void loop() {
  while((ADCSRA & (1 << ADIF)) == 0);
   u = (ADCL|ADCH << 8);
   lcd.setCursor(0, 0);lcd.print(2560*u/1023);lcd.print(" mV        ");
   delay(500);  
}