Dont work
This commit is contained in:
parent
3c08e59843
commit
8f63e7b0c3
@ -58,9 +58,13 @@ extern "C" {
|
|||||||
|
|
||||||
#endif /* XC_HEADER_TEMPLATE_H */
|
#endif /* XC_HEADER_TEMPLATE_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 sensor_init(void);
|
void led_init(void);
|
||||||
void ADC0_init(void);
|
void ADC0_init(void);
|
||||||
uint16_t ADC0_read();
|
uint16_t ADC0_read();
|
||||||
void ADC0_start(void);
|
void ADC0_start(void);
|
||||||
bool ADC0_conversionDone(void);
|
bool ADC0_conversationDone(void);
|
||||||
@ -5,19 +5,38 @@
|
|||||||
* Created on March 6, 2024, 12:34 PM
|
* Created on March 6, 2024, 12:34 PM
|
||||||
*/
|
*/
|
||||||
#include "header.h"
|
#include "header.h"
|
||||||
uint16_t adcVal;
|
#define F_CPU 4000000UL
|
||||||
uint16_t internalVal;
|
#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>
|
||||||
|
|
||||||
|
static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE);
|
||||||
|
|
||||||
void sensor_init(void)
|
void sensor_init(void)
|
||||||
{
|
{
|
||||||
PORTB.DIRSET = PIN0_bm;
|
/* Disable digital input buffer */
|
||||||
PORTB.DIRSET = PIN1_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 */
|
||||||
|
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 */
|
||||||
@ -26,6 +45,29 @@ void ADC0_init(void)
|
|||||||
ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc;
|
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)
|
uint16_t ADC0_read(void)
|
||||||
{
|
{
|
||||||
/* Start ADC conversion */
|
/* Start ADC conversion */
|
||||||
@ -42,20 +84,29 @@ uint16_t ADC0_read(void)
|
|||||||
|
|
||||||
bool ADC0_conversationDone(void)
|
bool ADC0_conversationDone(void)
|
||||||
{
|
{
|
||||||
return (ADC0.INTFLAGS & ADC_RESRDY_bm);
|
if(ADC0.INTFLAGS && ADC_RESRDY_bm){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{ sensor_init();
|
{ sensor_init();
|
||||||
ADC0_init();
|
ADC0_init();
|
||||||
|
USART3_init();
|
||||||
|
stdout = &USART_stream;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (ADC0_conversionDone())
|
//printf("loop\n");
|
||||||
|
if (ADC0_conversationDone())
|
||||||
{
|
{
|
||||||
adcVal = ADC0_read();
|
adcVal = ADC0_read();
|
||||||
|
VREF.ADC0REF = VREF_REFSEL_VDD_gc;
|
||||||
|
printf("The values: \n");
|
||||||
|
//printf("%u , %u",VREF_REFSEL_VDD_gc , adcVal);
|
||||||
}
|
}
|
||||||
internalVal = VREF.ADC0REF;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@ -29,10 +29,10 @@
|
|||||||
<targetDevice>AVR128DB48</targetDevice>
|
<targetDevice>AVR128DB48</targetDevice>
|
||||||
<targetHeader></targetHeader>
|
<targetHeader></targetHeader>
|
||||||
<targetPluginBoard></targetPluginBoard>
|
<targetPluginBoard></targetPluginBoard>
|
||||||
<platformTool>noID</platformTool>
|
<platformTool>nEdbgTool</platformTool>
|
||||||
<languageToolchain>XC8</languageToolchain>
|
<languageToolchain>XC8</languageToolchain>
|
||||||
<languageToolchainVersion>2.45</languageToolchainVersion>
|
<languageToolchainVersion>2.46</languageToolchainVersion>
|
||||||
<platform>2</platform>
|
<platform>3</platform>
|
||||||
</toolsSet>
|
</toolsSet>
|
||||||
<packs>
|
<packs>
|
||||||
<pack name="AVR-Dx_DFP" vendor="Microchip" version="2.3.272"/>
|
<pack name="AVR-Dx_DFP" vendor="Microchip" version="2.3.272"/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user