fix rebase module05
This commit is contained in:
@@ -1,14 +1,6 @@
|
||||
#include "header.h"
|
||||
|
||||
// Table 14-6. Port C Pins Alternate Functions
|
||||
// - PC0 -> ADC0 (ADC Input Channel 0)
|
||||
// -> PCINT8 (Pin Change Interrupt 8)
|
||||
//
|
||||
// 24.2 : The ADC generates a 10-bit result which is presented in the ADC Data Registers, ADCH and ADCL
|
||||
//
|
||||
// START A CONVERSTION in single conversion mode :
|
||||
// - disabling the Power Reduction ADC bit, PRADC
|
||||
// - writing a logical one to the ADC Start Conversion bit, ADSC
|
||||
|
||||
void adc_init(uint8_t prescaler_value) {
|
||||
ADMUX = (1 << REFS0); // Table 24-3 : set voltage reference, AVCC with external capacitor at AREF pin
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
#include "usart.h"
|
||||
#include "adc.h"
|
||||
|
||||
//
|
||||
// GLOBAL
|
||||
//
|
||||
extern volatile uint8_t adc_channel;
|
||||
|
||||
//
|
||||
// PROTOTYPES
|
||||
//
|
||||
|
||||
@@ -16,20 +16,14 @@
|
||||
|
||||
volatile uint8_t adc_channel = 0;
|
||||
|
||||
// description
|
||||
// read potentiometer value and print it in uart as hexadecimal 2-number
|
||||
int main() {
|
||||
char buffer[4];
|
||||
SREG |= ENABLE_GLOBAL_INTERRUPT; // 7.3.1 : Status Register, bit 7 : I – Global Interrupt Enable
|
||||
uart_init();
|
||||
adc_init(ADC_PRESCALER);
|
||||
|
||||
while(1) {
|
||||
uint16_t value = adc_read(0); // Read from ADC0 (A0)
|
||||
int_to_hex_string(value, buffer, 2);
|
||||
uart_printstr_endl(buffer);
|
||||
_delay_ms(20); // Wait 20ms
|
||||
}
|
||||
}
|
||||
timer_1B_init();
|
||||
|
||||
// ISR(ADC_vect) { // Table 12-6 : interrupt vector for ADC Conversion Complete
|
||||
// }
|
||||
while(1);
|
||||
}
|
||||
9
module05/ex00/math.c
Normal file
9
module05/ex00/math.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "header.h"
|
||||
|
||||
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) {
|
||||
uint8_t shift = (num_digits - 1 - i) * 4;
|
||||
out[i] = INT_TO_HEX_CHAR((value >> shift) & 0x0F);
|
||||
}
|
||||
out[num_digits] = '\0';
|
||||
}
|
||||
Reference in New Issue
Block a user