migration

This commit is contained in:
2023-03-09 16:08:27 +01:00
parent a5315c03a7
commit 966ff2ae3a
47 changed files with 25 additions and 142 deletions

135
mcc_generated_files/adc.c Normal file
View File

@ -0,0 +1,135 @@
/**
ADC Generated Driver File
@Company
Microchip Technology Inc.
@File Name
adc.c
@Summary
This is the generated driver implementation file for the ADC driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description
This source file provides implementations for driver APIs for ADC.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.02
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
/**
Section: Included Files
*/
#include <xc.h>
#include "adc.h"
#include "device_config.h"
void (*ADC_InterruptHandler)(void);
/**
Section: ADC Module APIs
*/
void ADC_Initialize(void)
{
// set the ADC to the options selected in the User Interface
// VCFG1 VSS; VCFG0 VDD;
ADCON1 = 0x00;
// ADFM right; ACQT 0; ADCS FOSC/2;
ADCON2 = 0x80;
// ADRESL 0;
ADRESL = 0x00;
// ADRESH 0;
ADRESH = 0x00;
// GO_nDONE stop; ADCAL Normal_a/d_operation; ADON enabled; CHS AN0;
ADCON0 = 0x01;
}
void ADC_SelectChannel(adc_channel_t channel)
{
// select the A/D channel
ADCON0bits.CHS = channel;
// Turn on the ADC module
ADCON0bits.ADON = 1;
}
void ADC_StartConversion(void)
{
// Start the conversion
ADCON0bits.GO_nDONE = 1;
}
bool ADC_IsConversionDone(void)
{
// Start the conversion
return ((bool)(!ADCON0bits.GO_nDONE));
}
adc_result_t ADC_GetConversionResult(void)
{
// Conversion finished, return the result
return ((adc_result_t)((ADRESH << 8) + ADRESL));
}
adc_result_t ADC_GetConversion(adc_channel_t channel)
{
// select the A/D channel
ADCON0bits.CHS = channel;
// Turn on the ADC module
ADCON0bits.ADON = 1;
// Start the conversion
ADCON0bits.GO_nDONE = 1;
// Wait for the conversion to finish
while (ADCON0bits.GO_nDONE)
{
}
// Conversion finished, return the result
return ((adc_result_t)((ADRESH << 8) + ADRESL));
}
void ADC_TemperatureAcquisitionDelay(void)
{
__delay_us(200);
}
/**
End of File
*/

326
mcc_generated_files/adc.h Normal file
View File

@ -0,0 +1,326 @@
/**
ADC Generated Driver API Header File
@Company
Microchip Technology Inc.
@File Name
adc.h
@Summary
This is the generated header file for the ADC driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description
This header file provides APIs for driver for ADC.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.02
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#ifndef ADC_H
#define ADC_H
/**
Section: Included Files
*/
#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
/**
Section: Data Types Definitions
*/
/**
* result size of an A/D conversion
*/
typedef uint16_t adc_result_t;
/**
* result type of a Double ADC conversion
*/
typedef struct
{
adc_result_t adcResult1;
adc_result_t adcResult2;
} adc_sync_double_result_t;
/** ADC Channel Definition
@Summary
Defines the channels available for conversion.
@Description
This routine defines the channels that are available for the module to use.
Remarks:
None
*/
typedef enum
{
voltage = 0x5,
current = 0x6
} adc_channel_t;
/**
Section: ADC Module APIs
*/
/**
@Summary
Initializes the ADC
@Description
This routine initializes the Initializes the ADC.
This routine must be called before any other ADC routine is called.
This routine should only be called once during system initialization.
@Preconditions
None
@Param
None
@Returns
None
@Comment
@Example
<code>
uint16_t convertedValue;
ADC_Initialize();
convertedValue = ADC_GetConversionResult();
</code>
*/
void ADC_Initialize(void);
/**
@Summary
Allows selection of a channel for conversion
@Description
This routine is used to select desired channel for conversion.
available
@Preconditions
ADC_Initialize() function should have been called before calling this function.
@Returns
None
@Param
Pass in required channel number
"For available channel refer to enum under adc.h file"
@Example
<code>
uint16_t convertedValue;
ADC_Initialize();
ADC_SelectChannel(AN1_Channel);
ADC_StartConversion();
convertedValue = ADC_GetConversionResult();
</code>
*/
void ADC_SelectChannel(adc_channel_t channel);
/**
@Summary
Starts conversion
@Description
This routine is used to start conversion of desired channel.
@Preconditions
ADC_Initialize() function should have been called before calling this function.
@Returns
None
@Param
None
@Example
<code>
uint16_t convertedValue;
ADC_Initialize();
ADC_StartConversion();
convertedValue = ADC_GetConversionResult();
</code>
*/
void ADC_StartConversion(void);
/**
@Summary
Returns true when the conversion is completed otherwise false.
@Description
This routine is used to determine if conversion is completed.
When conversion is complete routine returns true. It returns false otherwise.
@Preconditions
ADC_Initialize() and ADC_StartConversion(void)
function should have been called before calling this function.
@Returns
true - If conversion is complete
false - If conversion is not completed
@Param
None
@Example
<code>
uint16_t convertedValue;
ADC_Initialize();
ADC_StartConversion();
while(!ADC_IsConversionDone());
convertedValue = ADC_GetConversionResult();
</code>
*/
bool ADC_IsConversionDone(void);
/**
@Summary
Returns the ADC conversion value.
@Description
This routine is used to get the analog to digital converted value. This
routine gets converted values from the channel specified.
@Preconditions
This routine returns the conversion value only after the conversion is complete.
Completion status can be checked using
ADC_IsConversionDone() routine.
@Returns
Returns the converted value.
@Param
None
@Example
<code>
uint16_t convertedValue;
ADC_Initialize();
ADC_StartConversion();
while(ADC_IsConversionDone());
convertedValue = ADC_GetConversionResult();
</code>
*/
adc_result_t ADC_GetConversionResult(void);
/**
@Summary
Returns the ADC conversion value
also allows selection of a channel for conversion.
@Description
This routine is used to select desired channel for conversion
and to get the analog to digital converted value.
@Preconditions
ADC_Initialize() function should have been called before calling this function.
@Returns
Returns the converted value.
@Param
Pass in required channel number.
"For available channel refer to enum under adc.h file"
@Example
<code>
uint16_t convertedValue;
ADC_Initialize();
conversion = ADC_GetConversion(AN1_Channel);
</code>
*/
adc_result_t ADC_GetConversion(adc_channel_t channel);
/**
@Summary
Acquisition Delay for temperature sensor
@Description
This routine should be called when temperature sensor is used.
@Preconditions
ADC_Initialize() function should have been called before calling this function.
@Returns
None
@Param
None
@Example
<code>
uint16_t convertedValue;
ADC_Initialize();
ADC_StartConversion();
ADC_temperatureAcquisitionDelay();
convertedValue = ADC_GetConversionResult();
</code>
*/
void ADC_TemperatureAcquisitionDelay(void);
#ifdef __cplusplus // Provide C++ Compatibility
}
#endif
#endif //ADC_H
/**
End of File
*/

View File

@ -0,0 +1,76 @@
/**
@Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Source File
@Company:
Microchip Technology Inc.
@File Name:
mcc.c
@Summary:
This is the device_config.c file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description:
This header file provides implementations for driver APIs for all modules selected in the GUI.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.00
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above or later
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
// Configuration bits: selected in the GUI
// CONFIG1L
#pragma config WDT = OFF // Watchdog Timer Enable bit->WDT disabled (control is placed on SWDTEN bit)
#pragma config STVR = ON // Stack Overflow/Underflow Reset Enable bit->Reset on stack overflow/underflow enabled
#pragma config XINST = OFF // Extended Instruction Set Enable bit->Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
#pragma config DEBUG = OFF // Background Debugger Enable bit->Background debugger disabled; RB6 and RB7 configured as general purpose I/O pins
// CONFIG1H
#pragma config CP0 = OFF // Code Protection bit->Program memory is not code-protected
// CONFIG2L
#pragma config FOSC = HS // Oscillator Selection bits->HS oscillator
#pragma config FOSC2 = ON // Default/Reset System Clock Select bit->Clock selected by FOSC1:FOSC0 as system clock is enabled when OSCCON<1:0> = 00
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor enabled
#pragma config IESO = ON // Two-Speed Start-up (Internal/External Oscillator Switchover) Control bit->Two-Speed Start-up enabled
// CONFIG2H
#pragma config WDTPS = 32768 // Watchdog Timer Postscaler Select bits->1:32768
// CONFIG3L
#pragma config EASHFT = ON // External Address Bus Shift Enable bit->Address shifting enabled; address on external bus is offset to start at 000000h
#pragma config MODE = MM // External Memory Bus->Microcontroller mode, external bus disabled
#pragma config BW = 16 // Data Bus Width Select bit->16-Bit Data Width mode
#pragma config WAIT = OFF // External Bus Wait Enable bit->Wait states for operations on external memory bus disabled
// CONFIG3H
#pragma config CCP2MX = ON // ECCP2 MUX bit->ECCP2/P2A is multiplexed with RC1
#pragma config ECCPMX = ON // ECCP MUX bit->ECCP1 outputs (P1B/P1C) are multiplexed with RE6 and RE5; ECCP3 outputs (P3B/P3C) are multiplexed with RE4 and RE3
#pragma config ETHLED = ON // Ethernet LED Enable bit->RA0/RA1 are multiplexed with LEDA/LEDB when Ethernet module is enabled and function as I/O when Ethernet is disabled

View File

@ -0,0 +1,55 @@
/**
@Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Header File
@Company:
Microchip Technology Inc.
@File Name:
mcc.c
@Summary:
This is the device_config.h file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description:
This header file provides implementations for driver APIs for all modules selected in the GUI.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.00
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above or later
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#ifndef DEVICE_CONFIG_H
#define DEVICE_CONFIG_H
#define _XTAL_FREQ 25000000
#endif /* DEVICE_CONFIG_H */
/**
End of File
*/

View File

@ -0,0 +1,96 @@
/**
EPWM1 Generated Driver File
@Company
Microchip Technology Inc.
@File Name
epwm1.c
@Summary
This is the generated driver implementation file for the EPWM1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description
This source file provides implementations for driver APIs for EPWM1.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.01
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
/**
Section: Included Files
*/
#include <xc.h>
#include "epwm1.h"
/**
Section: Macro Declarations
*/
#define PWM1_INITIALIZE_DUTY_VALUE 511
/**
Section: EPWM Module APIs
*/
void EPWM1_Initialize(void)
{
// Set the EPWM1 to the options selected in the User Interface
// CCP1M P1A,P1C: active high; P1B,P1D: active high; DC1B 3; P1M single;
CCP1CON = 0x3C;
// ECCPASE operating; PSSBD P1BP1D_0; PSSAC P1AP1C_0; ECCPAS disabled;
ECCP1AS = 0x00;
// P1RSEN automatic_restart; P1DC0 0;
ECCP1DEL = 0x80;
// CCPR1H 0;
CCPR1H = 0x00;
// CCPR1L 127;
CCPR1L = 0x7F;
}
void EPWM1_LoadDutyValue(uint16_t dutyValue)
{
// Writing to 8 MSBs of pwm duty cycle in CCPRL register
CCPR1L = ((dutyValue & 0x03FC)>>2);
// Writing to 2 LSBs of pwm duty cycle in CCPCON register
CCP1CON = ((uint8_t)(CCP1CON & 0xCF) | ((dutyValue & 0x0003)<<4));
}
/**
End of File
*/

133
mcc_generated_files/epwm1.h Normal file
View File

@ -0,0 +1,133 @@
/**
EPWM1 Generated Driver File
@Company
Microchip Technology Inc.
@File Name
epwm1.h
@Summary
This is the generated driver implementation file for the EPWM1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description
This header file provides implementations for driver APIs for EPWM1.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.01
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#ifndef EPWM1_H
#define EPWM1_H
/**
Section: Included Files
*/
#include <xc.h>
#include <stdint.h>
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
/**
Section: EPWM Module APIs
*/
/**
@Summary
Initializes the EPWM1
@Description
This routine initializes the EPWM1 module.
This routine must be called before any other EPWM1 routine is called.
This routine should only be called once during system initialization.
@Preconditions
None
@Param
None
@Returns
None
@Comment
@Example
<code>
uint16_t dutycycle;
ECCP1_Initialize();
EPWM1_LoadDutyValue(dutycycle);
</code>
*/
void EPWM1_Initialize(void);
/**
@Summary
Loads 16-bit duty cycle.
@Description
This routine loads the 16 bit duty cycle value.
@Preconditions
EPWM1_Initialize() function should have been called before calling this function.
@Param
Pass 16bit duty cycle value.
@Returns
None
@Example
<code>
uint16_t dutycycle;
EPWM1_Initialize();
EPWM1_LoadDutyValue(dutycycle);
</code>
*/
void EPWM1_LoadDutyValue(uint16_t dutyValue);
#ifdef __cplusplus // Provide C++ Compatibility
}
#endif
#endif //EPWM1_H
/**
End of File
*/

View File

@ -0,0 +1,239 @@
/**
EUSART1 Generated Driver File
@Company
Microchip Technology Inc.
@File Name
eusart1.c
@Summary
This is the generated driver implementation file for the EUSART1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description
This source file provides APIs for EUSART1.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.1.1
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
/**
Section: Included Files
*/
#include "eusart1.h"
/**
Section: Macro Declarations
*/
#define EUSART1_TX_BUFFER_SIZE 8
#define EUSART1_RX_BUFFER_SIZE 8
/**
Section: Global Variables
*/
volatile uint8_t eusart1RxHead = 0;
volatile uint8_t eusart1RxTail = 0;
volatile uint8_t eusart1RxBuffer[EUSART1_RX_BUFFER_SIZE];
volatile eusart1_status_t eusart1RxStatusBuffer[EUSART1_RX_BUFFER_SIZE];
volatile uint8_t eusart1RxCount;
volatile eusart1_status_t eusart1RxLastError;
/**
Section: EUSART1 APIs
*/
void (*EUSART1_RxDefaultInterruptHandler)(void);
void (*EUSART1_FramingErrorHandler)(void);
void (*EUSART1_OverrunErrorHandler)(void);
void (*EUSART1_ErrorHandler)(void);
void EUSART1_DefaultFramingErrorHandler(void);
void EUSART1_DefaultOverrunErrorHandler(void);
void EUSART1_DefaultErrorHandler(void);
void EUSART1_Initialize(void)
{
// disable interrupts before changing states
PIE1bits.RC1IE = 0;
EUSART1_SetRxInterruptHandler(EUSART1_Receive_ISR);
// Set the EUSART1 module to the options selected in the user interface.
// ABDOVF no_overflow; SCKP async_noninverted_sync_fallingedge; BRG16 16bit_generator; WUE disabled; ABDEN disabled; RXDTP not_inverted;
BAUDCON1 = 0x08;
// SPEN enabled; RX9 9-bit; CREN enabled; ADDEN disabled; SREN disabled;
RCSTA1 = 0xD0;
// TX9 9-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC asynchronous; BRGH hi_speed; CSRC master_mode;
TXSTA1 = 0xE4;
//
SPBRG1 = 0x8A;
//
SPBRGH1 = 0x02;
EUSART1_SetFramingErrorHandler(EUSART1_DefaultFramingErrorHandler);
EUSART1_SetOverrunErrorHandler(EUSART1_DefaultOverrunErrorHandler);
EUSART1_SetErrorHandler(EUSART1_DefaultErrorHandler);
eusart1RxLastError.status = 0;
eusart1RxHead = 0;
eusart1RxTail = 0;
eusart1RxCount = 0;
// enable receive interrupt
PIE1bits.RC1IE = 1;
}
bool EUSART1_is_tx_ready(void)
{
return (bool)(PIR1bits.TX1IF && TXSTA1bits.TXEN);
}
bool EUSART1_is_rx_ready(void)
{
return (eusart1RxCount ? true : false);
}
bool EUSART1_is_tx_done(void)
{
return TXSTA1bits.TRMT;
}
eusart1_status_t EUSART1_get_last_status(void){
return eusart1RxLastError;
}
uint8_t EUSART1_Read(void)
{
uint8_t readValue = 0;
while(0 == eusart1RxCount)
{
}
eusart1RxLastError = eusart1RxStatusBuffer[eusart1RxTail];
readValue = eusart1RxBuffer[eusart1RxTail++];
if(sizeof(eusart1RxBuffer) <= eusart1RxTail)
{
eusart1RxTail = 0;
}
PIE1bits.RC1IE = 0;
eusart1RxCount--;
PIE1bits.RC1IE = 1;
return readValue;
}
void EUSART1_Write(uint8_t txData)
{
while(0 == PIR1bits.TX1IF)
{
}
TXREG1 = txData; // Write the data byte to the USART.
}
void EUSART1_Receive_ISR(void)
{
eusart1RxStatusBuffer[eusart1RxHead].status = 0;
if(RCSTA1bits.FERR){
eusart1RxStatusBuffer[eusart1RxHead].ferr = 1;
EUSART1_FramingErrorHandler();
}
if(RCSTA1bits.OERR){
eusart1RxStatusBuffer[eusart1RxHead].oerr = 1;
EUSART1_OverrunErrorHandler();
}
if(eusart1RxStatusBuffer[eusart1RxHead].status){
EUSART1_ErrorHandler();
} else {
EUSART1_RxDataHandler();
}
// or set custom function using EUSART1_SetRxInterruptHandler()
}
void EUSART1_RxDataHandler(void){
// use this default receive interrupt handler code
eusart1RxBuffer[eusart1RxHead++] = RCREG1;
if(sizeof(eusart1RxBuffer) <= eusart1RxHead)
{
eusart1RxHead = 0;
}
eusart1RxCount++;
}
void EUSART1_DefaultFramingErrorHandler(void){}
void EUSART1_DefaultOverrunErrorHandler(void){
// EUSART1 error - restart
RCSTA1bits.CREN = 0;
RCSTA1bits.CREN = 1;
}
void EUSART1_DefaultErrorHandler(void){
EUSART1_RxDataHandler();
}
void EUSART1_SetFramingErrorHandler(void (* interruptHandler)(void)){
EUSART1_FramingErrorHandler = interruptHandler;
}
void EUSART1_SetOverrunErrorHandler(void (* interruptHandler)(void)){
EUSART1_OverrunErrorHandler = interruptHandler;
}
void EUSART1_SetErrorHandler(void (* interruptHandler)(void)){
EUSART1_ErrorHandler = interruptHandler;
}
void EUSART1_SetRxInterruptHandler(void (* interruptHandler)(void)){
EUSART1_RxDefaultInterruptHandler = interruptHandler;
}
/**
End of File
*/

View File

@ -0,0 +1,476 @@
/**
EUSART1 Generated Driver API Header File
@Company
Microchip Technology Inc.
@File Name
eusart1.h
@Summary
This is the generated header file for the EUSART1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description
This header file provides APIs for driver for EUSART1.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.1.1
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#ifndef EUSART1_H
#define EUSART1_H
/**
Section: Included Files
*/
#include <xc.h>
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
/**
Section: Macro Declarations
*/
#define EUSART1_DataReady (EUSART1_is_rx_ready())
/**
Section: Data Type Definitions
*/
typedef union {
struct {
unsigned perr : 1;
unsigned ferr : 1;
unsigned oerr : 1;
unsigned reserved : 5;
};
uint8_t status;
}eusart1_status_t;
/**
Section: Global variables
*/
extern volatile uint8_t eusart1TxBufferRemaining;
extern volatile uint8_t eusart1RxCount;
/**
Section: EUSART1 APIs
*/
extern void (*EUSART1_RxDefaultInterruptHandler)(void);
/**
@Summary
Initialization routine that takes inputs from the EUSART1 GUI.
@Description
This routine initializes the EUSART1 driver.
This routine must be called before any other EUSART1 routine is called.
@Preconditions
None
@Param
None
@Returns
None
@Comment
*/
void EUSART1_Initialize(void);
/**
@Summary
Checks if the EUSART1 transmitter is ready to transmit data
@Description
This routine checks if EUSART1 transmitter is ready
to accept and transmit data byte
@Preconditions
EUSART1_Initialize() function should have been called
before calling this function.
EUSART1 transmitter should be enabled before calling
this function
@Param
None
@Returns
Status of EUSART1 transmitter
TRUE: EUSART1 transmitter is ready
FALSE: EUSART1 transmitter is not ready
@Example
<code>
void main(void)
{
volatile uint8_t rxData;
// Initialize the device
SYSTEM_Initialize();
while(1)
{
// Logic to echo received data
if(EUSART1_is_rx_ready())
{
rxData = UART1_Read();
if(EUSART1_is_tx_ready())
{
EUSART1Write(rxData);
}
}
}
}
</code>
*/
bool EUSART1_is_tx_ready(void);
/**
@Summary
Checks if the EUSART1 receiver ready for reading
@Description
This routine checks if EUSART1 receiver has received data
and ready to be read
@Preconditions
EUSART1_Initialize() function should be called
before calling this function
EUSART1 receiver should be enabled before calling this
function
@Param
None
@Returns
Status of EUSART1 receiver
TRUE: EUSART1 receiver is ready for reading
FALSE: EUSART1 receiver is not ready for reading
@Example
<code>
void main(void)
{
volatile uint8_t rxData;
// Initialize the device
SYSTEM_Initialize();
while(1)
{
// Logic to echo received data
if(EUSART1_is_rx_ready())
{
rxData = UART1_Read();
if(EUSART1_is_tx_ready())
{
EUSART1_Write(rxData);
}
}
}
}
</code>
*/
bool EUSART1_is_rx_ready(void);
/**
@Summary
Checks if EUSART1 data is transmitted
@Description
This function return the status of transmit shift register
@Preconditions
EUSART1_Initialize() function should be called
before calling this function
EUSART1 transmitter should be enabled and EUSART1_Write
should be called before calling this function
@Param
None
@Returns
Status of EUSART1 receiver
TRUE: Data completely shifted out if the USART shift register
FALSE: Data is not completely shifted out of the shift register
@Example
<code>
void main(void)
{
volatile uint8_t rxData;
// Initialize the device
SYSTEM_Initialize();
while(1)
{
if(EUSART1_is_tx_ready())
{
LED_0_SetHigh();
EUSART1Write(rxData);
}
if(EUSART1_is_tx_done()
{
LED_0_SetLow();
}
}
}
</code>
*/
bool EUSART1_is_tx_done(void);
/**
@Summary
Gets the error status of the last read byte.
@Description
This routine gets the error status of the last read byte.
@Preconditions
EUSART1_Initialize() function should have been called
before calling this function. The returned value is only
updated after a read is called.
@Param
None
@Returns
the status of the last read byte
@Example
<code>
void main(void)
{
volatile uint8_t rxData;
volatile eusart1_status_t rxStatus;
// Initialize the device
SYSTEM_Initialize();
// Enable the Global Interrupts
INTERRUPT_GlobalInterruptEnable();
while(1)
{
// Logic to echo received data
if(EUSART1_is_rx_ready())
{
rxData = EUSART1_Read();
rxStatus = EUSART1_get_last_status();
if(rxStatus.ferr){
LED_0_SetHigh();
}
}
}
}
</code>
*/
eusart1_status_t EUSART1_get_last_status(void);
/**
@Summary
Read a byte of data from the EUSART1.
@Description
This routine reads a byte of data from the EUSART1.
@Preconditions
EUSART1_Initialize() function should have been called
before calling this function. The transfer status should be checked to see
if the receiver is not empty before calling this function.
@Param
None
@Returns
A data byte received by the driver.
*/
uint8_t EUSART1_Read(void);
/**
@Summary
Writes a byte of data to the EUSART1.
@Description
This routine writes a byte of data to the EUSART1.
@Preconditions
EUSART1_Initialize() function should have been called
before calling this function. The transfer status should be checked to see
if transmitter is not busy before calling this function.
@Param
txData - Data byte to write to the EUSART1
@Returns
None
*/
void EUSART1_Write(uint8_t txData);
/**
@Summary
Maintains the driver's receiver state machine and implements its ISR
@Description
This routine is used to maintain the driver's internal receiver state
machine.This interrupt service routine is called when the state of the
receiver needs to be maintained in a non polled manner.
@Preconditions
EUSART1_Initialize() function should have been called
for the ISR to execute correctly.
@Param
None
@Returns
None
*/
void EUSART1_Receive_ISR(void);
/**
@Summary
Maintains the driver's receiver state machine
@Description
This routine is called by the receive state routine and is used to maintain
the driver's internal receiver state machine. It should be called by a custom
ISR to maintain normal behavior
@Preconditions
EUSART1_Initialize() function should have been called
for the ISR to execute correctly.
@Param
None
@Returns
None
*/
void EUSART1_RxDataHandler(void);
/**
@Summary
Set EUSART1 Framing Error Handler
@Description
This API sets the function to be called upon EUSART1 framing error
@Preconditions
Initialize the EUSART1 before calling this API
@Param
Address of function to be set as framing error handler
@Returns
None
*/
void EUSART1_SetFramingErrorHandler(void (* interruptHandler)(void));
/**
@Summary
Set EUSART1 Overrun Error Handler
@Description
This API sets the function to be called upon EUSART1 overrun error
@Preconditions
Initialize the EUSART1 module before calling this API
@Param
Address of function to be set as overrun error handler
@Returns
None
*/
void EUSART1_SetOverrunErrorHandler(void (* interruptHandler)(void));
/**
@Summary
Set EUSART1 Error Handler
@Description
This API sets the function to be called upon EUSART1 error
@Preconditions
Initialize the EUSART1 module before calling this API
@Param
Address of function to be set as error handler
@Returns
None
*/
void EUSART1_SetErrorHandler(void (* interruptHandler)(void));
/**
@Summary
Sets the receive handler function to be called by the interrupt service
@Description
Calling this function will set a new custom function that will be
called when the receive interrupt needs servicing.
@Preconditions
EUSART1_Initialize() function should have been called
for the ISR to execute correctly.
@Param
A pointer to the new function
@Returns
None
*/
void EUSART1_SetRxInterruptHandler(void (* interruptHandler)(void));
#ifdef __cplusplus // Provide C++ Compatibility
}
#endif
#endif // EUSART1_H
/**
End of File
*/

View File

@ -0,0 +1,83 @@
/**
Generated Interrupt Manager Source File
@Company:
Microchip Technology Inc.
@File Name:
interrupt_manager.c
@Summary:
This is the Interrupt Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description:
This header file provides implementations for global interrupt handling.
For individual peripheral handlers please see the peripheral driver for
all modules selected in the GUI.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.04
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above or later
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#include "interrupt_manager.h"
#include "mcc.h"
void INTERRUPT_Initialize (void)
{
// Disable Interrupt Priority Vectors (16CXXX Compatibility Mode)
RCONbits.IPEN = 0;
}
void __interrupt() INTERRUPT_InterruptManager (void)
{
// interrupt handler
if(INTCONbits.TMR0IE == 1 && INTCONbits.TMR0IF == 1)
{
TMR0_ISR();
}
else if(INTCONbits.PEIE == 1)
{
if(PIE1bits.RC1IE == 1 && PIR1bits.RC1IF == 1)
{
EUSART1_RxDefaultInterruptHandler();
}
else
{
//Unhandled Interrupt
}
}
else
{
//Unhandled Interrupt
}
}
/**
End of File
*/

View File

@ -0,0 +1,115 @@
/**
Generated Interrupt Manager Header File
@Company:
Microchip Technology Inc.
@File Name:
interrupt_manager.h
@Summary:
This is the Interrupt Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description:
This header file provides implementations for global interrupt handling.
For individual peripheral handlers please see the peripheral driver for
all modules selected in the GUI.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.03
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above or later
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#ifndef INTERRUPT_MANAGER_H
#define INTERRUPT_MANAGER_H
/**
* @Param
none
* @Returns
none
* @Description
This macro will enable global interrupts.
* @Example
INTERRUPT_GlobalInterruptEnable();
*/
#define INTERRUPT_GlobalInterruptEnable() (INTCONbits.GIE = 1)
/**
* @Param
none
* @Returns
none
* @Description
This macro will disable global interrupts.
* @Example
INTERRUPT_GlobalInterruptDisable();
*/
#define INTERRUPT_GlobalInterruptDisable() (INTCONbits.GIE = 0)
/**
* @Param
none
* @Returns
none
* @Description
This macro will enable peripheral interrupts.
* @Example
INTERRUPT_PeripheralInterruptEnable();
*/
#define INTERRUPT_PeripheralInterruptEnable() (INTCONbits.PEIE = 1)
/**
* @Param
none
* @Returns
none
* @Description
This macro will disable peripheral interrupts.
* @Example
INTERRUPT_PeripheralInterruptDisable();
*/
#define INTERRUPT_PeripheralInterruptDisable() (INTCONbits.PEIE = 0)
/**
* @Param
none
* @Returns
none
* @Description
Initializes PIC18 peripheral interrupt priorities; enables/disables priority vectors
* @Example
INTERRUPT_Initialize();
*/
void INTERRUPT_Initialize (void);
#endif // INTERRUPT_MANAGER_H
/**
End of File
*/

74
mcc_generated_files/mcc.c Normal file
View File

@ -0,0 +1,74 @@
/**
@Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Source File
@Company:
Microchip Technology Inc.
@File Name:
mcc.c
@Summary:
This is the mcc.c file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description:
This header file provides implementations for driver APIs for all modules selected in the GUI.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.00
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above or later
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#include "mcc.h"
void SYSTEM_Initialize(void)
{
INTERRUPT_Initialize();
PIN_MANAGER_Initialize();
OSCILLATOR_Initialize();
ADC_Initialize();
EPWM1_Initialize();
TMR2_Initialize();
TMR0_Initialize();
EUSART1_Initialize();
}
void OSCILLATOR_Initialize(void)
{
// SCS Primary_OSC; OSTS intosc; IDLEN disabled;
OSCCON = 0x02;
// PLLEN disabled; PPST0 disabled; PPRE divide_by_3; PPST1 divide_by_3;
OSCTUNE = 0x00;
}
/**
End of File
*/

93
mcc_generated_files/mcc.h Normal file
View File

@ -0,0 +1,93 @@
/**
@Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Header File
@Company:
Microchip Technology Inc.
@File Name:
mcc.h
@Summary:
This is the mcc.h file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description:
This header file provides implementations for driver APIs for all modules selected in the GUI.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.00
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above or later
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#ifndef MCC_H
#define MCC_H
#include <xc.h>
#include "device_config.h"
#include "pin_manager.h"
#include <stdint.h>
#include <stdbool.h>
#include <conio.h>
#include "interrupt_manager.h"
#include "epwm1.h"
#include "tmr2.h"
#include "adc.h"
#include "tmr0.h"
#include "eusart1.h"
/**
* @Param
none
* @Returns
none
* @Description
Initializes the device to the default states configured in the
* MCC GUI
* @Example
SYSTEM_Initialize(void);
*/
void SYSTEM_Initialize(void);
/**
* @Param
none
* @Returns
none
* @Description
Initializes the oscillator to the default states configured in the
* MCC GUI
* @Example
OSCILLATOR_Initialize(void);
*/
void OSCILLATOR_Initialize(void);
#endif /* MCC_H */
/**
End of File
*/

View File

@ -0,0 +1,97 @@
/**
Generated Pin Manager File
Company:
Microchip Technology Inc.
File Name:
pin_manager.c
Summary:
This is the Pin Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
Description:
This header file provides implementations for pin APIs for all pins selected in the GUI.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.0
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#include "pin_manager.h"
void PIN_MANAGER_Initialize(void)
{
/**
LATx registers
*/
LATE = 0x00;
LATJ = 0x00;
LATD = 0x00;
LATA = 0x00;
LATF = 0x00;
LATB = 0x00;
LATG = 0x00;
LATC = 0x00;
LATH = 0x00;
/**
TRISx registers
*/
TRISE = 0xFF;
TRISF = 0xFF;
TRISA = 0x3F;
TRISG = 0xFF;
TRISB = 0xFF;
TRISH = 0xFF;
TRISC = 0xBB;
TRISD = 0xFF;
TRISJ = 0xFF;
/**
PCFG setting
*/
ADCON1bits.PCFG = 0x00;
}
void PIN_MANAGER_IOC(void)
{
}
/**
End of File
*/

View File

@ -0,0 +1,144 @@
/**
@Generated Pin Manager Header File
@Company:
Microchip Technology Inc.
@File Name:
pin_manager.h
@Summary:
This is the Pin Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description:
This header file provides implementations for pin APIs for all pins selected in the GUI.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Version : 2.0
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
Copyright (c) 2013 - 2015 released Microchip Technology Inc. All rights reserved.
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#ifndef PIN_MANAGER_H
#define PIN_MANAGER_H
/**
Section: Included Files
*/
#include <xc.h>
#define INPUT 1
#define OUTPUT 0
#define HIGH 1
#define LOW 0
#define ANALOG 1
#define DIGITAL 0
#define PULL_UP_ENABLED 1
#define PULL_UP_DISABLED 0
// get/set RC2 procedures
#define RC2_SetHigh() do { LATCbits.LATC2 = 1; } while(0)
#define RC2_SetLow() do { LATCbits.LATC2 = 0; } while(0)
#define RC2_Toggle() do { LATCbits.LATC2 = ~LATCbits.LATC2; } while(0)
#define RC2_GetValue() PORTCbits.RC2
#define RC2_SetDigitalInput() do { TRISCbits.TRISC2 = 1; } while(0)
#define RC2_SetDigitalOutput() do { TRISCbits.TRISC2 = 0; } while(0)
// get/set RC6 procedures
#define RC6_SetHigh() do { LATCbits.LATC6 = 1; } while(0)
#define RC6_SetLow() do { LATCbits.LATC6 = 0; } while(0)
#define RC6_Toggle() do { LATCbits.LATC6 = ~LATCbits.LATC6; } while(0)
#define RC6_GetValue() PORTCbits.RC6
#define RC6_SetDigitalInput() do { TRISCbits.TRISC6 = 1; } while(0)
#define RC6_SetDigitalOutput() do { TRISCbits.TRISC6 = 0; } while(0)
// get/set voltage aliases
#define voltage_TRIS TRISFbits.TRISF0
#define voltage_LAT LATFbits.LATF0
#define voltage_PORT PORTFbits.RF0
#define voltage_ANS anselRF0bits.anselRF0
#define voltage_SetHigh() do { LATFbits.LATF0 = 1; } while(0)
#define voltage_SetLow() do { LATFbits.LATF0 = 0; } while(0)
#define voltage_Toggle() do { LATFbits.LATF0 = ~LATFbits.LATF0; } while(0)
#define voltage_GetValue() PORTFbits.RF0
#define voltage_SetDigitalInput() do { TRISFbits.TRISF0 = 1; } while(0)
#define voltage_SetDigitalOutput() do { TRISFbits.TRISF0 = 0; } while(0)
#define voltage_SetAnalogMode() do { anselRF0bits.anselRF0 = 1; } while(0)
#define voltage_SetDigitalMode() do { anselRF0bits.anselRF0 = 0; } while(0)
// get/set current aliases
#define current_TRIS TRISFbits.TRISF1
#define current_LAT LATFbits.LATF1
#define current_PORT PORTFbits.RF1
#define current_ANS anselRF1bits.anselRF1
#define current_SetHigh() do { LATFbits.LATF1 = 1; } while(0)
#define current_SetLow() do { LATFbits.LATF1 = 0; } while(0)
#define current_Toggle() do { LATFbits.LATF1 = ~LATFbits.LATF1; } while(0)
#define current_GetValue() PORTFbits.RF1
#define current_SetDigitalInput() do { TRISFbits.TRISF1 = 1; } while(0)
#define current_SetDigitalOutput() do { TRISFbits.TRISF1 = 0; } while(0)
#define current_SetAnalogMode() do { anselRF1bits.anselRF1 = 1; } while(0)
#define current_SetDigitalMode() do { anselRF1bits.anselRF1 = 0; } while(0)
/**
@Param
none
@Returns
none
@Description
GPIO and peripheral I/O initialization
@Example
PIN_MANAGER_Initialize();
*/
void PIN_MANAGER_Initialize (void);
/**
* @Param
none
* @Returns
none
* @Description
Interrupt on Change Handling routine
* @Example
PIN_MANAGER_IOC();
*/
void PIN_MANAGER_IOC(void);
#endif // PIN_MANAGER_H
/**
End of File
*/

167
mcc_generated_files/tmr0.c Normal file
View File

@ -0,0 +1,167 @@
/**
TMR0 Generated Driver File
@Company
Microchip Technology Inc.
@File Name
tmr0.c
@Summary
This is the generated driver implementation file for the TMR0 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description
This source file provides APIs for TMR0.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.01
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
/**
Section: Included Files
*/
#include <xc.h>
#include "tmr0.h"
/**
Section: Global Variables Definitions
*/
void (*TMR0_InterruptHandler)(void);
volatile uint16_t timer0ReloadVal;
/**
Section: TMR0 APIs
*/
void TMR0_Initialize(void)
{
// Set TMR0 to the options selected in the User Interface
//Enable 16bit timer mode before assigning value to TMR0H
T0CONbits.T08BIT = 0;
// TMR0H 158;
TMR0H = 0x9E;
// TMR0L 87;
TMR0L = 0x57;
// Load TMR0 value to the 16-bit reload variable
timer0ReloadVal = (uint16_t)((TMR0H << 8) | TMR0L);
// Clear Interrupt flag before enabling the interrupt
INTCONbits.TMR0IF = 0;
// Enabling TMR0 interrupt.
INTCONbits.TMR0IE = 1;
// Set Default Interrupt Handler
TMR0_SetInterruptHandler(TMR0_DefaultInterruptHandler);
// T0PS 1:2; T08BIT 16-bit; T0SE Increment_hi_lo; T0CS FOSC/4; TMR0ON enabled; PSA not_assigned;
T0CON = 0x98;
}
void TMR0_StartTimer(void)
{
// Start the Timer by writing to TMR0ON bit
T0CONbits.TMR0ON = 1;
}
void TMR0_StopTimer(void)
{
// Stop the Timer by writing to TMR0ON bit
T0CONbits.TMR0ON = 0;
}
uint16_t TMR0_ReadTimer(void)
{
uint16_t readVal;
uint8_t readValLow;
uint8_t readValHigh;
readValLow = TMR0L;
readValHigh = TMR0H;
readVal = ((uint16_t)readValHigh << 8) + readValLow;
return readVal;
}
void TMR0_WriteTimer(uint16_t timerVal)
{
// Write to the Timer0 register
TMR0H = timerVal >> 8;
TMR0L = (uint8_t) timerVal;
}
void TMR0_Reload(void)
{
// Write to the Timer0 register
TMR0H = timer0ReloadVal >> 8;
TMR0L = (uint8_t) timer0ReloadVal;
}
void TMR0_ISR(void)
{
// clear the TMR0 interrupt flag
INTCONbits.TMR0IF = 0;
// reload TMR0
// Write to the Timer0 register
TMR0H = timer0ReloadVal >> 8;
TMR0L = (uint8_t) timer0ReloadVal;
if(TMR0_InterruptHandler)
{
TMR0_InterruptHandler();
}
// add your TMR0 interrupt custom code
}
void TMR0_SetInterruptHandler(void (* InterruptHandler)(void)){
TMR0_InterruptHandler = InterruptHandler;
}
void TMR0_DefaultInterruptHandler(void){
// add your TMR0 interrupt custom code
// or set custom function using TMR0_SetInterruptHandler()
}
/**
End of File
*/

356
mcc_generated_files/tmr0.h Normal file
View File

@ -0,0 +1,356 @@
/**
TMR0 Generated Driver API Header File
@Company
Microchip Technology Inc.
@File Name
tmr0.h
@Summary
This is the generated header file for the TMR0 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description
This header file provides APIs for TMR0.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.01
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#ifndef TMR0_H
#define TMR0_H
/**
Section: Included Files
*/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
/**
Section: TMR0 APIs
*/
/**
@Summary
Initializes the TMR0.
@Description
This function initializes the TMR0 Registers.
This function must be called before any other TMR0 function is called.
@Preconditions
None
@Param
None
@Returns
None
@Comment
@Example
<code>
main()
{
// Initialize TMR0 module
TMR0_Initialize();
// Do something else...
}
</code>
*/
void TMR0_Initialize(void);
/**
@Summary
This function starts the TMR0.
@Description
This function starts the TMR0 operation.
This function must be called after the initialization of TMR0.
@Preconditions
Initialize the TMR0 before calling this function.
@Param
None
@Returns
None
@Example
<code>
// Initialize TMR0 module
// Start TMR0
TMR0_StartTimer();
// Do something else...
</code>
*/
void TMR0_StartTimer(void);
/**
@Summary
This function stops the TMR0.
@Description
This function stops the TMR0 operation.
This function must be called after the start of TMR0.
@Preconditions
Initialize the TMR0 before calling this function.
@Param
None
@Returns
None
@Example
<code>
// Initialize TMR0 module
// Start TMR0
TMR0_StartTimer();
// Do something else...
// Stop TMR0;
TMR0_StopTimer();
</code>
*/
void TMR0_StopTimer(void);
/**
@Summary
Reads the 16 bits TMR0 register value.
@Description
This function reads the 16 bits TMR0 register value and return it.
@Preconditions
Initialize the TMR0 before calling this function.
@Param
None
@Returns
This function returns the 16 bits value of TMR0 register.
@Example
<code>
// Initialize TMR0 module
// Start TMR0
TMR0_StartTimer();
// Read the current value of TMR0
if(0 == TMR0_ReadTimer())
{
// Do something else...
// Reload the TMR value
TMR0_Reload();
}
</code>
*/
uint16_t TMR0_ReadTimer(void);
/**
@Summary
Writes the 16 bits value to TMR0 register.
@Description
This function writes the 16 bits value to TMR0 register.
This function must be called after the initialization of TMR0.
@Preconditions
Initialize the TMR0 before calling this function.
@Param
timerVal - Value to write into TMR0 register.
@Returns
None
@Example
<code>
#define PERIOD 0x8000
#define ZERO 0x0000
while(1)
{
//Read the TMR0 register
if(ZERO == TMR0_ReadTimer())
{
// Do something else...
// Write the TMR0 register
TMR0_WriteTimer(PERIOD);
}
// Do something else...
}
</code>
*/
void TMR0_WriteTimer(uint16_t timerVal);
/**
@Summary
Reload the 16 bits value to TMR0 register.
@Description
This function reloads the 16 bit value to TMR0 register.
This function must be called to write initial value into TMR0 register.
@Preconditions
Initialize the TMR0 before calling this function.
@Param
None
@Returns
None
@Example
<code>
while(1)
{
if(TMR0IF)
{
// Do something else...
// clear the TMR0 interrupt flag
TMR0IF = 0;
// Reload the initial value of TMR0
TMR0_Reload();
}
}
</code>
*/
void TMR0_Reload(void);
/**
@Summary
Timer Interrupt Service Routine
@Description
Timer Interrupt Service Routine is called by the Interrupt Manager.
@Preconditions
Initialize the TMR0 module with interrupt before calling this isr.
@Param
None
@Returns
None
*/
void TMR0_ISR(void);
/**
@Summary
Set Timer Interrupt Handler
@Description
This sets the function to be called during the ISR
@Preconditions
Initialize the TMR0 module with interrupt before calling this.
@Param
Address of function to be set
@Returns
None
*/
void TMR0_SetInterruptHandler(void (* InterruptHandler)(void));
/**
@Summary
Timer Interrupt Handler
@Description
This is a function pointer to the function that will be called during the ISR
@Preconditions
Initialize the TMR0 module with interrupt before calling this isr.
@Param
None
@Returns
None
*/
extern void (*TMR0_InterruptHandler)(void);
/**
@Summary
Default Timer Interrupt Handler
@Description
This is the default Interrupt Handler function
@Preconditions
Initialize the TMR0 module with interrupt before calling this isr.
@Param
None
@Returns
None
*/
void TMR0_DefaultInterruptHandler(void);
#ifdef __cplusplus // Provide C++ Compatibility
}
#endif
#endif // TMR0_H
/**
End of File
*/

124
mcc_generated_files/tmr2.c Normal file
View File

@ -0,0 +1,124 @@
/**
TMR2 Generated Driver File
@Company
Microchip Technology Inc.
@File Name
tmr2.c
@Summary
This is the generated driver implementation file for the TMR2 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description
This source file provides APIs for TMR2.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.01
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
/**
Section: Included Files
*/
#include <xc.h>
#include "tmr2.h"
/**
Section: Global Variables Definitions
*/
/**
Section: TMR2 APIs
*/
void TMR2_Initialize(void)
{
// Set TMR2 to the options selected in the User Interface
// PR2 255;
PR2 = 0xFF;
// TMR2 0;
TMR2 = 0x00;
// Clearing IF flag.
PIR1bits.TMR2IF = 0;
// T2CKPS 1:1; TOUTPS 1:1; TMR2ON on;
T2CON = 0x04;
}
void TMR2_StartTimer(void)
{
// Start the Timer by writing to TMRxON bit
T2CONbits.TMR2ON = 1;
}
void TMR2_StopTimer(void)
{
// Stop the Timer by writing to TMRxON bit
T2CONbits.TMR2ON = 0;
}
uint8_t TMR2_ReadTimer(void)
{
uint8_t readVal;
readVal = TMR2;
return readVal;
}
void TMR2_WriteTimer(uint8_t timerVal)
{
// Write to the Timer2 register
TMR2 = timerVal;
}
void TMR2_LoadPeriodRegister(uint8_t periodVal)
{
PR2 = periodVal;
}
bool TMR2_HasOverflowOccured(void)
{
// check if overflow has occurred by checking the TMRIF bit
bool status = PIR1bits.TMR2IF;
if(status)
{
// Clearing IF flag.
PIR1bits.TMR2IF = 0;
}
return status;
}
/**
End of File
*/

337
mcc_generated_files/tmr2.h Normal file
View File

@ -0,0 +1,337 @@
/**
TMR2 Generated Driver API Header File
@Company
Microchip Technology Inc.
@File Name
tmr2.h
@Summary
This is the generated header file for the TMR2 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
@Description
This header file provides APIs for TMR2.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8
Device : PIC18F97J60
Driver Version : 2.01
The generated drivers are tested against the following:
Compiler : XC8 2.36 and above
MPLAB : MPLAB X 6.00
*/
/*
(c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and any
derivatives exclusively with Microchip products. It is your responsibility to comply with third party
license terms applicable to your use of third party software (including open source software) that
may accompany Microchip software.
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.
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.
*/
#ifndef TMR2_H
#define TMR2_H
/**
Section: Included Files
*/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
/**
Section: Macro Declarations
*/
/**
Section: TMR2 APIs
*/
/**
@Summary
Initializes the TMR2 module.
@Description
This function initializes the TMR2 Registers.
This function must be called before any other TMR2 function is called.
@Preconditions
None
@Param
None
@Returns
None
@Comment
@Example
<code>
main()
{
// Initialize TMR2 module
TMR2_Initialize();
// Do something else...
}
</code>
*/
void TMR2_Initialize(void);
/**
@Summary
This function starts the TMR2.
@Description
This function starts the TMR2 operation.
This function must be called after the initialization of TMR2.
@Preconditions
Initialize the TMR2 before calling this function.
@Param
None
@Returns
None
@Example
<code>
// Initialize TMR2 module
// Start TMR2
TMR2_StartTimer();
// Do something else...
</code>
*/
void TMR2_StartTimer(void);
/**
@Summary
This function stops the TMR2.
@Description
This function stops the TMR2 operation.
This function must be called after the start of TMR2.
@Preconditions
Initialize the TMR2 before calling this function.
@Param
None
@Returns
None
@Example
<code>
// Initialize TMR2 module
// Start TMR2
TMR2_StartTimer();
// Do something else...
// Stop TMR2;
TMR2_StopTimer();
</code>
*/
void TMR2_StopTimer(void);
/**
@Summary
Reads the TMR2 register.
@Description
This function reads the TMR2 register value and return it.
@Preconditions
Initialize the TMR2 before calling this function.
@Param
None
@Returns
This function returns the current value of TMR2 register.
@Example
<code>
// Initialize TMR2 module
// Start TMR2
TMR2_StartTimer();
// Read the current value of TMR2
if(0 == TMR2_ReadTimer())
{
// Do something else...
// Reload the TMR value
TMR2_Reload();
}
</code>
*/
uint8_t TMR2_ReadTimer(void);
/**
@Summary
Writes the TMR2 register.
@Description
This function writes the TMR2 register.
This function must be called after the initialization of TMR2.
@Preconditions
Initialize the TMR2 before calling this function.
@Param
timerVal - Value to write into TMR2 register.
@Returns
None
@Example
<code>
#define PERIOD 0x80
#define ZERO 0x00
while(1)
{
// Read the TMR2 register
if(ZERO == TMR2_ReadTimer())
{
// Do something else...
// Write the TMR2 register
TMR2_WriteTimer(PERIOD);
}
// Do something else...
}
</code>
*/
void TMR2_WriteTimer(uint8_t timerVal);
/**
@Summary
Load value to Period Register.
@Description
This function writes the value to PR2 register.
This function must be called after the initialization of TMR2.
@Preconditions
Initialize the TMR2 before calling this function.
@Param
periodVal - Value to load into TMR2 register.
@Returns
None
@Example
<code>
#define PERIOD1 0x80
#define PERIOD2 0x40
#define ZERO 0x00
while(1)
{
// Read the TMR2 register
if(ZERO == TMR2_ReadTimer())
{
// Do something else...
if(flag)
{
flag = 0;
// Load Period 1 value
TMR2_LoadPeriodRegister(PERIOD1);
}
else
{
flag = 1;
// Load Period 2 value
TMR2_LoadPeriodRegister(PERIOD2);
}
}
// Do something else...
}
</code>
*/
void TMR2_LoadPeriodRegister(uint8_t periodVal);
/**
@Summary
Boolean routine to poll or to check for the match flag on the fly.
@Description
This function is called to check for the timer match flag.
This function is used in timer polling method.
@Preconditions
Initialize the TMR2 module before calling this routine.
@Param
None
@Returns
true - timer match has occurred.
false - timer match has not occurred.
@Example
<code>
while(1)
{
// check the match flag
if(TMR2_HasOverflowOccured())
{
// Do something else...
// Reload the TMR2 value
TMR2_Reload();
}
}
</code>
*/
bool TMR2_HasOverflowOccured(void);
#ifdef __cplusplus // Provide C++ Compatibility
}
#endif
#endif // TMR2_H
/**
End of File
*/