diff --git a/prosjekt.X/header.h b/prosjekt.X/header.h index 9cfe156..4789bf9 100644 --- a/prosjekt.X/header.h +++ b/prosjekt.X/header.h @@ -44,81 +44,28 @@ #include // include processor files - each processor file is guarded. + +#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); +void USART3_sendChar(char c); +void USART3_sendString(char *str); +static int USART3_printChar(char c, FILE *stream); uint16_t adcVal; - -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; - -} - -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); -} +void led_init(void); +void ADC0_init(void); +uint16_t ADC0_read(); +void ADC0_start(void); +bool ADC0_conersionDone(void); \ No newline at end of file