Remove stuff that was unnecessary
This commit is contained in:
parent
65fd9d375c
commit
5be15a53f9
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Created on March 6, 2024, 12:34 PM
|
* Created on March 6, 2024, 12:34 PM
|
||||||
*/
|
*/
|
||||||
#include "oving.h"
|
#include "header.h"
|
||||||
#define F_CPU 4000000UL
|
#define F_CPU 4000000UL
|
||||||
#define RTC_PERIOD (511)
|
#define RTC_PERIOD (511)
|
||||||
#define DELAY_TIME 1000
|
#define DELAY_TIME 1000
|
||||||
@ -16,75 +16,99 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
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;
|
uint16_t adcVal;
|
||||||
void led_init(void);
|
|
||||||
void ADC0_init(void);
|
void sensor_init(void)
|
||||||
uint16_t ADC0_read();
|
{
|
||||||
void ADC0_start(void);
|
PORTE.DIRSET = PIN0_bm;
|
||||||
bool ADC0_conersionDone(void);
|
PORTE.DIRSET = PIN1_bm;
|
||||||
|
PORTE.DIRSET = PIN2_bm;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void USART3_init(void)
|
||||||
|
{
|
||||||
|
PORTB.DIRCLR &= ~PIN1_bm;
|
||||||
|
PORTB.DIRSET |= PIN0_bm;
|
||||||
|
PORTB.DIRCLR = PIN2_bm;
|
||||||
|
PORTB.PIN2CTRL |= PORT_PULLUPEN_bm;
|
||||||
|
USART3.CTRLB |= USART_RXEN_bm | USART_TXEN_bm; /* Enable both TX and
|
||||||
|
RX */
|
||||||
|
}
|
||||||
|
|
||||||
|
void ADC0_init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
ADC0.CTRLC = ADC_PRESC_DIV4_gc;
|
||||||
|
VREF.ADC0REF = VREF_REFSEL_VDD_gc; /* Internal reference */
|
||||||
|
ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */
|
||||||
|
| ADC_RESSEL_10BIT_gc; /* 10-bit mode */
|
||||||
|
/* Select ADC channel */
|
||||||
|
ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void USART3_sendChar(char c)
|
||||||
|
{
|
||||||
|
while (!(USART3.STATUS & USART_DREIF_bm))
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
|
USART3.TXDATAL = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void USART3_sendString(char *str)
|
||||||
|
{
|
||||||
|
for(size_t i = 0; i < strlen(str); i++)
|
||||||
|
{
|
||||||
|
USART3_sendChar(str[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int USART3_printChar(char c, FILE *stream)
|
||||||
|
{
|
||||||
|
USART3_sendChar(c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t ADC0_read(void)
|
||||||
|
{
|
||||||
|
/* Start ADC conversion */
|
||||||
|
ADC0.COMMAND = ADC_STCONV_bm;
|
||||||
|
/* Wait until ADC conversion done */
|
||||||
|
while ( !(ADC0.INTFLAGS & ADC_RESRDY_bm) )
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
|
/* Clear the interrupt flag by writing 1: */
|
||||||
|
ADC0.INTFLAGS = ADC_RESRDY_bm;
|
||||||
|
return ADC0.RES;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ADC0_conversionDone(void)
|
||||||
|
{
|
||||||
|
return (ADC0.INTFLAGS & ADC_RESRDY_bm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE);
|
static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE);
|
||||||
|
|
||||||
int teller = 100;
|
int teller = 100;
|
||||||
int main(void)
|
int main(void)
|
||||||
{ led_init();
|
{ sensor_init();
|
||||||
ADC0_init();
|
ADC0_init();
|
||||||
USART3_init();
|
USART3_init();
|
||||||
stdout = &USART_stream;
|
stdout = &USART_stream;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int teller = teller++;
|
if (ADC0_conversionDone())
|
||||||
if (teller <=100)
|
|
||||||
{
|
|
||||||
if (ADC0_conersionDone())
|
|
||||||
{
|
{
|
||||||
float temp = (1/248.15)+(1/0.25)*(adcVal/1000)
|
|
||||||
adcVal = ADC0_read();
|
adcVal = ADC0_read();
|
||||||
printf("%d \n",adcVal);
|
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};
|
/*char out_str[30] = {0};
|
||||||
float flt_num = adcVal;
|
float flt_num = adcVal;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user