foxbrain
Full Member level 2
thanks alexan that was it ...
but i made the changes and it still didn't work the led is lightning in all cases & all the time.
i think i found the error:
i rewrite the code to this:
i made the conversation goes too slowly by making the division factor = 8...
so while converting a led in port d,1 will be lightning on and off
and then if the Vcc < 3.5 another led on portd,5 will light otherwise it will turn off....
but what is happening is that nothing is lightning at all since i power the MCU it should at least light the led D,1 on and off for once....
So is the problem that the MCU isn't converting at all?!?!?!?!
but i made the changes and it still didn't work the led is lightning in all cases & all the time.
i think i found the error:
i rewrite the code to this:
Code:
#include <util/delay.h>
#include <avr/io.h>
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
int main(void)
{
float vcc,adc;
DDRD=0xFF;
PORTD=0x00;
ADMUX=0b00011110;
ADCSRA = (1<<ADEN)|(0<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); // prescaler = 8
while(ADCSRA&(1<<ADSC))
{
SETBIT(PORTD,1);
_delay_ms(1000);
CLEARBIT(PORTD,1);
_delay_ms(1000);
} //wait for convertion to complete
adc=ADC;
vcc = 1.22 * 255 /adc;
if(vcc<3.5)
SETBIT(PORTD,5);
else CLEARBIT(PORTD,5);
}
so while converting a led in port d,1 will be lightning on and off
and then if the Vcc < 3.5 another led on portd,5 will light otherwise it will turn off....
but what is happening is that nothing is lightning at all since i power the MCU it should at least light the led D,1 on and off for once....
So is the problem that the MCU isn't converting at all?!?!?!?!