Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
#include <avr/io.h>int main(){ DDRA = 0b00000100; DDRB = 0xff; ADCSR |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // Set ADC prescalar to 128 ADMUX |= (1 << REFS0); // Set ADC reference to AVCC ADMUX |= (1 << ADLAR); // Left adjust ADC result to allow easy 8 bit reading ADMUX |= (1 << MUX0); // Set ADMUX to sample ADC1 ADCSR |= (1 << ADFR); // Set ADC to Free-Running Mode ADCSR |= (1 << ADEN); // Enable ADC ADCSR |= (1 << ADSC); // Start A2D Conversions unsigned char sensor=0; while(1){ sensor = ADCH; PORTB = sensor; if(sensor > 122){ PORTA=0x04; } else { PORTA=0x00; } }}
Does the adc continuously read? if not then youve only told the adc module to read once. everytime you copy the register then you are only copying the initial reading.try puttingADCSR |= (1 << ADSC); // Start A2D Conversionsinside the while loop