mshh
Full Member level 6
- Joined
- May 30, 2010
- Messages
- 349
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,296
- Location
- usa
- Activity points
- 3,871
I want to make analoge to digital on atmega8 using avrstudio i wrote code but wheen i simulate on proteus the Leds are always high and didn't change
please help
please help
Code:
#ifndef F_CPU
#define F_CPU 8000000UL // or whatever may be your frequency
#endif
#include <avr/io.h>
#include <util/delay.h>
void adc_init(void)
{
ADCSRA=0x85; //ENABLE ADC, PRESCALER 128
ADMUX=0x00; //PC0, AVcc AS REFERENCE VOLTAGE
}
uint16_t adc_read()
{
adc_init;
while((ADCSRA)&(1<<ADSC)); //WAIT UNTIL CONVERSION IS COMPLETE
return(ADC); //RETURN ADC VALUE
}
int main(void)
{
uint16_t adc_value;
DDRD=0xff;
while(1)
{
adc_init(); //INITIALIZE ADC
adc_value=adc_read(0); //READ ADC VALUE FROM CHANNEL 0
PORTD=ADC;
}
}