small fix
This commit is contained in:
parent
8f63e7b0c3
commit
86c127d3cd
@ -26,10 +26,6 @@
|
|||||||
* 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/io.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
@ -62,9 +58,8 @@ void USART3_init(void);
|
|||||||
void USART3_sendChar(char c);
|
void USART3_sendChar(char c);
|
||||||
void USART3_sendString(char *str);
|
void USART3_sendString(char *str);
|
||||||
static int USART3_printChar(char c, FILE *stream);
|
static int USART3_printChar(char c, FILE *stream);
|
||||||
uint16_t adcVal;
|
|
||||||
void led_init(void);
|
void led_init(void);
|
||||||
void ADC0_init(void);
|
void ADC0_init(void);
|
||||||
uint16_t ADC0_read();
|
|
||||||
void ADC0_start(void);
|
void ADC0_start(void);
|
||||||
bool ADC0_conversationDone(void);
|
bool ADC0_conversationDone(void);
|
||||||
|
uint16_t adcVal;
|
||||||
@ -18,14 +18,12 @@
|
|||||||
|
|
||||||
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);
|
||||||
|
|
||||||
void sensor_init(void)
|
void sensor_init(void) {
|
||||||
{
|
|
||||||
/* Disable digital input buffer */
|
/* Disable digital input buffer */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void USART3_init(void)
|
void USART3_init(void) {
|
||||||
{
|
|
||||||
PORTB.DIRCLR &= ~PIN1_bm;
|
PORTB.DIRCLR &= ~PIN1_bm;
|
||||||
PORTB.DIRSET |= PIN0_bm;
|
PORTB.DIRSET |= PIN0_bm;
|
||||||
PORTB.DIRCLR = PIN2_bm;
|
PORTB.DIRCLR = PIN2_bm;
|
||||||
@ -35,8 +33,7 @@ void USART3_init(void)
|
|||||||
USART3.BAUD = USART3_BAUD_RATE(9600); /* Setting the baudrate */
|
USART3.BAUD = USART3_BAUD_RATE(9600); /* Setting the baudrate */
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADC0_init(void)
|
void ADC0_init(void) {
|
||||||
{
|
|
||||||
ADC0.CTRLC = ADC_PRESC_DIV4_gc;
|
ADC0.CTRLC = ADC_PRESC_DIV4_gc;
|
||||||
VREF.ADC0REF = VREF_REFSEL_VDD_gc; /* Internal reference */
|
VREF.ADC0REF = VREF_REFSEL_VDD_gc; /* Internal reference */
|
||||||
ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */
|
ADC0.CTRLA = ADC_ENABLE_bm /* ADC Enable: enabled */
|
||||||
@ -45,36 +42,29 @@ void ADC0_init(void)
|
|||||||
ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc;
|
ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void USART3_sendChar(char c)
|
void USART3_sendChar(char c) {
|
||||||
{
|
while (!(USART3.STATUS & USART_DREIF_bm)) {
|
||||||
while (!(USART3.STATUS & USART_DREIF_bm))
|
|
||||||
{
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
USART3.TXDATAL = c;
|
USART3.TXDATAL = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void USART3_sendString(char *str)
|
void USART3_sendString(char *str) {
|
||||||
{
|
for (size_t i = 0; i < strlen(str); i++) {
|
||||||
for(size_t i = 0; i < strlen(str); i++)
|
|
||||||
{
|
|
||||||
USART3_sendChar(str[i]);
|
USART3_sendChar(str[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int USART3_printChar(char c, FILE *stream)
|
static int USART3_printChar(char c, FILE *stream) {
|
||||||
{
|
|
||||||
USART3_sendChar(c);
|
USART3_sendChar(c);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ADC0_read(void)
|
uint16_t ADC0_read(void) {
|
||||||
{
|
|
||||||
/* Start ADC conversion */
|
/* Start ADC conversion */
|
||||||
ADC0.COMMAND = ADC_STCONV_bm;
|
ADC0.COMMAND = ADC_STCONV_bm;
|
||||||
/* Wait until ADC conversion done */
|
/* Wait until ADC conversion done */
|
||||||
while ( !(ADC0.INTFLAGS & ADC_RESRDY_bm) )
|
while (!(ADC0.INTFLAGS & ADC_RESRDY_bm)) {
|
||||||
{
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
/* Clear the interrupt flag by writing 1: */
|
/* Clear the interrupt flag by writing 1: */
|
||||||
@ -82,8 +72,7 @@ uint16_t ADC0_read(void)
|
|||||||
return ADC0.RES;
|
return ADC0.RES;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ADC0_conversationDone(void)
|
bool ADC0_conversationDone(void) {
|
||||||
{
|
|
||||||
if (ADC0.INTFLAGS && ADC_RESRDY_bm) {
|
if (ADC0.INTFLAGS && ADC_RESRDY_bm) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -92,17 +81,15 @@ bool ADC0_conversationDone(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void) {
|
||||||
{ sensor_init();
|
sensor_init();
|
||||||
ADC0_init();
|
ADC0_init();
|
||||||
USART3_init();
|
USART3_init();
|
||||||
stdout = &USART_stream;
|
stdout = &USART_stream;
|
||||||
|
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
//printf("loop\n");
|
//printf("loop\n");
|
||||||
if (ADC0_conversationDone())
|
if (ADC0_conversationDone()) {
|
||||||
{
|
|
||||||
adcVal = ADC0_read();
|
adcVal = ADC0_read();
|
||||||
VREF.ADC0REF = VREF_REFSEL_VDD_gc;
|
VREF.ADC0REF = VREF_REFSEL_VDD_gc;
|
||||||
printf("The values: \n");
|
printf("The values: \n");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user