Small change in added shit

This commit is contained in:
Inamr 2024-03-06 15:22:40 +01:00
parent e66d1979bb
commit 7d984eab63

View File

@ -26,6 +26,17 @@
* Revision history: * Revision history:
*/ */
#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>
#include <stdio.h>
// This is a guard condition so that contents of this file are not included // This is a guard condition so that contents of this file are not included
// more than once. // more than once.
#ifndef XC_HEADER_TEMPLATE_H #ifndef XC_HEADER_TEMPLATE_H
@ -33,46 +44,81 @@
#include <xc.h> // include processor files - each processor file is guarded. #include <xc.h> // include processor files - each processor file is guarded.
// TODO Insert appropriate #include <> uint16_t adcVal;
// TODO Insert C++ class definitions if appropriate void led_init(void)
{
/* Disable digital input buffer */
PORTC.PIN6CTRL &= ~PORT_ISC_gm;
PORTC.PIN6CTRL |= PORT_ISC_INPUT_DISABLE_gc;
/* Disable pull-up resistor */
PORTC.PIN6CTRL &= ~PORT_PULLUPEN_bm;
PORTE.DIRSET = PIN0_bm;
PORTE.DIRSET = PIN1_bm;
PORTE.DIRSET = PIN2_bm;
// TODO Insert declarations
// Comment a function and leverage automatic documentation with slash star star
/**
<p><b>Function prototype:</b></p>
<p><b>Summary:</b></p>
<p><b>Description:</b></p>
<p><b>Precondition:</b></p>
<p><b>Parameters:</b></p>
<p><b>Returns:</b></p>
<p><b>Example:</b></p>
<code>
</code>
<p><b>Remarks:</b></p>
*/
// TODO Insert declarations or function prototypes (right here) to leverage
// live documentation
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// TODO If C++ is being used, regular C code needs function names to have C
// linkage so the functions can be used by the c code.
#ifdef __cplusplus
} }
#endif /* __cplusplus */
#endif /* XC_HEADER_TEMPLATE_H */ 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 */
USART3.BAUD = USART3_BAUD_RATE (9600); /* Setting the baudrate */
}
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_conersionDone(void)
{
return (ADC0.INTFLAGS & ADC_RESRDY_bm);
}