added shit

This commit is contained in:
Inamr 2024-03-06 15:16:01 +01:00
parent bf5c83de2a
commit e66d1979bb
3 changed files with 162 additions and 16 deletions

78
prosjekt.X/header.h Normal file
View File

@ -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 <xc.h> // 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
/**
<p><b>Function prototype:</b></p>
<p><b>Summary:</b></p>
<p><b>Description:</b></p>
<p><b>Precondition:</b></p>
<p><b>Parameters:</b></p>
<p><b>Returns:</b></p>
<p><b>Example:</b></p>
<code>
</code>
<p><b>Remarks:</b></p>
*/
// 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 */

View File

@ -4,24 +4,91 @@
* *
* Created on March 6, 2024, 12:34 PM * 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 <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#define ADC_SAMPLES (uint8_t)200 //Number of ADC samples taken void USART3_init(void);
#define ADC_REF_V (float)3.33 void USART3_sendChar(char c);
#define ADC_GAIN (float)(ADC_REF_V / 4096) //ADC digital to analog voltage factor void USART3_sendString(char *str);
#define ANALOG_GAIN (float)1750 //Hardware gain static int USART3_printChar(char c, FILE *stream);
#define ADC_CH_POS 6 //AC signal input channel uint16_t adcVal;
#define ADC_CH_NEG 7 //AC signal reference point input void led_init(void);
V void ADC0_init(void);
void ADC_Handler(void); uint16_t ADC0_read();
void ADC0_start(void);
bool ADC0_conersionDone(void);
/* static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE);
*
*/
int main(int argc, char** argv) {
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); */
}

View File

@ -4,6 +4,7 @@
<logicalFolder name="HeaderFiles" <logicalFolder name="HeaderFiles"
displayName="Header Files" displayName="Header Files"
projectFiles="true"> projectFiles="true">
<itemPath>header.h</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="ExternalFiles" <logicalFolder name="ExternalFiles"
displayName="Important Files" displayName="Important Files"