m05e00 not so done finally...

This commit is contained in:
hugogogo
2025-03-13 18:57:43 +01:00
parent 7cad1f6776
commit 33ca0f68ed
2 changed files with 4 additions and 3 deletions

View File

@@ -19,7 +19,8 @@ void adc_init(uint8_t prescaler_value) {
uint16_t adc_read(uint8_t channel) {
CLEAR(PRR, PRADC); // 24.3 : ensure power reduction is disabled for ADC, (10.11.3 : PRR Power Reduction Register)
ADMUX = (ADMUX & 0b11110000) | (channel & 0b1111); // Table 24-4 : Select ADC channel, (Table 14-6 : alternate function for RV1 on PC0 -> ADC0)
// ADMUX |= (1 << ADLAR); // Enable left adjust result
ADCSRA |= (1 << ADSC); // 24.9.2 : Start conversion, ADSC: ADC Start Conversion
while (ADCSRA & (1 << ADSC)); // Wait for completion
return ADC;
return ADCH; // TODO: p247, read ADCH when left adjusted to only read 8 bits
}

View File

@@ -3,7 +3,7 @@
// 1.1.7 : AVCC is the supply voltage pin for the A/D Converter, PC3:0, and ADC7:6
// 1.1.8 : AREF is the analog reference pin for the A/D Converter
#define ADC_PRESCALER 8
#define ADC_PRESCALER 2
void int_to_hex_string(uint64_t value, char *out, uint8_t num_digits) { // num_digits : number of digit of the output, ex 2 for 3FF (1023) -> FF
for (uint8_t i = 0; i < num_digits; ++i) {
@@ -22,7 +22,7 @@ int main() {
while(1) {
uint16_t value = adc_read(0); // Read from ADC0 (A0)
int_to_hex_string(value, buffer, 3);
int_to_hex_string(value, buffer, 2);
uart_printstr_endl(buffer);
_delay_ms(20); // Wait 20ms
}