AD Wandler ungenau

OP #870592
Lesenswert?
• ▲
▼
Guckst du hier...ist ne simple LED Kette am PORTA die sich mit Erhöhung 
der Spannung AM AD Wandler verändert:

#define TRUE 1
#define FALSE 0
#define F_CPU 800000UL

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/eeprom.h>
#include <stdlib.h>
#include <util/delay.h>
int main (void)

{
int a;
DDRA = 0xff;
DDRB = 0x00;


ADMUX = 0b00101001;
ADCSR = 0xc5;

while(1)

{
loop_until_bit_is_clear(ADCSR,ADSC);

a = ADCH;


  {
    if (a>00&& a<31)
    PORTA = 0b00000001;

    if (a>32 && a<63)
    PORTA = 0b00000010;

    if (a>64 && a<95)
    PORTA = 0b00000100;

    if (a>96 && a<127)
    PORTA = 0b00001000;

    if (a>128 && a<159)
  PORTA = 0b00010000;

    if (a>160 && a<191)
    PORTA = 0b00100000;

    if (a>192 && a<223)
    PORTA = 0b01000000;

    if(a>224)
    PORTA = 0b10000000;
 }

ADCSR |= (1<<ADSC); //sbi(ADCSR,ADSC);
_delay_ms(10);
}
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren