moved voltage fram main to c file
This commit is contained in:
parent
18ea74bbb6
commit
4105c1ff04
@ -4,7 +4,8 @@
|
||||
*
|
||||
* Created on March 6, 2024, 12:34 PM
|
||||
*/
|
||||
#include "header.h"
|
||||
#include "voltage.h"
|
||||
#include "uart.h"
|
||||
#define RTC_PERIOD (511)
|
||||
#define DELAY_TIME 1000
|
||||
#include <avr/io.h>
|
||||
@ -15,50 +16,6 @@
|
||||
|
||||
#define F_CPU 4E6
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "uart.h"
|
||||
#include <util/delay.h>
|
||||
|
||||
void sensor_init(void) {
|
||||
/* Disable digital input buffer */
|
||||
}
|
||||
|
||||
void ADC0_init(void) {
|
||||
PORTD.PIN6CTRL &= ~PORT_ISC_gm;
|
||||
PORTD.PIN6CTRL |= PORT_ISC_INPUT_DISABLE_gc;
|
||||
PORTD.PIN6CTRL &= PORT_PULLUPEN_bm;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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_conversationDone(void) {
|
||||
if (ADC0.INTFLAGS && ADC_RESRDY_bm) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
sensor_init();
|
||||
ADC0_init();
|
||||
@ -66,7 +23,7 @@ int main() {
|
||||
stdout = &USART_stream;
|
||||
|
||||
while (1) {
|
||||
adcVal = ADC0_read();
|
||||
uint16_t adcVal = ADC0_read();
|
||||
VREF.ADC0REF = VREF_REFSEL_VDD_gc;
|
||||
printf("The values: \n%u , %u\n",VREF_REFSEL_VDD_gc , adcVal);
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
displayName="Header Files"
|
||||
projectFiles="true">
|
||||
<itemPath>uart.h</itemPath>
|
||||
<itemPath>header.h</itemPath>
|
||||
<itemPath>voltage.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="ExternalFiles"
|
||||
displayName="Important Files"
|
||||
@ -21,6 +21,7 @@
|
||||
projectFiles="true">
|
||||
<itemPath>main.c</itemPath>
|
||||
<itemPath>uart.c</itemPath>
|
||||
<itemPath>voltage.c</itemPath>
|
||||
</logicalFolder>
|
||||
</logicalFolder>
|
||||
<projectmakefile>Makefile</projectmakefile>
|
||||
|
||||
29
prosjekt.X/voltage.c
Normal file
29
prosjekt.X/voltage.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include "voltage.h"
|
||||
void sensor_init(void) {
|
||||
/* Disable digital input buffer */
|
||||
}
|
||||
|
||||
void ADC0_init(void) {
|
||||
PORTD.PIN6CTRL &= ~PORT_ISC_gm;
|
||||
PORTD.PIN6CTRL |= PORT_ISC_INPUT_DISABLE_gc;
|
||||
PORTD.PIN6CTRL &= PORT_PULLUPEN_bm;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@ -44,19 +44,15 @@
|
||||
#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.
|
||||
|
||||
void sensor_init(void);
|
||||
void ADC0_init(void);
|
||||
void ADC0_start(void);
|
||||
uint16_t ADC0_read(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* XC_HEADER_TEMPLATE_H */
|
||||
|
||||
void sensor_init(void);
|
||||
void ADC0_init(void);
|
||||
void ADC0_start(void);
|
||||
bool ADC0_conversationDone(void);
|
||||
uint16_t ADC0_read(void);
|
||||
uint16_t adcVal;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user