/* * File: main.c * Author: Sebastian H. Gabrielli * * Created on March 6, 2024, 12:34 PM */ #include "oving.h" #define F_CPU 4000000UL #define RTC_PERIOD (511) #define DELAY_TIME 1000 #define USART3_BAUD_RATE(BAUD_RATE) ((float) (64*F_CPU /(16*(float)BAUD_RATE) )+0.5) #include #include #include #include #include #include void USART3_init(void); void USART3_sendChar(char c); void USART3_sendString(char *str); static int USART3_printChar(char c, FILE *stream); uint16_t adcVal; void led_init(void); void ADC0_init(void); uint16_t ADC0_read(); void ADC0_start(void); bool ADC0_conersionDone(void); static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE); int teller = 100; int main(void) { led_init(); ADC0_init(); USART3_init(); stdout = &USART_stream; while (1) { int teller = teller++; if (teller <=100) { if (ADC0_conersionDone()) { float temp = (1/248.15)+(1/0.25)*(adcVal/1000) adcVal = ADC0_read(); printf("%d \n",adcVal); teller = 0; } } if(adcVal < 10) { PORTE.OUTSET = PIN2_bm; _delay_ms(DELAY_TIME); } else { PORTE.OUTCLR = PIN2_bm; } if((adcVal < 25) ^ (adcVal > 10)) { PORTE.OUTSET = PIN1_bm; _delay_ms(DELAY_TIME); } else { PORTE.OUTCLR = PIN1_bm; } if(adcVal > 25) { PORTE.OUTSET = PIN0_bm; _delay_ms(DELAY_TIME); } else { PORTE.OUTCLR = PIN0_bm; } } /*char out_str[30] = {0}; float flt_num = adcVal; sprintf(out_str, "flt_num = %f\r\n", flt_num); UartTxStr(out_str); */ }