Files
42_EXT_03_42chips/module05/ex00/main.c
2025-03-13 16:02:27 +01:00

27 lines
780 B
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "header.h"
void int_to_hex_string(uint64_t value, char *out, uint8_t num_digits) {
for (uint8_t i = 0; i < num_digits; ++i) {
uint8_t shift = (num_digits - 1 - i) * 4;
out[i] = INT_TO_HEX_CHAR((value >> shift) & 0x0F);
}
out[num_digits] = '\0';
}
// description
int main() {
const char buffer[4];
SREG |= ENABLE_GLOBAL_INTERRUPT; // 7.3.1 : Status Register, bit 7 : I Global Interrupt Enable
uart_init();
adc_init();
while(1) {
uint16_t value = adc_read(0); // Read from ADC0 (A0)
int_to_hex_string(value, buffer, 3);
uart_printstr_endl(buffer);
_delay_ms(20); // Wait 20ms
}
}
// ISR(ADC_vect) { // Table 12-6 : interrupt vector for ADC Conversion Complete
// }