primi test con timer lettura e buffer circolare
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
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.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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"
|
||||
|
||||
/**
|
||||
Section: Macro Declarations
|
||||
*/
|
||||
|
||||
#define ACQ_US_DELAY 5
|
||||
|
||||
void (*ADC_InterruptHandler)(void);
|
||||
|
||||
/**
|
||||
Section: ADC Module APIs
|
||||
*/
|
||||
|
||||
void ADC_Initialize(void)
|
||||
{
|
||||
// set the ADC to the options selected in the User Interface
|
||||
|
||||
// ADFM right; ADNREF VSS; ADPREF FVR; ADCS FOSC/16;
|
||||
ADCON1 = 0xD3;
|
||||
|
||||
// ADRESL 0;
|
||||
ADRESL = 0x00;
|
||||
|
||||
// ADRESH 0;
|
||||
ADRESH = 0x00;
|
||||
|
||||
// GO_nDONE stop; 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;
|
||||
|
||||
// Acquisition time delay
|
||||
__delay_us(ACQ_US_DELAY);
|
||||
|
||||
// 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
|
||||
*/
|
||||
@@ -0,0 +1,329 @@
|
||||
/**
|
||||
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.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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
|
||||
{
|
||||
A_S1 = 0x4,
|
||||
A_S2 = 0x5,
|
||||
channel_Temp = 0x1D,
|
||||
channel_DAC = 0x1E,
|
||||
channel_FVR = 0x1F
|
||||
} 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
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
\file
|
||||
\addtogroup doc_driver_delay_code
|
||||
\brief This file contains the functions to generate delays in the millisecond and microsecond ranges.
|
||||
\copyright (c) 2020 Microchip Technology Inc. and its subsidiaries.
|
||||
\page License
|
||||
(c) 2020 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.
|
||||
**/
|
||||
|
||||
|
||||
#include <xc.h>
|
||||
#include "device_config.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* \ingroup doc_driver_delay_code
|
||||
* Call this function to delay execution of the program for a certain number of milliseconds
|
||||
@param milliseconds - number of milliseconds to delay
|
||||
*/
|
||||
void DELAY_milliseconds(uint16_t milliseconds) {
|
||||
|
||||
while(milliseconds--){
|
||||
__delay_ms(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \ingroup doc_driver_delay_code
|
||||
* Call this function to delay execution of the program for a certain number of microseconds
|
||||
@param microseconds - number of microseconds to delay
|
||||
*/
|
||||
void DELAY_microseconds(uint16_t microseconds) {
|
||||
while( microseconds >= 32)
|
||||
{
|
||||
__delay_us(32);
|
||||
microseconds -= 32;
|
||||
}
|
||||
|
||||
while(microseconds--)
|
||||
{
|
||||
__delay_us(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
\file
|
||||
\defgroup doc_driver_delay_code Delay Driver Source Code Reference
|
||||
\ingroup doc_driver_delay
|
||||
\brief This file contains the API to generate delays in the millisecond and microsecond ranges.
|
||||
\copyright (c) 2020 Microchip Technology Inc. and its subsidiaries.
|
||||
\page License
|
||||
(c) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef _DELAY_H
|
||||
#define _DELAY_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void DELAY_milliseconds(uint16_t milliseconds);
|
||||
void DELAY_microseconds(uint16_t microseconds);
|
||||
|
||||
#endif // _DELAY_H
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
@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.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.00
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above or later
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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
|
||||
|
||||
// CONFIG1
|
||||
#pragma config FOSC = INTOSC // Oscillator Selection->INTOSC oscillator: I/O function on CLKIN pin
|
||||
#pragma config WDTE = OFF // Watchdog Timer Enable->WDT disabled
|
||||
#pragma config PWRTE = OFF // Power-up Timer Enable->PWRT disabled
|
||||
#pragma config MCLRE = ON // MCLR Pin Function Select->MCLR/VPP pin function is MCLR
|
||||
#pragma config CP = OFF // Flash Program Memory Code Protection->Program memory code protection is disabled
|
||||
#pragma config CPD = OFF // Data Memory Code Protection->Data memory code protection is disabled
|
||||
#pragma config BOREN = ON // Brown-out Reset Enable->Brown-out Reset enabled
|
||||
#pragma config CLKOUTEN = OFF // Clock Out Enable->CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
|
||||
#pragma config IESO = ON // Internal/External Switchover->Internal/External Switchover mode is enabled
|
||||
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor is enabled
|
||||
|
||||
// CONFIG2
|
||||
#pragma config WRT = OFF // Flash Memory Self-Write Protection->Write protection off
|
||||
#pragma config PLLEN = OFF // PLL Enable->4x PLL disabled
|
||||
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable->Stack Overflow or Underflow will cause a Reset
|
||||
#pragma config BORV = LO // Brown-out Reset Voltage Selection->Brown-out Reset Voltage (Vbor), low trip point selected.
|
||||
#pragma config LVP = ON // Low-Voltage Programming Enable->Low-voltage programming enabled
|
||||
@@ -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.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.00
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above or later
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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 4000000
|
||||
|
||||
#endif /* DEVICE_CONFIG_H */
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
\defgroup doc_driver_delay Delay Drivers
|
||||
|
||||
|
||||
|
||||
\section doc_driver_delay_driver Delay drivers for PIC and AVR
|
||||
|
||||
The MPLAB XC8 and XC16 compilers have built-in delay functions or macros for when users need to tell the MCU to wait for a certain amount of time.
|
||||
For these delay functions, time is measured in microseconds or milliseconds, and for PIC32 devices, in timer ticks as well. Format for invoking the macros
|
||||
will vary from device to device but this delay driver can help abstract these format differences.
|
||||
|
||||
\section doc_driver_delay_driver How to use the delay drivers
|
||||
|
||||
To use the delay drivers, just include the delay.h file wherever you intend to use the delay function and call the DELAY_milliseconds(time) or DELAY_microseconds(time) function where
|
||||
<i>time</i> is the number of milliseconds or microseconds to delay.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
<doxygenlayout version="1.0">
|
||||
<!-- Navigation index tabs for HTML output -->
|
||||
<navindex>
|
||||
<tab type="mainpage" visible="yes" title=""/>
|
||||
<tab type="pages" visible="yes" title="" intro=""/>
|
||||
<tab type="modules" visible="yes" title="" intro=""/>
|
||||
<tab type="namespaces" visible="yes" title="">
|
||||
<tab type="namespacelist" visible="yes" title="" intro=""/>
|
||||
<tab type="namespacemembers" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
<tab type="classes" visible="no" title="">
|
||||
<tab type="classlist" visible="yes" title="" intro=""/>
|
||||
<tab type="classindex" visible="$ALPHABETICAL_INDEX" title=""/>
|
||||
<tab type="hierarchy" visible="yes" title="" intro=""/>
|
||||
<tab type="classmembers" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
<tab type="files" visible="yes" title="">
|
||||
<tab type="filelist" visible="yes" title="" intro=""/>
|
||||
<tab type="globals" visible="yes" title="" intro=""/>
|
||||
</tab>
|
||||
<tab type="dirs" visible="yes" title="" intro=""/>
|
||||
<tab type="examples" visible="yes" title="" intro=""/>
|
||||
</navindex>
|
||||
|
||||
<!-- Layout definition for a class page -->
|
||||
<class>
|
||||
<briefdescription visible="yes"/>
|
||||
<detaileddescription title=""/>
|
||||
<includes visible="$SHOW_INCLUDE_FILES"/>
|
||||
<inheritancegraph visible="$CLASS_GRAPH"/>
|
||||
<collaborationgraph visible="$COLLABORATION_GRAPH"/>
|
||||
<memberdecl>
|
||||
<nestedclasses visible="yes" title=""/>
|
||||
<publictypes title=""/>
|
||||
<publicslots title=""/>
|
||||
<signals title=""/>
|
||||
<publicmethods title=""/>
|
||||
<publicstaticmethods title=""/>
|
||||
<publicattributes title=""/>
|
||||
<publicstaticattributes title=""/>
|
||||
<protectedtypes title=""/>
|
||||
<protectedslots title=""/>
|
||||
<protectedmethods title=""/>
|
||||
<protectedstaticmethods title=""/>
|
||||
<protectedattributes title=""/>
|
||||
<protectedstaticattributes title=""/>
|
||||
<packagetypes title=""/>
|
||||
<packagemethods title=""/>
|
||||
<packagestaticmethods title=""/>
|
||||
<packageattributes title=""/>
|
||||
<packagestaticattributes title=""/>
|
||||
<properties title=""/>
|
||||
<events title=""/>
|
||||
<privatetypes title=""/>
|
||||
<privateslots title=""/>
|
||||
<privatemethods title=""/>
|
||||
<privatestaticmethods title=""/>
|
||||
<privateattributes title=""/>
|
||||
<privatestaticattributes title=""/>
|
||||
<friends title=""/>
|
||||
<related title="" subtitle=""/>
|
||||
<membergroups visible="yes"/>
|
||||
</memberdecl>
|
||||
<memberdef>
|
||||
<inlineclasses title="Data Structures"/>
|
||||
<functions title=""/>
|
||||
<typedefs title=""/>
|
||||
<enums title="" visible="yes"/>
|
||||
<constructors title=""/>
|
||||
<related title=""/>
|
||||
<variables title=""/>
|
||||
<properties title=""/>
|
||||
<events title=""/>
|
||||
</memberdef>
|
||||
<allmemberslink visible="yes"/>
|
||||
<usedfiles visible="$SHOW_USED_FILES"/>
|
||||
<authorsection visible="yes"/>
|
||||
</class>
|
||||
|
||||
<!-- Layout definition for a namespace page -->
|
||||
<namespace>
|
||||
<briefdescription visible="yes"/>
|
||||
<memberdecl>
|
||||
<nestednamespaces visible="yes" title=""/>
|
||||
<functions title=""/>
|
||||
<classes visible="yes" title="Data structures"/>
|
||||
<typedefs title=""/>
|
||||
<enums title="" visible="yes"/>
|
||||
<variables title=""/>
|
||||
<membergroups visible="yes"/>
|
||||
</memberdecl>
|
||||
<detaileddescription title=""/>
|
||||
<memberdef>
|
||||
<inlineclasses title="Data Structures"/>
|
||||
<functions title=""/>
|
||||
<typedefs title=""/>
|
||||
<enums title="" visible="yes"/>
|
||||
<variables title=""/>
|
||||
</memberdef>
|
||||
<authorsection visible="yes"/>
|
||||
</namespace>
|
||||
|
||||
<!-- Layout definition for a file page -->
|
||||
<file>
|
||||
<briefdescription visible="yes"/>
|
||||
<includes visible="$SHOW_INCLUDE_FILES"/>
|
||||
<includegraph visible="$INCLUDE_GRAPH"/>
|
||||
<includedbygraph visible="$INCLUDED_BY_GRAPH"/>
|
||||
<sourcelink visible="yes"/>
|
||||
<memberdecl>
|
||||
<classes visible="yes" title="Data structures"/>
|
||||
<namespaces visible="yes" title=""/>
|
||||
<functions title=""/>
|
||||
<defines title=""/>
|
||||
<typedefs title=""/>
|
||||
<enums title="" visible="yes"/>
|
||||
<variables title=""/>
|
||||
<membergroups visible="yes"/>
|
||||
</memberdecl>
|
||||
<detaileddescription title=""/>
|
||||
<memberdef>
|
||||
<inlineclasses title="Data Structures"/>
|
||||
<functions title=""/>
|
||||
<defines title=""/>
|
||||
<typedefs title=""/>
|
||||
<enums title="" visible="yes"/>
|
||||
<variables title=""/>
|
||||
</memberdef>
|
||||
<authorsection/>
|
||||
</file>
|
||||
|
||||
<!-- Layout definition for a group page -->
|
||||
<group>
|
||||
<briefdescription visible="yes"/>
|
||||
<detaileddescription title="Module description"/>
|
||||
<groupgraph visible="$GROUP_GRAPHS"/>
|
||||
<memberdecl>
|
||||
<nestedgroups visible="yes" title=""/>
|
||||
<dirs visible="no" title=""/>
|
||||
<files visible="no" title=""/>
|
||||
<namespaces visible="yes" title=""/>
|
||||
<classes visible="yes" title="Data structures"/>
|
||||
<typedefs title="Typedefs"/>
|
||||
<defines title="Definitions"/>
|
||||
<enums title="Enumerations"/>
|
||||
<enumvalues title=""/>
|
||||
<functions title="Functions"/>
|
||||
<variables title="" visible="yes"/>
|
||||
<signals title=""/>
|
||||
<publicslots title=""/>
|
||||
<protectedslots title=""/>
|
||||
<privateslots title=""/>
|
||||
<events title=""/>
|
||||
<properties title=""/>
|
||||
<friends title=""/>
|
||||
<membergroups visible="yes"/>
|
||||
</memberdecl>
|
||||
<memberdef>
|
||||
<pagedocs/>
|
||||
<inlineclasses title="Data structures"/>
|
||||
<defines title="Definition Documentation"/>
|
||||
<typedefs title="Typedef Documentation"/>
|
||||
<functions title="Function Documentation"/>
|
||||
<enums title="" visible="yes"/>
|
||||
<enumvalues title="" visible="yes"/>
|
||||
<variables title="" visible="yes"/>
|
||||
<signals title=""/>
|
||||
<publicslots title=""/>
|
||||
<protectedslots title=""/>
|
||||
<privateslots title=""/>
|
||||
<events title=""/>
|
||||
<properties title=""/>
|
||||
<friends title=""/>
|
||||
</memberdef>
|
||||
<authorsection visible="no"/>
|
||||
</group>
|
||||
|
||||
<!-- Layout definition for a directory page -->
|
||||
<directory>
|
||||
<briefdescription visible="yes"/>
|
||||
<directorygraph visible="yes"/>
|
||||
<memberdecl>
|
||||
<dirs visible="yes"/>
|
||||
<files visible="yes"/>
|
||||
</memberdecl>
|
||||
<detaileddescription title=""/>
|
||||
</directory>
|
||||
</doxygenlayout>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,294 @@
|
||||
/**
|
||||
EUSART Generated Driver File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
eusart.c
|
||||
|
||||
@Summary
|
||||
This is the generated driver implementation file for the EUSART driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This source file provides APIs for EUSART.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.1.0
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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 "eusart.h"
|
||||
|
||||
/**
|
||||
Section: Macro Declarations
|
||||
*/
|
||||
|
||||
#define EUSART_TX_BUFFER_SIZE 16
|
||||
#define EUSART_RX_BUFFER_SIZE 16
|
||||
|
||||
/**
|
||||
Section: Global Variables
|
||||
*/
|
||||
volatile uint8_t eusartTxHead = 0;
|
||||
volatile uint8_t eusartTxTail = 0;
|
||||
volatile uint8_t eusartTxBuffer[EUSART_TX_BUFFER_SIZE];
|
||||
volatile uint8_t eusartTxBufferRemaining;
|
||||
|
||||
volatile uint8_t eusartRxHead = 0;
|
||||
volatile uint8_t eusartRxTail = 0;
|
||||
volatile uint8_t eusartRxBuffer[EUSART_RX_BUFFER_SIZE];
|
||||
volatile eusart_status_t eusartRxStatusBuffer[EUSART_RX_BUFFER_SIZE];
|
||||
volatile uint8_t eusartRxCount;
|
||||
volatile eusart_status_t eusartRxLastError;
|
||||
|
||||
/**
|
||||
Section: EUSART APIs
|
||||
*/
|
||||
void (*EUSART_TxDefaultInterruptHandler)(void);
|
||||
void (*EUSART_RxDefaultInterruptHandler)(void);
|
||||
|
||||
void (*EUSART_FramingErrorHandler)(void);
|
||||
void (*EUSART_OverrunErrorHandler)(void);
|
||||
void (*EUSART_ErrorHandler)(void);
|
||||
|
||||
void EUSART_DefaultFramingErrorHandler(void);
|
||||
void EUSART_DefaultOverrunErrorHandler(void);
|
||||
void EUSART_DefaultErrorHandler(void);
|
||||
|
||||
void EUSART_Initialize(void)
|
||||
{
|
||||
// disable interrupts before changing states
|
||||
PIE1bits.RCIE = 0;
|
||||
EUSART_SetRxInterruptHandler(EUSART_Receive_ISR);
|
||||
PIE1bits.TXIE = 0;
|
||||
EUSART_SetTxInterruptHandler(EUSART_Transmit_ISR);
|
||||
// Set the EUSART module to the options selected in the user interface.
|
||||
|
||||
// ABDOVF no_overflow; SCKP Non-Inverted; BRG16 16bit_generator; WUE disabled; ABDEN disabled;
|
||||
BAUDCON = 0x08;
|
||||
|
||||
// SPEN enabled; RX9 8-bit; CREN enabled; ADDEN disabled; SREN disabled;
|
||||
RCSTA = 0x90;
|
||||
|
||||
// TX9 8-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC asynchronous; BRGH hi_speed; CSRC slave;
|
||||
TXSTA = 0x24;
|
||||
|
||||
// SPBRGL 8;
|
||||
SPBRGL = 0x08;
|
||||
|
||||
// SPBRGH 0;
|
||||
SPBRGH = 0x00;
|
||||
|
||||
|
||||
EUSART_SetFramingErrorHandler(EUSART_DefaultFramingErrorHandler);
|
||||
EUSART_SetOverrunErrorHandler(EUSART_DefaultOverrunErrorHandler);
|
||||
EUSART_SetErrorHandler(EUSART_DefaultErrorHandler);
|
||||
|
||||
eusartRxLastError.status = 0;
|
||||
|
||||
// initializing the driver state
|
||||
eusartTxHead = 0;
|
||||
eusartTxTail = 0;
|
||||
eusartTxBufferRemaining = sizeof(eusartTxBuffer);
|
||||
|
||||
eusartRxHead = 0;
|
||||
eusartRxTail = 0;
|
||||
eusartRxCount = 0;
|
||||
|
||||
// enable receive interrupt
|
||||
PIE1bits.RCIE = 1;
|
||||
}
|
||||
|
||||
bool EUSART_is_tx_ready(void)
|
||||
{
|
||||
return (eusartTxBufferRemaining ? true : false);
|
||||
}
|
||||
|
||||
bool EUSART_is_rx_ready(void)
|
||||
{
|
||||
return (eusartRxCount ? true : false);
|
||||
}
|
||||
|
||||
bool EUSART_is_tx_done(void)
|
||||
{
|
||||
return TXSTAbits.TRMT;
|
||||
}
|
||||
|
||||
eusart_status_t EUSART_get_last_status(void){
|
||||
return eusartRxLastError;
|
||||
}
|
||||
|
||||
uint8_t EUSART_Read(void)
|
||||
{
|
||||
uint8_t readValue = 0;
|
||||
|
||||
while(0 == eusartRxCount)
|
||||
{
|
||||
}
|
||||
|
||||
eusartRxLastError = eusartRxStatusBuffer[eusartRxTail];
|
||||
|
||||
readValue = eusartRxBuffer[eusartRxTail++];
|
||||
if(sizeof(eusartRxBuffer) <= eusartRxTail)
|
||||
{
|
||||
eusartRxTail = 0;
|
||||
}
|
||||
PIE1bits.RCIE = 0;
|
||||
eusartRxCount--;
|
||||
PIE1bits.RCIE = 1;
|
||||
|
||||
return readValue;
|
||||
}
|
||||
|
||||
void EUSART_Write(uint8_t txData)
|
||||
{
|
||||
while(0 == eusartTxBufferRemaining)
|
||||
{
|
||||
}
|
||||
|
||||
if(0 == PIE1bits.TXIE)
|
||||
{
|
||||
TXREG = txData;
|
||||
}
|
||||
else
|
||||
{
|
||||
PIE1bits.TXIE = 0;
|
||||
eusartTxBuffer[eusartTxHead++] = txData;
|
||||
if(sizeof(eusartTxBuffer) <= eusartTxHead)
|
||||
{
|
||||
eusartTxHead = 0;
|
||||
}
|
||||
eusartTxBufferRemaining--;
|
||||
}
|
||||
PIE1bits.TXIE = 1;
|
||||
}
|
||||
|
||||
char getch(void)
|
||||
{
|
||||
return EUSART_Read();
|
||||
}
|
||||
|
||||
void putch(char txData)
|
||||
{
|
||||
EUSART_Write(txData);
|
||||
}
|
||||
|
||||
void EUSART_Transmit_ISR(void)
|
||||
{
|
||||
|
||||
// add your EUSART interrupt custom code
|
||||
if(sizeof(eusartTxBuffer) > eusartTxBufferRemaining)
|
||||
{
|
||||
TXREG = eusartTxBuffer[eusartTxTail++];
|
||||
if(sizeof(eusartTxBuffer) <= eusartTxTail)
|
||||
{
|
||||
eusartTxTail = 0;
|
||||
}
|
||||
eusartTxBufferRemaining++;
|
||||
}
|
||||
else
|
||||
{
|
||||
PIE1bits.TXIE = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void EUSART_Receive_ISR(void)
|
||||
{
|
||||
|
||||
eusartRxStatusBuffer[eusartRxHead].status = 0;
|
||||
|
||||
if(RCSTAbits.FERR){
|
||||
eusartRxStatusBuffer[eusartRxHead].ferr = 1;
|
||||
EUSART_FramingErrorHandler();
|
||||
}
|
||||
|
||||
if(RCSTAbits.OERR){
|
||||
eusartRxStatusBuffer[eusartRxHead].oerr = 1;
|
||||
EUSART_OverrunErrorHandler();
|
||||
}
|
||||
|
||||
if(eusartRxStatusBuffer[eusartRxHead].status){
|
||||
EUSART_ErrorHandler();
|
||||
} else {
|
||||
EUSART_RxDataHandler();
|
||||
}
|
||||
|
||||
// or set custom function using EUSART_SetRxInterruptHandler()
|
||||
}
|
||||
|
||||
void EUSART_RxDataHandler(void){
|
||||
// use this default receive interrupt handler code
|
||||
eusartRxBuffer[eusartRxHead++] = RCREG;
|
||||
if(sizeof(eusartRxBuffer) <= eusartRxHead)
|
||||
{
|
||||
eusartRxHead = 0;
|
||||
}
|
||||
eusartRxCount++;
|
||||
}
|
||||
|
||||
void EUSART_DefaultFramingErrorHandler(void){}
|
||||
|
||||
void EUSART_DefaultOverrunErrorHandler(void){
|
||||
// EUSART error - restart
|
||||
|
||||
RCSTAbits.CREN = 0;
|
||||
RCSTAbits.CREN = 1;
|
||||
|
||||
}
|
||||
|
||||
void EUSART_DefaultErrorHandler(void){
|
||||
EUSART_RxDataHandler();
|
||||
}
|
||||
|
||||
void EUSART_SetFramingErrorHandler(void (* interruptHandler)(void)){
|
||||
EUSART_FramingErrorHandler = interruptHandler;
|
||||
}
|
||||
|
||||
void EUSART_SetOverrunErrorHandler(void (* interruptHandler)(void)){
|
||||
EUSART_OverrunErrorHandler = interruptHandler;
|
||||
}
|
||||
|
||||
void EUSART_SetErrorHandler(void (* interruptHandler)(void)){
|
||||
EUSART_ErrorHandler = interruptHandler;
|
||||
}
|
||||
|
||||
void EUSART_SetTxInterruptHandler(void (* interruptHandler)(void)){
|
||||
EUSART_TxDefaultInterruptHandler = interruptHandler;
|
||||
}
|
||||
|
||||
void EUSART_SetRxInterruptHandler(void (* interruptHandler)(void)){
|
||||
EUSART_RxDefaultInterruptHandler = interruptHandler;
|
||||
}
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,519 @@
|
||||
/**
|
||||
EUSART Generated Driver API Header File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
eusart.h
|
||||
|
||||
@Summary
|
||||
This is the generated header file for the EUSART driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This header file provides APIs for driver for EUSART.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.1.0
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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 EUSART_H
|
||||
#define EUSART_H
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <xc.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
Section: Macro Declarations
|
||||
*/
|
||||
|
||||
#define EUSART_DataReady (EUSART_is_rx_ready())
|
||||
#define EUSART_TX_BUFFER_SIZE 16
|
||||
#define EUSART_RX_BUFFER_SIZE 16
|
||||
|
||||
/**
|
||||
Section: Data Type Definitions
|
||||
*/
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
unsigned perr : 1;
|
||||
unsigned ferr : 1;
|
||||
unsigned oerr : 1;
|
||||
unsigned reserved : 5;
|
||||
};
|
||||
uint8_t status;
|
||||
}eusart_status_t;
|
||||
|
||||
/**
|
||||
Section: Global variables
|
||||
*/
|
||||
extern volatile uint8_t eusartTxBufferRemaining;
|
||||
extern volatile uint8_t eusartRxCount;
|
||||
|
||||
/**
|
||||
Section: EUSART APIs
|
||||
*/
|
||||
extern void (*EUSART_TxDefaultInterruptHandler)(void);
|
||||
extern void (*EUSART_RxDefaultInterruptHandler)(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Initialization routine that takes inputs from the EUSART GUI.
|
||||
|
||||
@Description
|
||||
This routine initializes the EUSART driver.
|
||||
This routine must be called before any other EUSART routine is called.
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Comment
|
||||
|
||||
*/
|
||||
void EUSART_Initialize(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Checks if the EUSART transmitter is ready to transmit data
|
||||
|
||||
@Description
|
||||
This routine checks if EUSART transmitter is ready
|
||||
to accept and transmit data byte
|
||||
|
||||
@Preconditions
|
||||
EUSART_Initialize() function should have been called
|
||||
before calling this function.
|
||||
EUSART transmitter should be enabled before calling
|
||||
this function
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
Status of EUSART transmitter
|
||||
TRUE: EUSART transmitter is ready
|
||||
FALSE: EUSART 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(EUSART_is_rx_ready())
|
||||
{
|
||||
rxData = UART1_Read();
|
||||
if(EUSART_is_tx_ready())
|
||||
{
|
||||
EUSARTWrite(rxData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
bool EUSART_is_tx_ready(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Checks if the EUSART receiver ready for reading
|
||||
|
||||
@Description
|
||||
This routine checks if EUSART receiver has received data
|
||||
and ready to be read
|
||||
|
||||
@Preconditions
|
||||
EUSART_Initialize() function should be called
|
||||
before calling this function
|
||||
EUSART receiver should be enabled before calling this
|
||||
function
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
Status of EUSART receiver
|
||||
TRUE: EUSART receiver is ready for reading
|
||||
FALSE: EUSART 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(EUSART_is_rx_ready())
|
||||
{
|
||||
rxData = UART1_Read();
|
||||
if(EUSART_is_tx_ready())
|
||||
{
|
||||
EUSART_Write(rxData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
bool EUSART_is_rx_ready(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Checks if EUSART data is transmitted
|
||||
|
||||
@Description
|
||||
This function return the status of transmit shift register
|
||||
|
||||
@Preconditions
|
||||
EUSART_Initialize() function should be called
|
||||
before calling this function
|
||||
EUSART transmitter should be enabled and EUSART_Write
|
||||
should be called before calling this function
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
Status of EUSART 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(EUSART_is_tx_ready())
|
||||
{
|
||||
LED_0_SetHigh();
|
||||
EUSARTWrite(rxData);
|
||||
}
|
||||
if(EUSART_is_tx_done()
|
||||
{
|
||||
LED_0_SetLow();
|
||||
}
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
bool EUSART_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
|
||||
EUSART_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 eusart_status_t rxStatus;
|
||||
|
||||
// Initialize the device
|
||||
SYSTEM_Initialize();
|
||||
|
||||
// Enable the Global Interrupts
|
||||
INTERRUPT_GlobalInterruptEnable();
|
||||
|
||||
while(1)
|
||||
{
|
||||
// Logic to echo received data
|
||||
if(EUSART_is_rx_ready())
|
||||
{
|
||||
rxData = EUSART_Read();
|
||||
rxStatus = EUSART_get_last_status();
|
||||
if(rxStatus.ferr){
|
||||
LED_0_SetHigh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
eusart_status_t EUSART_get_last_status(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Read a byte of data from the EUSART.
|
||||
|
||||
@Description
|
||||
This routine reads a byte of data from the EUSART.
|
||||
|
||||
@Preconditions
|
||||
EUSART_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 EUSART_Read(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Writes a byte of data to the EUSART.
|
||||
|
||||
@Description
|
||||
This routine writes a byte of data to the EUSART.
|
||||
|
||||
@Preconditions
|
||||
EUSART_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 EUSART
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void EUSART_Write(uint8_t txData);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Maintains the driver's transmitter state machine and implements its ISR.
|
||||
|
||||
@Description
|
||||
This routine is used to maintain the driver's internal transmitter state
|
||||
machine.This interrupt service routine is called when the state of the
|
||||
transmitter needs to be maintained in a non polled manner.
|
||||
|
||||
@Preconditions
|
||||
EUSART_Initialize() function should have been called
|
||||
for the ISR to execute correctly.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void EUSART_Transmit_ISR(void);
|
||||
|
||||
/**
|
||||
@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
|
||||
EUSART_Initialize() function should have been called
|
||||
for the ISR to execute correctly.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void EUSART_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
|
||||
EUSART_Initialize() function should have been called
|
||||
for the ISR to execute correctly.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void EUSART_RxDataHandler(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Set EUSART Framing Error Handler
|
||||
|
||||
@Description
|
||||
This API sets the function to be called upon EUSART framing error
|
||||
|
||||
@Preconditions
|
||||
Initialize the EUSART before calling this API
|
||||
|
||||
@Param
|
||||
Address of function to be set as framing error handler
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void EUSART_SetFramingErrorHandler(void (* interruptHandler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Set EUSART Overrun Error Handler
|
||||
|
||||
@Description
|
||||
This API sets the function to be called upon EUSART overrun error
|
||||
|
||||
@Preconditions
|
||||
Initialize the EUSART module before calling this API
|
||||
|
||||
@Param
|
||||
Address of function to be set as overrun error handler
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void EUSART_SetOverrunErrorHandler(void (* interruptHandler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Set EUSART Error Handler
|
||||
|
||||
@Description
|
||||
This API sets the function to be called upon EUSART error
|
||||
|
||||
@Preconditions
|
||||
Initialize the EUSART module before calling this API
|
||||
|
||||
@Param
|
||||
Address of function to be set as error handler
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void EUSART_SetErrorHandler(void (* interruptHandler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Sets the transmit 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 transmit interrupt needs servicing.
|
||||
|
||||
@Preconditions
|
||||
EUSART_Initialize() function should have been called
|
||||
for the ISR to execute correctly.
|
||||
|
||||
@Param
|
||||
A pointer to the new function
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void EUSART_SetTxInterruptHandler(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
|
||||
EUSART_Initialize() function should have been called
|
||||
for the ISR to execute correctly.
|
||||
|
||||
@Param
|
||||
A pointer to the new function
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void EUSART_SetRxInterruptHandler(void (* interruptHandler)(void));
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // EUSART_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
FVR Generated Driver File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
fvr.c
|
||||
|
||||
@Summary
|
||||
This is the generated driver implementation file for the FVR driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This source file provides APIs for FVR.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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 "fvr.h"
|
||||
|
||||
/**
|
||||
Section: FVR APIs
|
||||
*/
|
||||
|
||||
void FVR_Initialize(void)
|
||||
{
|
||||
// CDAFVR off; FVREN enabled; TSRNG Lo_range; ADFVR 2x; TSEN enabled;
|
||||
FVRCON = 0xA2;
|
||||
}
|
||||
|
||||
bool FVR_IsOutputReady(void)
|
||||
{
|
||||
return (FVRCONbits.FVRRDY);
|
||||
}
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
FVR Generated Driver API Header File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
fvr.h
|
||||
|
||||
@Summary
|
||||
This is the generated header file for the FVR driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This header file provides APIs for driver for FVR.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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 FVR_H
|
||||
#define FVR_H
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
Section: FVR APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Initializes the FVR
|
||||
|
||||
@Description
|
||||
This routine initializes the FVR.
|
||||
This routine must be called before any other FVR routine is called.
|
||||
This routine should only be called once during system initialization.
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Comment
|
||||
|
||||
|
||||
@Example
|
||||
<code>
|
||||
FVR_Initialize();
|
||||
</code>
|
||||
*/
|
||||
void FVR_Initialize(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Gets the FVR output ready status.
|
||||
|
||||
@Description
|
||||
This routine gets the FVR output ready status.
|
||||
|
||||
@Preconditions
|
||||
The FVR_Initialize() routine should be called
|
||||
prior to use this routine.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
true - FVR module is ready for use.
|
||||
false - FVR module is not ready for use.
|
||||
|
||||
@Example
|
||||
<code>
|
||||
FVR_Initialize();
|
||||
|
||||
if(FVR_IsOutputReady())
|
||||
{
|
||||
//user code
|
||||
}
|
||||
else
|
||||
{
|
||||
//user code
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
bool FVR_IsOutputReady(void);
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // FVR_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
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.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.03
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above or later
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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() INTERRUPT_InterruptManager (void)
|
||||
{
|
||||
// interrupt handler
|
||||
if(INTCONbits.IOCIE == 1 && INTCONbits.IOCIF == 1)
|
||||
{
|
||||
PIN_MANAGER_IOC();
|
||||
}
|
||||
else if(INTCONbits.PEIE == 1)
|
||||
{
|
||||
if(PIE1bits.RCIE == 1 && PIR1bits.RCIF == 1)
|
||||
{
|
||||
EUSART_RxDefaultInterruptHandler();
|
||||
}
|
||||
else if(PIE1bits.TXIE == 1 && PIR1bits.TXIF == 1)
|
||||
{
|
||||
EUSART_TxDefaultInterruptHandler();
|
||||
}
|
||||
else if(PIE1bits.TMR2IE == 1 && PIR1bits.TMR2IF == 1)
|
||||
{
|
||||
TMR2_ISR();
|
||||
}
|
||||
else if(PIE1bits.TMR1IE == 1 && PIR1bits.TMR1IF == 1)
|
||||
{
|
||||
TMR1_ISR();
|
||||
}
|
||||
else
|
||||
{
|
||||
//Unhandled Interrupt
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Unhandled Interrupt
|
||||
}
|
||||
}
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
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.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.03
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above or later
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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)
|
||||
|
||||
|
||||
#endif // INTERRUPT_MANAGER_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
@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.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.00
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above or later
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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)
|
||||
{
|
||||
|
||||
PIN_MANAGER_Initialize();
|
||||
OSCILLATOR_Initialize();
|
||||
WDT_Initialize();
|
||||
FVR_Initialize();
|
||||
ADC_Initialize();
|
||||
TMR2_Initialize();
|
||||
TMR1_Initialize();
|
||||
EUSART_Initialize();
|
||||
}
|
||||
|
||||
void OSCILLATOR_Initialize(void)
|
||||
{
|
||||
// SCS INTOSC; SPLLEN disabled; IRCF 4MHz_HF;
|
||||
OSCCON = 0x6A;
|
||||
// TUN 0;
|
||||
OSCTUNE = 0x00;
|
||||
// SBOREN disabled;
|
||||
BORCON = 0x00;
|
||||
}
|
||||
|
||||
void WDT_Initialize(void)
|
||||
{
|
||||
// WDTPS 1:65536; SWDTEN OFF;
|
||||
WDTCON = 0x16;
|
||||
}
|
||||
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
@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.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.00
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above or later
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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 "tmr1.h"
|
||||
#include "tmr2.h"
|
||||
#include "fvr.h"
|
||||
#include "memory.h"
|
||||
#include "adc.h"
|
||||
#include "eusart.h"
|
||||
#include "delay.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);
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Initializes the WDT module to the default states configured in the
|
||||
* MCC GUI
|
||||
* @Example
|
||||
WDT_Initialize(void);
|
||||
*/
|
||||
void WDT_Initialize(void);
|
||||
|
||||
#endif /* MCC_H */
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,224 @@
|
||||
/**
|
||||
MEMORY Generated Driver File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
memory.c
|
||||
|
||||
@Summary
|
||||
This is the generated driver implementation file for the MEMORY driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This source file provides implementations of driver APIs for MEMORY.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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 "memory.h"
|
||||
|
||||
/**
|
||||
Section: Flash Module APIs
|
||||
*/
|
||||
|
||||
uint16_t FLASH_ReadWord(uint16_t flashAddr)
|
||||
{
|
||||
uint8_t GIEBitValue = INTCONbits.GIE; // Save interrupt enable
|
||||
|
||||
INTCONbits.GIE = 0; // Disable interrupts
|
||||
EEADRL = (flashAddr & 0x00FF);
|
||||
EEADRH = ((flashAddr & 0xFF00) >> 8);
|
||||
|
||||
EECON1bits.CFGS = 0; // Deselect Configuration space
|
||||
EECON1bits.EEPGD = 1; // Select Program Memory
|
||||
EECON1bits.RD = 1; // Initiate Read
|
||||
NOP();
|
||||
NOP();
|
||||
INTCONbits.GIE = GIEBitValue; // Restore interrupt enable
|
||||
|
||||
return ((uint16_t)((EEDATH << 8) | EEDATL));
|
||||
}
|
||||
|
||||
void FLASH_WriteWord(uint16_t flashAddr, uint16_t *ramBuf, uint16_t word)
|
||||
{
|
||||
uint16_t blockStartAddr = (uint16_t)(flashAddr & ((END_FLASH-1) ^ (ERASE_FLASH_BLOCKSIZE-1)));
|
||||
uint8_t offset = (uint8_t)(flashAddr & (ERASE_FLASH_BLOCKSIZE-1));
|
||||
uint8_t i;
|
||||
|
||||
// Entire row will be erased, read and save the existing data
|
||||
for (i=0; i<ERASE_FLASH_BLOCKSIZE; i++)
|
||||
{
|
||||
ramBuf[i] = FLASH_ReadWord((blockStartAddr+i));
|
||||
}
|
||||
|
||||
// Write at offset
|
||||
ramBuf[offset] = word;
|
||||
|
||||
// Writes ramBuf to current block
|
||||
FLASH_WriteBlock(blockStartAddr, ramBuf);
|
||||
}
|
||||
|
||||
int8_t FLASH_WriteBlock(uint16_t writeAddr, uint16_t *flashWordArray)
|
||||
{
|
||||
uint16_t blockStartAddr = (uint16_t )(writeAddr & ((END_FLASH-1) ^ (ERASE_FLASH_BLOCKSIZE-1)));
|
||||
uint8_t GIEBitValue = INTCONbits.GIE; // Save interrupt enable
|
||||
uint8_t i,j,numberOfWriteBlocks=0,dataCounter=0;
|
||||
|
||||
numberOfWriteBlocks = (ERASE_FLASH_BLOCKSIZE/WRITE_FLASH_BLOCKSIZE);
|
||||
|
||||
// Flash write must start at the beginning of a row
|
||||
if( writeAddr != blockStartAddr )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
INTCONbits.GIE = 0; // Disable interrupts
|
||||
|
||||
// Block erase sequence
|
||||
FLASH_EraseBlock(writeAddr);
|
||||
|
||||
for(j=0; j<numberOfWriteBlocks; j++)
|
||||
{
|
||||
// Block write sequence
|
||||
EECON1bits.EEPGD = 1; // Select Program Memory
|
||||
EECON1bits.CFGS = 0; // Deselect Configuration space
|
||||
EECON1bits.WREN = 1; // Enable writes
|
||||
EECON1bits.LWLO = 1; // Only load write latches
|
||||
|
||||
for (i=0; i<WRITE_FLASH_BLOCKSIZE; i++)
|
||||
{
|
||||
// Load lower 8 bits of write address
|
||||
EEADRL = (writeAddr & 0xFF);
|
||||
// Load upper 6 bits of write address
|
||||
EEADRH = ((writeAddr & 0xFF00) >> 8);
|
||||
|
||||
// Load data in current address
|
||||
EEDATL = flashWordArray[dataCounter];
|
||||
EEDATH = ((flashWordArray[dataCounter] & 0xFF00) >> 8);
|
||||
dataCounter++;
|
||||
|
||||
if(i == (WRITE_FLASH_BLOCKSIZE-1))
|
||||
{
|
||||
// Start Flash program memory write
|
||||
EECON1bits.LWLO = 0;
|
||||
}
|
||||
|
||||
EECON2 = 0x55;
|
||||
EECON2 = 0xAA;
|
||||
EECON1bits.WR = 1;
|
||||
NOP();
|
||||
NOP();
|
||||
|
||||
writeAddr++;
|
||||
}
|
||||
}
|
||||
|
||||
EECON1bits.WREN = 0; // Disable writes
|
||||
INTCONbits.GIE = GIEBitValue; // Restore interrupt enable
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FLASH_EraseBlock(uint16_t startAddr)
|
||||
{
|
||||
uint8_t GIEBitValue = INTCONbits.GIE; // Save interrupt enable
|
||||
|
||||
INTCONbits.GIE = 0; // Disable interrupts
|
||||
// Load lower 8 bits of erase address boundary
|
||||
EEADRL = (startAddr & 0xFF);
|
||||
// Load upper 6 bits of erase address boundary
|
||||
EEADRH = ((startAddr & 0xFF00) >> 8);
|
||||
|
||||
// Block erase sequence
|
||||
EECON1bits.CFGS = 0; // Deselect Configuration space
|
||||
EECON1bits.EEPGD = 1; // Select Program Memory
|
||||
EECON1bits.FREE = 1; // Specify an erase operation
|
||||
EECON1bits.WREN = 1; // Allows erase cycles
|
||||
|
||||
// Start of required sequence to initiate erase
|
||||
EECON2 = 0x55;
|
||||
EECON2 = 0xAA;
|
||||
EECON1bits.WR = 1; // Set WR bit to begin erase
|
||||
NOP();
|
||||
NOP();
|
||||
|
||||
EECON1bits.WREN = 0; // Disable writes
|
||||
INTCONbits.GIE = GIEBitValue; // Restore interrupt enable
|
||||
}
|
||||
|
||||
/**
|
||||
Section: Data EEPROM Module APIs
|
||||
*/
|
||||
|
||||
void DATAEE_WriteByte(uint8_t bAdd, uint8_t bData)
|
||||
{
|
||||
uint8_t GIEBitValue = 0;
|
||||
|
||||
EEADRL = (uint8_t)(bAdd & 0x0ff); // Data Memory Address to write
|
||||
EEDATL = bData; // Data Memory Value to write
|
||||
EECON1bits.EEPGD = 0; // Point to DATA memory
|
||||
EECON1bits.CFGS = 0; // Deselect Configuration space
|
||||
EECON1bits.WREN = 1; // Enable writes
|
||||
|
||||
GIEBitValue = INTCONbits.GIE;
|
||||
INTCONbits.GIE = 0; // Disable INTs
|
||||
EECON2 = 0x55;
|
||||
EECON2 = 0xAA;
|
||||
EECON1bits.WR = 1; // Set WR bit to begin write
|
||||
// Wait for write to complete
|
||||
while (EECON1bits.WR)
|
||||
{
|
||||
}
|
||||
|
||||
EECON1bits.WREN = 0; // Disable writes
|
||||
INTCONbits.GIE = GIEBitValue;
|
||||
}
|
||||
|
||||
uint8_t DATAEE_ReadByte(uint8_t bAdd)
|
||||
{
|
||||
EEADRL = (uint8_t)(bAdd & 0x0ff); // Data Memory Address to read
|
||||
EECON1bits.CFGS = 0; // Deselect Configuration space
|
||||
EECON1bits.EEPGD = 0; // Point to DATA memory
|
||||
EECON1bits.RD = 1; // EE Read
|
||||
NOP(); // NOPs may be required for latency at high frequencies
|
||||
NOP();
|
||||
|
||||
return (EEDATL);
|
||||
}
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,257 @@
|
||||
/**
|
||||
MEMORY Generated Driver API Header File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
memory.h
|
||||
|
||||
@Summary
|
||||
This is the generated header file for the MEMORY driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This header file provides APIs for driver for MEMORY.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
(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 MEMORY_H
|
||||
#define MEMORY_H
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
Section: Macro Declarations
|
||||
*/
|
||||
|
||||
#define WRITE_FLASH_BLOCKSIZE 32
|
||||
#define ERASE_FLASH_BLOCKSIZE 32
|
||||
#define END_FLASH 0x2000
|
||||
|
||||
/**
|
||||
Section: Flash Module APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Reads a word from Flash
|
||||
|
||||
@Description
|
||||
This routine reads a word from given Flash address
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
flashAddr - Flash program memory location from which data has to be read
|
||||
|
||||
@Returns
|
||||
Data word read from given Flash address
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint16_t readWord;
|
||||
uint16_t flashAddr = 0x01C0;
|
||||
|
||||
readWord = FLASH_ReadWord(flashAddr);
|
||||
</code>
|
||||
*/
|
||||
uint16_t FLASH_ReadWord(uint16_t flashAddr);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Writes a word into Flash
|
||||
|
||||
@Description
|
||||
This routine writes the given word into mentioned Flash address
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
flashAddr - Flash program memory location to which data has to be written
|
||||
*ramBuf - Pointer to an array of size 'ERASE_FLASH_BLOCKSIZE' at least
|
||||
word - Word to be written in Flash
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint16_t writeData = 0x55AA;
|
||||
uint16_t flashAddr = 0x01C0;
|
||||
uint16_t Buf[ERASE_FLASH_BLOCKSIZE];
|
||||
|
||||
FLASH_WriteWord(flashAddr, Buf, writeData);
|
||||
</code>
|
||||
*/
|
||||
void FLASH_WriteWord(uint16_t flashAddr, uint16_t *ramBuf, uint16_t word);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Writes data to complete block of Flash
|
||||
|
||||
@Description
|
||||
This routine writes data words to complete block in Flash program memory
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
writeAddr - A valid block starting address in Flash
|
||||
*flashWordArray - Pointer to an array of size 'WRITE_FLASH_BLOCKSIZE' at least
|
||||
|
||||
@Returns
|
||||
-1 if the given address is not a valid block starting address of Flash
|
||||
0 in case of valid block starting address
|
||||
|
||||
@Example
|
||||
<code>
|
||||
#define FLASH_ROW_ADDRESS 0x01C0
|
||||
|
||||
uint16_t wrBlockData[] =
|
||||
{
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000D, 0x000F,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F
|
||||
}
|
||||
|
||||
// write to Flash memory block
|
||||
FLASH_WriteBlock((uint16_t)FLASH_ROW_ADDRESS, (uint16_t*)wrBlockData);
|
||||
</code>
|
||||
*/
|
||||
int8_t FLASH_WriteBlock(uint16_t writeAddr, uint16_t *flashWordArray);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Erases complete Flash program memory block
|
||||
|
||||
@Description
|
||||
This routine erases complete Flash program memory block
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
startAddr - A valid block starting address in Flash program memory
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint16_t flashBlockStartAddr = 0x01C0;
|
||||
|
||||
FLASH_EraseBlock(flashBlockStartAddr);
|
||||
</code>
|
||||
*/
|
||||
void FLASH_EraseBlock(uint16_t startAddr);
|
||||
|
||||
/**
|
||||
Section: Data EEPROM Module APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Writes a data byte to Data EEPROM
|
||||
|
||||
@Description
|
||||
This routine writes a data byte to given Data EEPROM location
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
bAdd - Data EEPROM location to which data to be written
|
||||
bData - Data to be written to Data EEPROM location
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint8_t dataeeAddr = 0x10;
|
||||
uint8_t dataeeData = 0x55;
|
||||
|
||||
DATAEE_WriteByte(dataeeAddr, dataeeData);
|
||||
</code>
|
||||
*/
|
||||
void DATAEE_WriteByte(uint8_t bAdd, uint8_t bData);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Reads a data byte from Data EEPROM
|
||||
|
||||
@Description
|
||||
This routine reads a data byte from given Data EEPROM location
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
bAdd - Data EEPROM location from which data has to be read
|
||||
|
||||
@Returns
|
||||
Data byte read from given Data EEPROM location
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint8_t dataeeAddr = 0x10;
|
||||
uint8_t readData;
|
||||
|
||||
readData = DATAEE_ReadByte(dataeeAddr);
|
||||
</code>
|
||||
*/
|
||||
uint8_t DATAEE_ReadByte(uint8_t bAdd);
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // MEMORY_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,199 @@
|
||||
/**
|
||||
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.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.11
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "pin_manager.h"
|
||||
|
||||
|
||||
|
||||
|
||||
void (*IOCAF4_InterruptHandler)(void);
|
||||
void (*IOCAF5_InterruptHandler)(void);
|
||||
|
||||
|
||||
void PIN_MANAGER_Initialize(void)
|
||||
{
|
||||
/**
|
||||
LATx registers
|
||||
*/
|
||||
LATA = 0x00;
|
||||
LATB = 0x00;
|
||||
LATC = 0x00;
|
||||
|
||||
/**
|
||||
TRISx registers
|
||||
*/
|
||||
TRISA = 0x3F;
|
||||
TRISB = 0x90;
|
||||
TRISC = 0x33;
|
||||
|
||||
/**
|
||||
ANSELx registers
|
||||
*/
|
||||
ANSELC = 0x03;
|
||||
ANSELB = 0x10;
|
||||
ANSELA = 0x07;
|
||||
|
||||
/**
|
||||
WPUx registers
|
||||
*/
|
||||
WPUB = 0x00;
|
||||
WPUA = 0x30;
|
||||
WPUC = 0x00;
|
||||
OPTION_REGbits.nWPUEN = 0;
|
||||
|
||||
|
||||
/**
|
||||
APFCONx registers
|
||||
*/
|
||||
APFCON0 = 0x84;
|
||||
APFCON1 = 0x00;
|
||||
|
||||
/**
|
||||
IOCx registers
|
||||
*/
|
||||
//interrupt on change for group IOCAF - flag
|
||||
IOCAFbits.IOCAF4 = 0;
|
||||
//interrupt on change for group IOCAF - flag
|
||||
IOCAFbits.IOCAF5 = 0;
|
||||
//interrupt on change for group IOCAN - negative
|
||||
IOCANbits.IOCAN4 = 1;
|
||||
//interrupt on change for group IOCAN - negative
|
||||
IOCANbits.IOCAN5 = 1;
|
||||
//interrupt on change for group IOCAP - positive
|
||||
IOCAPbits.IOCAP4 = 1;
|
||||
//interrupt on change for group IOCAP - positive
|
||||
IOCAPbits.IOCAP5 = 1;
|
||||
|
||||
|
||||
|
||||
// register default IOC callback functions at runtime; use these methods to register a custom function
|
||||
IOCAF4_SetInterruptHandler(IOCAF4_DefaultInterruptHandler);
|
||||
IOCAF5_SetInterruptHandler(IOCAF5_DefaultInterruptHandler);
|
||||
|
||||
// Enable IOCI interrupt
|
||||
INTCONbits.IOCIE = 1;
|
||||
|
||||
}
|
||||
|
||||
void PIN_MANAGER_IOC(void)
|
||||
{
|
||||
// interrupt on change for pin IOCAF4
|
||||
if(IOCAFbits.IOCAF4 == 1)
|
||||
{
|
||||
IOCAF4_ISR();
|
||||
}
|
||||
// interrupt on change for pin IOCAF5
|
||||
if(IOCAFbits.IOCAF5 == 1)
|
||||
{
|
||||
IOCAF5_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
IOCAF4 Interrupt Service Routine
|
||||
*/
|
||||
void IOCAF4_ISR(void) {
|
||||
|
||||
// Add custom IOCAF4 code
|
||||
|
||||
// Call the interrupt handler for the callback registered at runtime
|
||||
if(IOCAF4_InterruptHandler)
|
||||
{
|
||||
IOCAF4_InterruptHandler();
|
||||
}
|
||||
IOCAFbits.IOCAF4 = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Allows selecting an interrupt handler for IOCAF4 at application runtime
|
||||
*/
|
||||
void IOCAF4_SetInterruptHandler(void (* InterruptHandler)(void)){
|
||||
IOCAF4_InterruptHandler = InterruptHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
Default interrupt handler for IOCAF4
|
||||
*/
|
||||
void IOCAF4_DefaultInterruptHandler(void){
|
||||
// add your IOCAF4 interrupt custom code
|
||||
// or set custom function using IOCAF4_SetInterruptHandler()
|
||||
}
|
||||
|
||||
/**
|
||||
IOCAF5 Interrupt Service Routine
|
||||
*/
|
||||
void IOCAF5_ISR(void) {
|
||||
|
||||
// Add custom IOCAF5 code
|
||||
|
||||
// Call the interrupt handler for the callback registered at runtime
|
||||
if(IOCAF5_InterruptHandler)
|
||||
{
|
||||
IOCAF5_InterruptHandler();
|
||||
}
|
||||
IOCAFbits.IOCAF5 = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Allows selecting an interrupt handler for IOCAF5 at application runtime
|
||||
*/
|
||||
void IOCAF5_SetInterruptHandler(void (* InterruptHandler)(void)){
|
||||
IOCAF5_InterruptHandler = InterruptHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
Default interrupt handler for IOCAF5
|
||||
*/
|
||||
void IOCAF5_DefaultInterruptHandler(void){
|
||||
// add your IOCAF5 interrupt custom code
|
||||
// or set custom function using IOCAF5_SetInterruptHandler()
|
||||
}
|
||||
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,449 @@
|
||||
/**
|
||||
@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 APIs for driver for .
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.11
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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 BT_Stat1 aliases
|
||||
#define BT_Stat1_TRIS TRISAbits.TRISA4
|
||||
#define BT_Stat1_LAT LATAbits.LATA4
|
||||
#define BT_Stat1_PORT PORTAbits.RA4
|
||||
#define BT_Stat1_WPU WPUAbits.WPUA4
|
||||
#define BT_Stat1_ANS ANSELAbits.ANSA4
|
||||
#define BT_Stat1_SetHigh() do { LATAbits.LATA4 = 1; } while(0)
|
||||
#define BT_Stat1_SetLow() do { LATAbits.LATA4 = 0; } while(0)
|
||||
#define BT_Stat1_Toggle() do { LATAbits.LATA4 = ~LATAbits.LATA4; } while(0)
|
||||
#define BT_Stat1_GetValue() PORTAbits.RA4
|
||||
#define BT_Stat1_SetDigitalInput() do { TRISAbits.TRISA4 = 1; } while(0)
|
||||
#define BT_Stat1_SetDigitalOutput() do { TRISAbits.TRISA4 = 0; } while(0)
|
||||
#define BT_Stat1_SetPullup() do { WPUAbits.WPUA4 = 1; } while(0)
|
||||
#define BT_Stat1_ResetPullup() do { WPUAbits.WPUA4 = 0; } while(0)
|
||||
#define BT_Stat1_SetAnalogMode() do { ANSELAbits.ANSA4 = 1; } while(0)
|
||||
#define BT_Stat1_SetDigitalMode() do { ANSELAbits.ANSA4 = 0; } while(0)
|
||||
|
||||
// get/set BT_Stat2 aliases
|
||||
#define BT_Stat2_TRIS TRISAbits.TRISA5
|
||||
#define BT_Stat2_LAT LATAbits.LATA5
|
||||
#define BT_Stat2_PORT PORTAbits.RA5
|
||||
#define BT_Stat2_WPU WPUAbits.WPUA5
|
||||
#define BT_Stat2_SetHigh() do { LATAbits.LATA5 = 1; } while(0)
|
||||
#define BT_Stat2_SetLow() do { LATAbits.LATA5 = 0; } while(0)
|
||||
#define BT_Stat2_Toggle() do { LATAbits.LATA5 = ~LATAbits.LATA5; } while(0)
|
||||
#define BT_Stat2_GetValue() PORTAbits.RA5
|
||||
#define BT_Stat2_SetDigitalInput() do { TRISAbits.TRISA5 = 1; } while(0)
|
||||
#define BT_Stat2_SetDigitalOutput() do { TRISAbits.TRISA5 = 0; } while(0)
|
||||
#define BT_Stat2_SetPullup() do { WPUAbits.WPUA5 = 1; } while(0)
|
||||
#define BT_Stat2_ResetPullup() do { WPUAbits.WPUA5 = 0; } while(0)
|
||||
|
||||
// get/set Led2 aliases
|
||||
#define Led2_TRIS TRISBbits.TRISB5
|
||||
#define Led2_LAT LATBbits.LATB5
|
||||
#define Led2_PORT PORTBbits.RB5
|
||||
#define Led2_WPU WPUBbits.WPUB5
|
||||
#define Led2_ANS ANSELBbits.ANSB5
|
||||
#define Led2_SetHigh() do { LATBbits.LATB5 = 1; } while(0)
|
||||
#define Led2_SetLow() do { LATBbits.LATB5 = 0; } while(0)
|
||||
#define Led2_Toggle() do { LATBbits.LATB5 = ~LATBbits.LATB5; } while(0)
|
||||
#define Led2_GetValue() PORTBbits.RB5
|
||||
#define Led2_SetDigitalInput() do { TRISBbits.TRISB5 = 1; } while(0)
|
||||
#define Led2_SetDigitalOutput() do { TRISBbits.TRISB5 = 0; } while(0)
|
||||
#define Led2_SetPullup() do { WPUBbits.WPUB5 = 1; } while(0)
|
||||
#define Led2_ResetPullup() do { WPUBbits.WPUB5 = 0; } while(0)
|
||||
#define Led2_SetAnalogMode() do { ANSELBbits.ANSB5 = 1; } while(0)
|
||||
#define Led2_SetDigitalMode() do { ANSELBbits.ANSB5 = 0; } while(0)
|
||||
|
||||
// get/set Led aliases
|
||||
#define Led_TRIS TRISBbits.TRISB6
|
||||
#define Led_LAT LATBbits.LATB6
|
||||
#define Led_PORT PORTBbits.RB6
|
||||
#define Led_WPU WPUBbits.WPUB6
|
||||
#define Led_SetHigh() do { LATBbits.LATB6 = 1; } while(0)
|
||||
#define Led_SetLow() do { LATBbits.LATB6 = 0; } while(0)
|
||||
#define Led_Toggle() do { LATBbits.LATB6 = ~LATBbits.LATB6; } while(0)
|
||||
#define Led_GetValue() PORTBbits.RB6
|
||||
#define Led_SetDigitalInput() do { TRISBbits.TRISB6 = 1; } while(0)
|
||||
#define Led_SetDigitalOutput() do { TRISBbits.TRISB6 = 0; } while(0)
|
||||
#define Led_SetPullup() do { WPUBbits.WPUB6 = 1; } while(0)
|
||||
#define Led_ResetPullup() do { WPUBbits.WPUB6 = 0; } while(0)
|
||||
|
||||
// get/set A_S1 aliases
|
||||
#define A_S1_TRIS TRISCbits.TRISC0
|
||||
#define A_S1_LAT LATCbits.LATC0
|
||||
#define A_S1_PORT PORTCbits.RC0
|
||||
#define A_S1_WPU WPUCbits.WPUC0
|
||||
#define A_S1_ANS ANSELCbits.ANSC0
|
||||
#define A_S1_SetHigh() do { LATCbits.LATC0 = 1; } while(0)
|
||||
#define A_S1_SetLow() do { LATCbits.LATC0 = 0; } while(0)
|
||||
#define A_S1_Toggle() do { LATCbits.LATC0 = ~LATCbits.LATC0; } while(0)
|
||||
#define A_S1_GetValue() PORTCbits.RC0
|
||||
#define A_S1_SetDigitalInput() do { TRISCbits.TRISC0 = 1; } while(0)
|
||||
#define A_S1_SetDigitalOutput() do { TRISCbits.TRISC0 = 0; } while(0)
|
||||
#define A_S1_SetPullup() do { WPUCbits.WPUC0 = 1; } while(0)
|
||||
#define A_S1_ResetPullup() do { WPUCbits.WPUC0 = 0; } while(0)
|
||||
#define A_S1_SetAnalogMode() do { ANSELCbits.ANSC0 = 1; } while(0)
|
||||
#define A_S1_SetDigitalMode() do { ANSELCbits.ANSC0 = 0; } while(0)
|
||||
|
||||
// get/set A_S2 aliases
|
||||
#define A_S2_TRIS TRISCbits.TRISC1
|
||||
#define A_S2_LAT LATCbits.LATC1
|
||||
#define A_S2_PORT PORTCbits.RC1
|
||||
#define A_S2_WPU WPUCbits.WPUC1
|
||||
#define A_S2_ANS ANSELCbits.ANSC1
|
||||
#define A_S2_SetHigh() do { LATCbits.LATC1 = 1; } while(0)
|
||||
#define A_S2_SetLow() do { LATCbits.LATC1 = 0; } while(0)
|
||||
#define A_S2_Toggle() do { LATCbits.LATC1 = ~LATCbits.LATC1; } while(0)
|
||||
#define A_S2_GetValue() PORTCbits.RC1
|
||||
#define A_S2_SetDigitalInput() do { TRISCbits.TRISC1 = 1; } while(0)
|
||||
#define A_S2_SetDigitalOutput() do { TRISCbits.TRISC1 = 0; } while(0)
|
||||
#define A_S2_SetPullup() do { WPUCbits.WPUC1 = 1; } while(0)
|
||||
#define A_S2_ResetPullup() do { WPUCbits.WPUC1 = 0; } while(0)
|
||||
#define A_S2_SetAnalogMode() do { ANSELCbits.ANSC1 = 1; } while(0)
|
||||
#define A_S2_SetDigitalMode() do { ANSELCbits.ANSC1 = 0; } while(0)
|
||||
|
||||
// get/set O_Vbrd aliases
|
||||
#define O_Vbrd_TRIS TRISCbits.TRISC2
|
||||
#define O_Vbrd_LAT LATCbits.LATC2
|
||||
#define O_Vbrd_PORT PORTCbits.RC2
|
||||
#define O_Vbrd_WPU WPUCbits.WPUC2
|
||||
#define O_Vbrd_ANS ANSELCbits.ANSC2
|
||||
#define O_Vbrd_SetHigh() do { LATCbits.LATC2 = 1; } while(0)
|
||||
#define O_Vbrd_SetLow() do { LATCbits.LATC2 = 0; } while(0)
|
||||
#define O_Vbrd_Toggle() do { LATCbits.LATC2 = ~LATCbits.LATC2; } while(0)
|
||||
#define O_Vbrd_GetValue() PORTCbits.RC2
|
||||
#define O_Vbrd_SetDigitalInput() do { TRISCbits.TRISC2 = 1; } while(0)
|
||||
#define O_Vbrd_SetDigitalOutput() do { TRISCbits.TRISC2 = 0; } while(0)
|
||||
#define O_Vbrd_SetPullup() do { WPUCbits.WPUC2 = 1; } while(0)
|
||||
#define O_Vbrd_ResetPullup() do { WPUCbits.WPUC2 = 0; } while(0)
|
||||
#define O_Vbrd_SetAnalogMode() do { ANSELCbits.ANSC2 = 1; } while(0)
|
||||
#define O_Vbrd_SetDigitalMode() do { ANSELCbits.ANSC2 = 0; } while(0)
|
||||
|
||||
// get/set BT_RxInd aliases
|
||||
#define BT_RxInd_TRIS TRISCbits.TRISC3
|
||||
#define BT_RxInd_LAT LATCbits.LATC3
|
||||
#define BT_RxInd_PORT PORTCbits.RC3
|
||||
#define BT_RxInd_WPU WPUCbits.WPUC3
|
||||
#define BT_RxInd_ANS ANSELCbits.ANSC3
|
||||
#define BT_RxInd_SetHigh() do { LATCbits.LATC3 = 1; } while(0)
|
||||
#define BT_RxInd_SetLow() do { LATCbits.LATC3 = 0; } while(0)
|
||||
#define BT_RxInd_Toggle() do { LATCbits.LATC3 = ~LATCbits.LATC3; } while(0)
|
||||
#define BT_RxInd_GetValue() PORTCbits.RC3
|
||||
#define BT_RxInd_SetDigitalInput() do { TRISCbits.TRISC3 = 1; } while(0)
|
||||
#define BT_RxInd_SetDigitalOutput() do { TRISCbits.TRISC3 = 0; } while(0)
|
||||
#define BT_RxInd_SetPullup() do { WPUCbits.WPUC3 = 1; } while(0)
|
||||
#define BT_RxInd_ResetPullup() do { WPUCbits.WPUC3 = 0; } while(0)
|
||||
#define BT_RxInd_SetAnalogMode() do { ANSELCbits.ANSC3 = 1; } while(0)
|
||||
#define BT_RxInd_SetDigitalMode() do { ANSELCbits.ANSC3 = 0; } while(0)
|
||||
|
||||
// get/set RC4 procedures
|
||||
#define RC4_SetHigh() do { LATCbits.LATC4 = 1; } while(0)
|
||||
#define RC4_SetLow() do { LATCbits.LATC4 = 0; } while(0)
|
||||
#define RC4_Toggle() do { LATCbits.LATC4 = ~LATCbits.LATC4; } while(0)
|
||||
#define RC4_GetValue() PORTCbits.RC4
|
||||
#define RC4_SetDigitalInput() do { TRISCbits.TRISC4 = 1; } while(0)
|
||||
#define RC4_SetDigitalOutput() do { TRISCbits.TRISC4 = 0; } while(0)
|
||||
#define RC4_SetPullup() do { WPUCbits.WPUC4 = 1; } while(0)
|
||||
#define RC4_ResetPullup() do { WPUCbits.WPUC4 = 0; } while(0)
|
||||
|
||||
// get/set RC5 procedures
|
||||
#define RC5_SetHigh() do { LATCbits.LATC5 = 1; } while(0)
|
||||
#define RC5_SetLow() do { LATCbits.LATC5 = 0; } while(0)
|
||||
#define RC5_Toggle() do { LATCbits.LATC5 = ~LATCbits.LATC5; } while(0)
|
||||
#define RC5_GetValue() PORTCbits.RC5
|
||||
#define RC5_SetDigitalInput() do { TRISCbits.TRISC5 = 1; } while(0)
|
||||
#define RC5_SetDigitalOutput() do { TRISCbits.TRISC5 = 0; } while(0)
|
||||
#define RC5_SetPullup() do { WPUCbits.WPUC5 = 1; } while(0)
|
||||
#define RC5_ResetPullup() do { WPUCbits.WPUC5 = 0; } while(0)
|
||||
|
||||
// get/set BT_Rst aliases
|
||||
#define BT_Rst_TRIS TRISCbits.TRISC6
|
||||
#define BT_Rst_LAT LATCbits.LATC6
|
||||
#define BT_Rst_PORT PORTCbits.RC6
|
||||
#define BT_Rst_WPU WPUCbits.WPUC6
|
||||
#define BT_Rst_ANS ANSELCbits.ANSC6
|
||||
#define BT_Rst_SetHigh() do { LATCbits.LATC6 = 1; } while(0)
|
||||
#define BT_Rst_SetLow() do { LATCbits.LATC6 = 0; } while(0)
|
||||
#define BT_Rst_Toggle() do { LATCbits.LATC6 = ~LATCbits.LATC6; } while(0)
|
||||
#define BT_Rst_GetValue() PORTCbits.RC6
|
||||
#define BT_Rst_SetDigitalInput() do { TRISCbits.TRISC6 = 1; } while(0)
|
||||
#define BT_Rst_SetDigitalOutput() do { TRISCbits.TRISC6 = 0; } while(0)
|
||||
#define BT_Rst_SetPullup() do { WPUCbits.WPUC6 = 1; } while(0)
|
||||
#define BT_Rst_ResetPullup() do { WPUCbits.WPUC6 = 0; } while(0)
|
||||
#define BT_Rst_SetAnalogMode() do { ANSELCbits.ANSC6 = 1; } while(0)
|
||||
#define BT_Rst_SetDigitalMode() do { ANSELCbits.ANSC6 = 0; } while(0)
|
||||
|
||||
// get/set BT_Mode aliases
|
||||
#define BT_Mode_TRIS TRISCbits.TRISC7
|
||||
#define BT_Mode_LAT LATCbits.LATC7
|
||||
#define BT_Mode_PORT PORTCbits.RC7
|
||||
#define BT_Mode_WPU WPUCbits.WPUC7
|
||||
#define BT_Mode_ANS ANSELCbits.ANSC7
|
||||
#define BT_Mode_SetHigh() do { LATCbits.LATC7 = 1; } while(0)
|
||||
#define BT_Mode_SetLow() do { LATCbits.LATC7 = 0; } while(0)
|
||||
#define BT_Mode_Toggle() do { LATCbits.LATC7 = ~LATCbits.LATC7; } while(0)
|
||||
#define BT_Mode_GetValue() PORTCbits.RC7
|
||||
#define BT_Mode_SetDigitalInput() do { TRISCbits.TRISC7 = 1; } while(0)
|
||||
#define BT_Mode_SetDigitalOutput() do { TRISCbits.TRISC7 = 0; } while(0)
|
||||
#define BT_Mode_SetPullup() do { WPUCbits.WPUC7 = 1; } while(0)
|
||||
#define BT_Mode_ResetPullup() do { WPUCbits.WPUC7 = 0; } while(0)
|
||||
#define BT_Mode_SetAnalogMode() do { ANSELCbits.ANSC7 = 1; } while(0)
|
||||
#define BT_Mode_SetDigitalMode() do { ANSELCbits.ANSC7 = 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);
|
||||
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Interrupt on Change Handler for the IOCAF4 pin functionality
|
||||
* @Example
|
||||
IOCAF4_ISR();
|
||||
*/
|
||||
void IOCAF4_ISR(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Interrupt Handler Setter for IOCAF4 pin interrupt-on-change functionality
|
||||
|
||||
@Description
|
||||
Allows selecting an interrupt handler for IOCAF4 at application runtime
|
||||
|
||||
@Preconditions
|
||||
Pin Manager intializer called
|
||||
|
||||
@Returns
|
||||
None.
|
||||
|
||||
@Param
|
||||
InterruptHandler function pointer.
|
||||
|
||||
@Example
|
||||
PIN_MANAGER_Initialize();
|
||||
IOCAF4_SetInterruptHandler(MyInterruptHandler);
|
||||
|
||||
*/
|
||||
void IOCAF4_SetInterruptHandler(void (* InterruptHandler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Dynamic Interrupt Handler for IOCAF4 pin
|
||||
|
||||
@Description
|
||||
This is a dynamic interrupt handler to be used together with the IOCAF4_SetInterruptHandler() method.
|
||||
This handler is called every time the IOCAF4 ISR is executed and allows any function to be registered at runtime.
|
||||
|
||||
@Preconditions
|
||||
Pin Manager intializer called
|
||||
|
||||
@Returns
|
||||
None.
|
||||
|
||||
@Param
|
||||
None.
|
||||
|
||||
@Example
|
||||
PIN_MANAGER_Initialize();
|
||||
IOCAF4_SetInterruptHandler(IOCAF4_InterruptHandler);
|
||||
|
||||
*/
|
||||
extern void (*IOCAF4_InterruptHandler)(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Default Interrupt Handler for IOCAF4 pin
|
||||
|
||||
@Description
|
||||
This is a predefined interrupt handler to be used together with the IOCAF4_SetInterruptHandler() method.
|
||||
This handler is called every time the IOCAF4 ISR is executed.
|
||||
|
||||
@Preconditions
|
||||
Pin Manager intializer called
|
||||
|
||||
@Returns
|
||||
None.
|
||||
|
||||
@Param
|
||||
None.
|
||||
|
||||
@Example
|
||||
PIN_MANAGER_Initialize();
|
||||
IOCAF4_SetInterruptHandler(IOCAF4_DefaultInterruptHandler);
|
||||
|
||||
*/
|
||||
void IOCAF4_DefaultInterruptHandler(void);
|
||||
|
||||
|
||||
/**
|
||||
* @Param
|
||||
none
|
||||
* @Returns
|
||||
none
|
||||
* @Description
|
||||
Interrupt on Change Handler for the IOCAF5 pin functionality
|
||||
* @Example
|
||||
IOCAF5_ISR();
|
||||
*/
|
||||
void IOCAF5_ISR(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Interrupt Handler Setter for IOCAF5 pin interrupt-on-change functionality
|
||||
|
||||
@Description
|
||||
Allows selecting an interrupt handler for IOCAF5 at application runtime
|
||||
|
||||
@Preconditions
|
||||
Pin Manager intializer called
|
||||
|
||||
@Returns
|
||||
None.
|
||||
|
||||
@Param
|
||||
InterruptHandler function pointer.
|
||||
|
||||
@Example
|
||||
PIN_MANAGER_Initialize();
|
||||
IOCAF5_SetInterruptHandler(MyInterruptHandler);
|
||||
|
||||
*/
|
||||
void IOCAF5_SetInterruptHandler(void (* InterruptHandler)(void));
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Dynamic Interrupt Handler for IOCAF5 pin
|
||||
|
||||
@Description
|
||||
This is a dynamic interrupt handler to be used together with the IOCAF5_SetInterruptHandler() method.
|
||||
This handler is called every time the IOCAF5 ISR is executed and allows any function to be registered at runtime.
|
||||
|
||||
@Preconditions
|
||||
Pin Manager intializer called
|
||||
|
||||
@Returns
|
||||
None.
|
||||
|
||||
@Param
|
||||
None.
|
||||
|
||||
@Example
|
||||
PIN_MANAGER_Initialize();
|
||||
IOCAF5_SetInterruptHandler(IOCAF5_InterruptHandler);
|
||||
|
||||
*/
|
||||
extern void (*IOCAF5_InterruptHandler)(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Default Interrupt Handler for IOCAF5 pin
|
||||
|
||||
@Description
|
||||
This is a predefined interrupt handler to be used together with the IOCAF5_SetInterruptHandler() method.
|
||||
This handler is called every time the IOCAF5 ISR is executed.
|
||||
|
||||
@Preconditions
|
||||
Pin Manager intializer called
|
||||
|
||||
@Returns
|
||||
None.
|
||||
|
||||
@Param
|
||||
None.
|
||||
|
||||
@Example
|
||||
PIN_MANAGER_Initialize();
|
||||
IOCAF5_SetInterruptHandler(IOCAF5_DefaultInterruptHandler);
|
||||
|
||||
*/
|
||||
void IOCAF5_DefaultInterruptHandler(void);
|
||||
|
||||
|
||||
|
||||
#endif // PIN_MANAGER_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
TMR1 Generated Driver File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
tmr1.c
|
||||
|
||||
@Summary
|
||||
This is the generated driver implementation file for the TMR1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This source file provides APIs for TMR1.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.11
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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 "tmr1.h"
|
||||
|
||||
/**
|
||||
Section: Global Variables Definitions
|
||||
*/
|
||||
volatile uint16_t timer1ReloadVal;
|
||||
void (*TMR1_InterruptHandler)(void);
|
||||
|
||||
/**
|
||||
Section: TMR1 APIs
|
||||
*/
|
||||
|
||||
void TMR1_Initialize(void)
|
||||
{
|
||||
//Set the Timer to the options selected in the GUI
|
||||
|
||||
//T1GSS T1G_pin; TMR1GE disabled; T1GTM disabled; T1GPOL low; T1GGO done; T1GSPM disabled;
|
||||
T1GCON = 0x00;
|
||||
|
||||
//TMR1H 11;
|
||||
TMR1H = 0x0B;
|
||||
|
||||
//TMR1L 220;
|
||||
TMR1L = 0xDC;
|
||||
|
||||
// Clearing IF flag before enabling the interrupt.
|
||||
PIR1bits.TMR1IF = 0;
|
||||
|
||||
// Load the TMR value to reload variable
|
||||
timer1ReloadVal=(uint16_t)((TMR1H << 8) | TMR1L);
|
||||
|
||||
// Enabling TMR1 interrupt.
|
||||
PIE1bits.TMR1IE = 1;
|
||||
|
||||
// Set Default Interrupt Handler
|
||||
TMR1_SetInterruptHandler(TMR1_DefaultInterruptHandler);
|
||||
|
||||
// T1CKPS 1:8; T1OSCEN disabled; nT1SYNC do_not_synchronize; TMR1CS FOSC/4; TMR1ON enabled;
|
||||
T1CON = 0x35;
|
||||
}
|
||||
|
||||
void TMR1_StartTimer(void)
|
||||
{
|
||||
// Start the Timer by writing to TMRxON bit
|
||||
T1CONbits.TMR1ON = 1;
|
||||
}
|
||||
|
||||
void TMR1_StopTimer(void)
|
||||
{
|
||||
// Stop the Timer by writing to TMRxON bit
|
||||
T1CONbits.TMR1ON = 0;
|
||||
}
|
||||
|
||||
uint16_t TMR1_ReadTimer(void)
|
||||
{
|
||||
uint16_t readVal;
|
||||
uint8_t readValHigh;
|
||||
uint8_t readValLow;
|
||||
|
||||
|
||||
readValLow = TMR1L;
|
||||
readValHigh = TMR1H;
|
||||
|
||||
readVal = ((uint16_t)readValHigh << 8) | readValLow;
|
||||
|
||||
return readVal;
|
||||
}
|
||||
|
||||
void TMR1_WriteTimer(uint16_t timerVal)
|
||||
{
|
||||
if (T1CONbits.nT1SYNC == 1)
|
||||
{
|
||||
// Stop the Timer by writing to TMRxON bit
|
||||
T1CONbits.TMR1ON = 0;
|
||||
|
||||
// Write to the Timer1 register
|
||||
TMR1H = (timerVal >> 8);
|
||||
TMR1L = timerVal;
|
||||
|
||||
// Start the Timer after writing to the register
|
||||
T1CONbits.TMR1ON =1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write to the Timer1 register
|
||||
TMR1H = (timerVal >> 8);
|
||||
TMR1L = timerVal;
|
||||
}
|
||||
}
|
||||
|
||||
void TMR1_Reload(void)
|
||||
{
|
||||
TMR1_WriteTimer(timer1ReloadVal);
|
||||
}
|
||||
|
||||
void TMR1_StartSinglePulseAcquisition(void)
|
||||
{
|
||||
T1GCONbits.T1GGO = 1;
|
||||
}
|
||||
|
||||
uint8_t TMR1_CheckGateValueStatus(void)
|
||||
{
|
||||
return (T1GCONbits.T1GVAL);
|
||||
}
|
||||
|
||||
void TMR1_ISR(void)
|
||||
{
|
||||
static volatile unsigned int CountCallBack = 0;
|
||||
|
||||
// Clear the TMR1 interrupt flag
|
||||
PIR1bits.TMR1IF = 0;
|
||||
TMR1_WriteTimer(timer1ReloadVal);
|
||||
|
||||
// callback function - called every 2th pass
|
||||
if (++CountCallBack >= TMR1_INTERRUPT_TICKER_FACTOR)
|
||||
{
|
||||
// ticker function call
|
||||
TMR1_CallBack();
|
||||
|
||||
// reset ticker counter
|
||||
CountCallBack = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TMR1_CallBack(void)
|
||||
{
|
||||
// Add your custom callback code here
|
||||
if(TMR1_InterruptHandler)
|
||||
{
|
||||
TMR1_InterruptHandler();
|
||||
}
|
||||
}
|
||||
|
||||
void TMR1_SetInterruptHandler(void (* InterruptHandler)(void)){
|
||||
TMR1_InterruptHandler = InterruptHandler;
|
||||
}
|
||||
|
||||
void TMR1_DefaultInterruptHandler(void){
|
||||
// add your TMR1 interrupt custom code
|
||||
// or set custom function using TMR1_SetInterruptHandler()
|
||||
}
|
||||
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,450 @@
|
||||
/**
|
||||
TMR1 Generated Driver API Header File
|
||||
|
||||
@Company
|
||||
Microchip Technology Inc.
|
||||
|
||||
@File Name
|
||||
tmr1.h
|
||||
|
||||
@Summary
|
||||
This is the generated header file for the TMR1 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs
|
||||
|
||||
@Description
|
||||
This header file provides APIs for driver for TMR1.
|
||||
Generation Information :
|
||||
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.11
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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 TMR1_H
|
||||
#define TMR1_H
|
||||
|
||||
/**
|
||||
Section: Included Files
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
#define TMR1_INTERRUPT_TICKER_FACTOR 2
|
||||
|
||||
/**
|
||||
Section: TMR1 APIs
|
||||
*/
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Initializes the TMR1
|
||||
|
||||
@Description
|
||||
This routine initializes the TMR1.
|
||||
This routine must be called before any other TMR1 routine is called.
|
||||
This routine should only be called once during system initialization.
|
||||
|
||||
@Preconditions
|
||||
None
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Comment
|
||||
|
||||
|
||||
@Example
|
||||
<code>
|
||||
main()
|
||||
{
|
||||
// Initialize TMR1 module
|
||||
TMR1_Initialize();
|
||||
|
||||
// Do something else...
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void TMR1_Initialize(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
This function starts the TMR1.
|
||||
|
||||
@Description
|
||||
This function starts the TMR1 operation.
|
||||
This function must be called after the initialization of TMR1.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR1 before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
// Initialize TMR1 module
|
||||
|
||||
// Start TMR1
|
||||
TMR1_StartTimer();
|
||||
|
||||
// Do something else...
|
||||
</code>
|
||||
*/
|
||||
void TMR1_StartTimer(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
This function stops the TMR1.
|
||||
|
||||
@Description
|
||||
This function stops the TMR1 operation.
|
||||
This function must be called after the start of TMR1.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR1 before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
// Initialize TMR1 module
|
||||
|
||||
// Start TMR1
|
||||
TMR1_StartTimer();
|
||||
|
||||
// Do something else...
|
||||
|
||||
// Stop TMR1;
|
||||
TMR1_StopTimer();
|
||||
</code>
|
||||
*/
|
||||
void TMR1_StopTimer(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Reads the TMR1 register.
|
||||
|
||||
@Description
|
||||
This function reads the TMR1 register value and return it.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR1 before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
This function returns the current value of TMR1 register.
|
||||
|
||||
@Example
|
||||
<code>
|
||||
// Initialize TMR1 module
|
||||
|
||||
// Start TMR1
|
||||
TMR1_StartTimer();
|
||||
|
||||
// Read the current value of TMR1
|
||||
if(0 == TMR1_ReadTimer())
|
||||
{
|
||||
// Do something else...
|
||||
|
||||
// Reload the TMR value
|
||||
TMR1_Reload();
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
uint16_t TMR1_ReadTimer(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Writes the TMR1 register.
|
||||
|
||||
@Description
|
||||
This function writes the TMR1 register.
|
||||
This function must be called after the initialization of TMR1.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR1 before calling this function.
|
||||
|
||||
@Param
|
||||
timerVal - Value to write into TMR1 register.
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
#define PERIOD 0x80
|
||||
#define ZERO 0x00
|
||||
|
||||
while(1)
|
||||
{
|
||||
// Read the TMR1 register
|
||||
if(ZERO == TMR1_ReadTimer())
|
||||
{
|
||||
// Do something else...
|
||||
|
||||
// Write the TMR1 register
|
||||
TMR1_WriteTimer(PERIOD);
|
||||
}
|
||||
|
||||
// Do something else...
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void TMR1_WriteTimer(uint16_t timerVal);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Reload the TMR1 register.
|
||||
|
||||
@Description
|
||||
This function reloads the TMR1 register.
|
||||
This function must be called to write initial value into TMR1 register.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR1 before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
while(1)
|
||||
{
|
||||
if(TMR1IF)
|
||||
{
|
||||
// Do something else...
|
||||
|
||||
// clear the TMR1 interrupt flag
|
||||
TMR1IF = 0;
|
||||
|
||||
// Reload the initial value of TMR1
|
||||
TMR1_Reload();
|
||||
}
|
||||
}
|
||||
</code>
|
||||
*/
|
||||
void TMR1_Reload(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Starts the single pulse acquisition in TMR1 gate operation.
|
||||
|
||||
@Description
|
||||
This function starts the single pulse acquisition in TMR1 gate operation.
|
||||
This function must be used when the TMR1 gate is enabled.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR1 with gate enable before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint16_t xVal;
|
||||
uint16_t yVal;
|
||||
|
||||
// enable TMR1 singlepulse mode
|
||||
TMR1_StartSinglePulseAcquistion();
|
||||
|
||||
// check TMR1 gate status
|
||||
if(TMR1_CheckGateValueStatus()== 0)
|
||||
xVal = TMR1_ReadTimer();
|
||||
|
||||
// wait untill gate interrupt occured
|
||||
while(TMR1GIF == 0)
|
||||
{
|
||||
}
|
||||
|
||||
yVal = TMR1_ReadTimer();
|
||||
</code>
|
||||
*/
|
||||
void TMR1_StartSinglePulseAcquisition(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Check the current state of Timer1 gate.
|
||||
|
||||
@Description
|
||||
This function reads the TMR1 gate value and return it.
|
||||
This function must be used when the TMR1 gate is enabled.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR1 with gate enable before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
|
||||
@Example
|
||||
<code>
|
||||
uint16_t xVal;
|
||||
uint16_t yVal;
|
||||
|
||||
// enable TMR1 singlepulse mode
|
||||
TMR1_StartSinglePulseAcquistion();
|
||||
|
||||
// check TMR1 gate status
|
||||
if(TMR1_CheckGateValueStatus()== 0)
|
||||
xVal = TMR1_ReadTimer();
|
||||
|
||||
// wait untill gate interrupt occured
|
||||
while(TMR1IF == 0)
|
||||
{
|
||||
}
|
||||
|
||||
yVal = TMR1_ReadTimer();
|
||||
</code>
|
||||
*/
|
||||
uint8_t TMR1_CheckGateValueStatus(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Timer Interrupt Service Routine
|
||||
|
||||
@Description
|
||||
Timer Interrupt Service Routine is called by the Interrupt Manager.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR1 module with interrupt before calling this ISR.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void TMR1_ISR(void);
|
||||
/**
|
||||
@Summary
|
||||
CallBack function.
|
||||
|
||||
@Description
|
||||
This routine is called by the Interrupt Manager.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR1 module with interrupt before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void TMR1_CallBack(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Set Timer Interrupt Handler
|
||||
|
||||
@Description
|
||||
This sets the function to be called during the ISR
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR1 module with interrupt before calling this.
|
||||
|
||||
@Param
|
||||
Address of function to be set
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void TMR1_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 TMR1 module with interrupt before calling this isr.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
extern void (*TMR1_InterruptHandler)(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Default Timer Interrupt Handler
|
||||
|
||||
@Description
|
||||
This is the default Interrupt Handler function
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR1 module with interrupt before calling this isr.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void TMR1_DefaultInterruptHandler(void);
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // TMR1_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
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.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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
|
||||
*/
|
||||
|
||||
void (*TMR2_InterruptHandler)(void);
|
||||
|
||||
/**
|
||||
Section: TMR2 APIs
|
||||
*/
|
||||
|
||||
void TMR2_Initialize(void)
|
||||
{
|
||||
// Set TMR2 to the options selected in the User Interface
|
||||
|
||||
// PR2 249;
|
||||
PR2 = 0xF9;
|
||||
|
||||
// TMR2 0;
|
||||
TMR2 = 0x00;
|
||||
|
||||
// Clearing IF flag before enabling the interrupt.
|
||||
PIR1bits.TMR2IF = 0;
|
||||
|
||||
// Enabling TMR2 interrupt.
|
||||
PIE1bits.TMR2IE = 1;
|
||||
|
||||
// Set Default Interrupt Handler
|
||||
TMR2_SetInterruptHandler(TMR2_DefaultInterruptHandler);
|
||||
|
||||
// T2CKPS 1:64; T2OUTPS 1:16; TMR2ON on;
|
||||
T2CON = 0x7F;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void TMR2_ISR(void)
|
||||
{
|
||||
static volatile unsigned int CountCallBack = 0;
|
||||
|
||||
// clear the TMR2 interrupt flag
|
||||
PIR1bits.TMR2IF = 0;
|
||||
|
||||
// callback function - called every 8th pass
|
||||
if (++CountCallBack >= TMR2_INTERRUPT_TICKER_FACTOR)
|
||||
{
|
||||
// ticker function call
|
||||
TMR2_CallBack();
|
||||
|
||||
// reset ticker counter
|
||||
CountCallBack = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TMR2_CallBack(void)
|
||||
{
|
||||
// Add your custom callback code here
|
||||
// this code executes every TMR2_INTERRUPT_TICKER_FACTOR periods of TMR2
|
||||
if(TMR2_InterruptHandler)
|
||||
{
|
||||
TMR2_InterruptHandler();
|
||||
}
|
||||
}
|
||||
|
||||
void TMR2_SetInterruptHandler(void (* InterruptHandler)(void)){
|
||||
TMR2_InterruptHandler = InterruptHandler;
|
||||
}
|
||||
|
||||
void TMR2_DefaultInterruptHandler(void){
|
||||
// add your TMR2 interrupt custom code
|
||||
// or set custom function using TMR2_SetInterruptHandler()
|
||||
}
|
||||
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
@@ -0,0 +1,393 @@
|
||||
/**
|
||||
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.6
|
||||
Device : PIC16F1829
|
||||
Driver Version : 2.01
|
||||
The generated drivers are tested against the following:
|
||||
Compiler : XC8 2.30 and above
|
||||
MPLAB : MPLAB X 5.40
|
||||
*/
|
||||
|
||||
/*
|
||||
(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
|
||||
*/
|
||||
#define TMR2_INTERRUPT_TICKER_FACTOR 8
|
||||
|
||||
/**
|
||||
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
|
||||
Timer Interrupt Service Routine
|
||||
|
||||
@Description
|
||||
Timer Interrupt Service Routine is called by the Interrupt Manager.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR2 module with interrupt before calling this isr.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void TMR2_ISR(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
CallBack function
|
||||
|
||||
@Description
|
||||
This function is called from the timer ISR. User can write your code in this function.
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR2 module with interrupt before calling this function.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void TMR2_CallBack(void);
|
||||
/**
|
||||
@Summary
|
||||
Set Timer Interrupt Handler
|
||||
|
||||
@Description
|
||||
This sets the function to be called during the ISR
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR2 module with interrupt before calling this.
|
||||
|
||||
@Param
|
||||
Address of function to be set
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void TMR2_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 TMR2 module with interrupt before calling this isr.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
extern void (*TMR2_InterruptHandler)(void);
|
||||
|
||||
/**
|
||||
@Summary
|
||||
Default Timer Interrupt Handler
|
||||
|
||||
@Description
|
||||
This is the default Interrupt Handler function
|
||||
|
||||
@Preconditions
|
||||
Initialize the TMR2 module with interrupt before calling this isr.
|
||||
|
||||
@Param
|
||||
None
|
||||
|
||||
@Returns
|
||||
None
|
||||
*/
|
||||
void TMR2_DefaultInterruptHandler(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // TMR2_H
|
||||
/**
|
||||
End of File
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user