task 1:
a).
#include <avr/io.h>
#include <util/delay.h>
//From util/delay.h use void _delay_ms ( double __ms) ;
int main(int argc , char const * argv [ ] ) {
DDRD = 0b00000001; // Data Direction Register D:
while(1){
PD3 = 0b00000001;
PD7 = 0b00000000;
_delay_ms(500);
PD3 = 0b00000000;
PD7 = 0b00000001;
_delay_ms(500);
}
return 0;
}
b).
Cadmium-Sulfide: It's dependend on the volume of light, as more as
well have a light we get less resistance
we need output voltage to measure the difference between in/decresment light where
if no light than the resistance has full resistance => the output still the same
but if we turn on a light source , then the resistance decreases
the output voltage inverse proportion with the resistance
c).
// in this example we use the last three digits of our immatriculation number to find the TimerFreq
For example ur immatriculation number is: 3103400 -> TimerFreq = 1/400
timerFreq = 1/0.000238s = 4202 HZ
TimerFreq = 20 MHz / pre * top => 4202 Hz = 20MHz / pre * top
top = 20000000 Hz / 4202 Hz * pre
20000000 Hz / 4202 Hz * 1 = 4760 > 255
20000000 Hz / 4202 Hz * 8 = 595 > 255
20000000 Hz / 4202 Hz * 64 = 75 =< 255 no error,
-> pre = 64, top = 75
because with 8 bit we can cover until 11111111 (binary) = 255 (decimal)
d).
(i).
ADMUX =ADC7 // use pin ADC7 as input
ADMUX |= (1 << REFS0); // use AVcc as reference voltage
(ii).
ADCSRA |= (1 << ADEN); // Enable the ADC
ADCSRA |= (1 << ADSC); // Start the ADC conversion
// I don't know what he means with remaining hte ADC interrupt and ADC prescaler setting
unchanged !!
(iii).
while (ADSRA & (1<<ADSC)); //wait for end of conversion
ADCSRA |= (1 << ADIE); // Enable Interrupt