From e66d1979bb915867b25c1150c7ea72297f1cb602 Mon Sep 17 00:00:00 2001 From: Inamr Date: Wed, 6 Mar 2024 15:16:01 +0100 Subject: [PATCH] added shit --- prosjekt.X/header.h | 78 +++++++++++++++++++ prosjekt.X/main.c | 99 +++++++++++++++++++++---- prosjekt.X/nbproject/configurations.xml | 1 + 3 files changed, 162 insertions(+), 16 deletions(-) create mode 100644 prosjekt.X/header.h diff --git a/prosjekt.X/header.h b/prosjekt.X/header.h new file mode 100644 index 0000000..8a03290 --- /dev/null +++ b/prosjekt.X/header.h @@ -0,0 +1,78 @@ +/* Microchip Technology Inc. and its subsidiaries. You may use this software + * and any derivatives exclusively with Microchip products. + * + * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED + * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A + * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION + * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. + * + * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS + * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE + * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS + * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF + * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. + * + * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE + * TERMS. + */ + +/* + * File: + * Author: + * Comments: + * Revision history: + */ + +// This is a guard condition so that contents of this file are not included +// more than once. +#ifndef XC_HEADER_TEMPLATE_H +#define XC_HEADER_TEMPLATE_H + +#include // include processor files - each processor file is guarded. + +// TODO Insert appropriate #include <> + +// TODO Insert C++ class definitions if appropriate + +// TODO Insert declarations + +// Comment a function and leverage automatic documentation with slash star star +/** +

Function prototype:

+ +

Summary:

+ +

Description:

+ +

Precondition:

+ +

Parameters:

+ +

Returns:

+ +

Example:

+ + + + +

Remarks:

+ */ +// TODO Insert declarations or function prototypes (right here) to leverage +// live documentation + +#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 */ + diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index 11f62d1..a7c1358 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -4,24 +4,91 @@ * * Created on March 6, 2024, 12:34 PM */ - +#include "oving.h" +#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 +#include +#include +#include +#include #include -#include -#define ADC_SAMPLES (uint8_t)200 //Number of ADC samples taken -#define ADC_REF_V (float)3.33 -#define ADC_GAIN (float)(ADC_REF_V / 4096) //ADC digital to analog voltage factor -#define ANALOG_GAIN (float)1750 //Hardware gain -#define ADC_CH_POS 6 //AC signal input channel -#define ADC_CH_NEG 7 //AC signal reference point input -V -void ADC_Handler(void); +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); +void ADC0_init(void); +uint16_t ADC0_read(); +void ADC0_start(void); +bool ADC0_conersionDone(void); -/* - * - */ -int main(int argc, char** argv) { +static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE); - return (EXIT_SUCCESS); +int teller = 100; +int main(void) +{ led_init(); + ADC0_init(); + USART3_init(); + stdout = &USART_stream; + + while (1) + { + int teller = teller++; + if (teller <=100) + { + if (ADC0_conersionDone()) + { + float temp = (1/248.15)+(1/0.25)*(adcVal/1000) + adcVal = ADC0_read(); + printf("%d \n",adcVal); + teller = 0; + } + } + + if(adcVal < 10) + { + + PORTE.OUTSET = PIN2_bm; + + _delay_ms(DELAY_TIME); + } + else + { + PORTE.OUTCLR = PIN2_bm; + + } + if((adcVal < 25) ^ (adcVal > 10)) + { + PORTE.OUTSET = PIN1_bm; + + _delay_ms(DELAY_TIME); + } + else + { + PORTE.OUTCLR = PIN1_bm; + + } + if(adcVal > 25) + { + PORTE.OUTSET = PIN0_bm; + + _delay_ms(DELAY_TIME); + } + else + { + PORTE.OUTCLR = PIN0_bm; + + } + + } + /*char out_str[30] = {0}; + float flt_num = adcVal; + sprintf(out_str, "flt_num = %f\r\n", flt_num); + UartTxStr(out_str); */ + } - diff --git a/prosjekt.X/nbproject/configurations.xml b/prosjekt.X/nbproject/configurations.xml index 867e0b8..a2ca271 100644 --- a/prosjekt.X/nbproject/configurations.xml +++ b/prosjekt.X/nbproject/configurations.xml @@ -4,6 +4,7 @@ + header.h