finished 4.b1

This commit is contained in:
Sem van der Hoeven
2021-03-03 11:55:41 +01:00
parent bd2a5e6091
commit 3196b86762
2 changed files with 12 additions and 3 deletions

View File

@@ -47,7 +47,6 @@ ISR( TIMER2_OVF_vect ) {
int length = snprintf(NULL, 0, "%d", number + 1);
char str[length + 1];
snprintf(str, length + 1, "%d", number + 1);
lcd_write_string(str);
}

View File

@@ -30,11 +30,19 @@ void wait( int ms )
}
// Initialize ADC: 10-bits (left justified), free running
// Initialize ADC: 10-bits (left justified), no free running
void adcInit( void )
{
sei(); // enable interrupts
ADMUX = 0b01100011; // AREF=VCC, result left adjusted, channel3 at pin PF3
ADCSRA = 0b11100110; // ADC-enable, no interrupt, start, free running, division by 64
ADCSRA = 0b10001110; // ADC-enable, start conversion mode, no free running, interrupt enable
}
/************************************************************************/
/* starts AD converstion by setting bit 6 in ADCSRA to 1 */
/************************************************************************/
void startConversion(void) {
ADCSRA |= BIT(6);
}
@@ -50,6 +58,8 @@ int main( void )
{
PORTB = ADCL; // Show MSB/LSB (bit 10:0) of ADC
PORTA = ADCH;
startConversion();
wait(100); // every 100 ms (busy waiting)
}
}