Create draft, kinda workes
This commit is contained in:
parent
0aa9376fa6
commit
6b0608e04b
@ -58,11 +58,6 @@ 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 sensor_init(void);
|
||||||
void ADC0_init(void);
|
void ADC0_init(void);
|
||||||
|
|||||||
@ -18,24 +18,15 @@
|
|||||||
|
|
||||||
|
|
||||||
uint16_t adcVal;
|
uint16_t adcVal;
|
||||||
|
uint16_t internalVal;
|
||||||
|
|
||||||
void sensor_init(void)
|
void sensor_init(void)
|
||||||
{
|
{
|
||||||
PORTE.DIRSET = PIN0_bm;
|
PORTB.DIRSET = PIN0_bm;
|
||||||
PORTE.DIRSET = PIN1_bm;
|
PORTB.DIRSET = PIN1_bm;
|
||||||
PORTE.DIRSET = PIN2_bm;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void USART3_init(void)
|
|
||||||
{
|
|
||||||
PORTB.DIRCLR &= ~PIN1_bm;
|
|
||||||
PORTB.DIRSET |= PIN0_bm;
|
|
||||||
PORTB.DIRCLR = PIN2_bm;
|
|
||||||
USART3.CTRLB |= USART_RXEN_bm | USART_TXEN_bm; /* Enable both TX and
|
|
||||||
RX */
|
|
||||||
}
|
|
||||||
|
|
||||||
void ADC0_init(void)
|
void ADC0_init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -47,29 +38,6 @@ 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 */
|
||||||
@ -89,23 +57,17 @@ bool ADC0_conversionDone(void)
|
|||||||
return (ADC0.INTFLAGS & ADC_RESRDY_bm);
|
return (ADC0.INTFLAGS & ADC_RESRDY_bm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE);
|
|
||||||
|
|
||||||
int teller = 100;
|
|
||||||
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())
|
if (ADC0_conversionDone())
|
||||||
{
|
{
|
||||||
adcVal = ADC0_read();
|
adcVal = ADC0_read();
|
||||||
printf("%d \n",adcVal);
|
|
||||||
}
|
}
|
||||||
|
internalVal = VREF.ADC0REF;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user