2024-03-06 13:58:06 +00:00
|
|
|
/*
|
|
|
|
|
* File: main.c
|
|
|
|
|
* Author: Sebastian H. Gabrielli
|
|
|
|
|
*
|
|
|
|
|
* Created on March 6, 2024, 12:34 PM
|
|
|
|
|
*/
|
2024-03-06 14:16:01 +00:00
|
|
|
#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 <avr/io.h>
|
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
|
#include <util/delay.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdbool.h>
|
2024-03-06 13:58:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2024-03-06 14:16:01 +00:00
|
|
|
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);
|
2024-03-06 13:58:06 +00:00
|
|
|
|
2024-03-06 14:16:01 +00:00
|
|
|
static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE);
|
2024-03-06 13:58:06 +00:00
|
|
|
|
2024-03-06 14:16:01 +00:00
|
|
|
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); */
|
|
|
|
|
|
2024-03-06 13:58:06 +00:00
|
|
|
}
|