1 Data Visualizer Run Time (DVRT) Library Overview
The MCC Melody Data Visualizer Run Time (DVRT) Library supports the DVRT functionality of the MPLAB® Data Visualizer on a host computer. The DVRT Library allows the user to "watch" and plot project variables at run time on the Data Visualizer plugin window.
1.1 Data Visualizer Run Time Basics




1.1.1 MCC Melody DV Run Time Configuration
1.1.1.1 MCC Content Manager: Add Melody Data Streamer Library
Since the Data Streamer is not default content, it may be missing from Device Resources.

In this case, click the button to open the MCC Content Manager.





1.1.1.2 Builder: Add DV Run Time Library
Application Builder: Click 'Add Component'.

Filter on 'Data' then click the icon to add the DV Run Time.


- Timer Dependency Selection: Select any available timer. The Timer driver default of 1 ms, with interrupts enabled is used.
- UART Dependency Selection: Determine the UART instance connected to
your computer's COM port, which could be a Virtual Serial Port (CDC). Check
the board layout schematic on the MCU side to find the UART instance and the
Device Manager for Windows or on a Mac terminal type
ls /dev/tty.*
to find which serial port the UART is connected to.Note: CDC refers to USB Communications Class Device.Note: For Curiosity Nano boards, this is usually the UART instance connected to the debugger. Using USB-to-Serial bridges will also work. Here, the Data Visualizer will automatically detect the COM port of the connected kit.Note: UART Software Receive Buffer Size is calculated by the DV Run Time Library: Receive buffer for DVRT Frame needs to fit the largest command, i.e., UpdateVariablePtrTableCmd, which is 28 bytes by default, when NumVars is 8. Frame calculation: Start_Byte + Cmd_Byte + NumVars_Byte + (NumVars * 3 Bytes) + End_Byte.
1.1.1.3 Connecting MPLAB Data Visualizer DvrtProtocol options to Melody Library fields
The image below shows the MPLAB Data Visualizer integrated into MPLAB X IDE, with an DVRT Protocol Session on the left hand side and the configuration options for the MCC Melody DV Run Time library on the right hand side.
- API Prefix: This text will be the prefix for all API associated with the DVRT.
- Number of Dynamic
Variables: This number has to be higher or equal to (>=) the
number of variables in the DVRT Streaming Table in the Data Visualizer. On the
Data Visualizer side, this is configured by setting the number of Streaming
Slots.
Figure 1-5. MPLAB Data Visualizer DvrtProtocol Session (PC side, on left) with DV Run Time Library (MCU side, on right) - Project FW Code: Can be
used to distinguish between different projects. The Data Visualizer compares the
Firmware Code read from the target to an expected value. A warning is displayed
if the values don't match.Note: The default value of the Project Firmware Code matches the Expected FM Code in the Data Visualizer.Note: This Project Firmware Code is used in the
DVRunTime_Config.h
.Note: In the DVRT library, the U suffix (e.g., 8U, 20U, 200U) denotes an unsigned integer constant, ensuring MISRA-compliant type clarity and safe use with types like uint8_t or uint16_t.
1.1.2 DV Run Time Implementation
Responsibilities: MCU Side and HOST PC Side

- MPLAB X IDE MCU Project is
compiled and an
.elf
file produced. - The
.elf
file is loaded in the Data Visualizer.Note: Choose the debug or production version of the.elf
, matching your compilation settings. - A Parser script is used to
generate a list of variables. Note: For volatile variables, this
.elf
file contains their name, address and type (length in bytes), i.e., at compile time, it is known where volatile variables will be located in the Microcontroller's RAM. - DVRT Streaming Table is used to select variables of interest to watch at run time.
- As variables are selected,
the DVRT command UPDATE_VARIABLE_POINTER_TABLE is sent to the
microcontroller to add these variables to a Dynamic Variables Pointer
Monitor Table (DVPMT). Note: For each variable, this is the address of the variable in the MCU's RAM, and the number of bytes is saved.
- The values of variables are fetched from specific locations in RAM and the Dynamic Output Buffer now contains updated values of each variable in the DVRT Streaming Table.
- Data Output Buffer sent over UART to Data Visualizer.
- Variable values updated in the DVRT Streaming Table.
Data Stream Protocol Format
The DV Run Time at the lowest level implements the Data Stream protocol to send data to the Data Visualizer.
The Data Stream Format is processed in the same order as the variables specified in the Variable Streamer. All data must be given as little-endian values, meaning sending the lowest byte first. Additionally, the Data Streamer Protocol requires a start byte and an end byte which are each other's complement (~). For example, if the startByte is: 0b0000 0011, the endByte will be 0b1111 1100. This wrapper, consisting of one byte before and one byte after the data stream variables, is used by the interpreter to synchronize it to the data stream. The start byte can be arbitrary, but the end byte must be the inverse of the start byte.

1.1.3 Data Visualizer Setup for DV Run Time


.elf
file. To increase the likelihood that a
variable's debug symbol can be found, set the variable to volatile and/or static. .elf
file contains their name, address and type (length in bytes), i.e., at compile time, it
is known where volatile variables will be located in the Microcontroller's RAM.- Within MPLAB X click the
icon to open the MPLAB Data Visualizer.
- Click the
button to see the current DVRT session or to start a new one.
Tip: A new DVRT session will open as follows: ->. - Next one needs to select a data
source matching the DVRT protocol format. This will be the COM port (UART) that was
configured as a dependency to the MCC Melody DV Run Time Library.
- Configure the Data Visualizer COM
Settings (PC side) to match what was configured in the MCC Melody DV Run Time
Library (MCU side).
- Next, load the
.elf
debug symbols file.Attention: Choose between the debug and the production version of the.elf
whichever matches the compilation settings.- Debug, if you are in a debug session
- Production, if you
have simply programmed your MCU
- Add variables to DVRT Streaming
Table.Tip: The volatile and static variables will show up in the symbols file.
- Reposition DVRT Streaming Table.
Tip: One can drag the DVRT Streaming Table to the bottom pannel of the Data Visualizer, to view this table at the same time as the Time Plot of variables.
- Once the Plot all variables button
is clicked, the DVRT Procol starts streaming and the Time Plot starts rolling.
1.2 MCC Melody Important References
- MCC Melody Technical Reference - Introduction
- MCC Melody Components
- MCC and MCC Melody API References (MCU Families: AVR , PIC16F / PIC18F, dsPIC33)
1.3 Supported Device Families
All Supported 8- and 16-bit devices in Melody.
1.4 Required Header Files:
#include "mcc_generated_files/DVRT/DVRunTime.h"
1.5 How to Use the Data Visualizer Run Time Library
- Count_msTicksSinceToggle is incremented up to toggle_ms, when LED_ON is toggled


1.6 DV Run Time API Reference
1.6.1 Module Documentation
1.6.1.1 DV Run Time
1.6.1.1.1 Module description
This file contains the API prototypes for the dvruntime driver module.
Data structures
struct DVRT_interface_t
Structure containing the function pointers to the DV Run Time driver APIs.
struct DVRT_VariablePointerTableEntry
Defines one entry of the Variable Pointer Table.
struct DVRT_StreamUpdates
Defines the data structure for updating the stream of variables sent to the Data Visualizer.
struct DVRT_VariableUpdate
Defines the data structure needed to update the Variable Pointer Table (DVPMT).
struct DVRT_StreamIntervalUpdate
Defines the data structure for updating the streaming period of frames sent from the DVRT to the Data Visualizer.
struct DVRT_CommandTemplate
Typedef for struct containing the elements needed for a generic DVRT command.
Functions
void DVRT_UART_WriteByte (uint8_t txData)
This blocking function writes a byte of data to the selected UART.
void DVRT_Initialize (void)
Initializes the DVRT driver. Sets the variable values to their initial values and registers error callback functions for UART errors.
void DVRT_Process (void)
Processes the DVRT driver. Checks the UART for incoming data and processes the data if it is available. It also checks for time-out conditions and triggers the periodic sending of data, if required. Finally, it executes one-shot readings and ping commands.
Variables
const DVRT_interface_t DVRT
Declaration of the DVRT interface and its function pointers.
1.6.1.1.2 Function Documentation
DVRT_Initialize()
void DVRT_Initialize (void )
Initializes the DVRT driver. Sets the variable values to their initial values and registers error callback functions for UART errors.
None. |
None. |
DVRT_Process()
void DVRT_Process (void )
Processes the DVRT driver. Checks the UART for incoming data and processes the data if it is available. It also checks for time-out conditions and triggers the periodic sending of data if required. Finally, it executes one-shot readings and ping commands.
None. |
None. |
DVRT_UART_WriteByte()
void DVRT_UART_WriteByte (uint8_t txData)
This blocking function writes a byte of data to the selected UART.
The transfer status is checked to see if the transmitter is ready to accept a byte before UART->Write() |
txData |
- Data byte to write to the TX FIFO |
None. |
1.6.1.1.3 Variable Documentation
DVRT
const DVRT_interface_t DVRT
Declaration of the DVRT interface and its function pointers.
Section: Included Files Section: Data Type Definitions
1.6.2 Data Structure Documentation
1.6.2.1 DVCmds Union Reference
1.6.2.1.1 Data Fields
1.6.2.1.2 Field Documentation
DVCmdArray
uint8_t DVCmdArray[sizeof(DVRT_StreamUpdates_t)]
generic
DVRT_CommandTemplate_t generic
interval
DVRT_StreamIntervalUpdate_t interval
stream
DVRT_StreamUpdates_t stream
Var
DVRT_VariableUpdate_t Var
1.6.2.2 DVRT_CommandTemplate Struct Reference
Typedef for struct containing the elements needed for a generic DVRT command.
1.6.2.2.1 Detailed Description
Typedef for struct containing the elements needed for a generic DVRT command.
#include <DVRunTime_types.h>
Data Fields
uint8_t startOfFrame
uint8_t command
uint8_t data
uint8_t endOfFrame
1.6.2.2.2 Field Documentation
command
uint8_t command
data
uint8_t data
endOfFrame
uint8_t endOfFrame
startOfFrame
uint8_t startOfFrame
1.6.2.3 DVRT_interface_t Struct Reference
Structure containing the function pointers to the DV Run Time driver APIs.
1.6.2.3.1 Detailed Description
Structure containing the function pointers to the DV Run Time driver APIs.
Section: Included Files Selecion: Data Type Definitions
#include <DVRunTime_interface.h>
Data Fields
void(* Initialize )(void)
void(* Process )(void)
1.6.2.3.2 Field Documentation
The documentation for this struct was generated from the following file:
source/
Initialize
void(* Initialize) (void)
Process
void(* Process) (void)
1.6.2.4 DVRT_StreamIntervalUpdate Struct Reference
Defines the data structure for updating the streaming period of frames sent from the DVRT to the Data Visualizer.
1.6.2.4.1 Detailed Description
Defines the data structure for updating the streaming period of frames sent from the DVRT to the Data Visualizer.
#include <DVRunTime_types.h>
Data Fields
uint8_t startOfFrame
uint8_t command
uint16_t period
uint8_t endOfFrame
1.6.2.4.2 Field Documentation
command
uint8_t command
endOfFrame
uint8_t endOfFrame
period
uint16_t period
startOfFrame
uint8_t startOfFrame
1.6.2.5 DVRT_StreamUpdates Struct Reference
Defines the data structure for updating the stream of variables sent to the Data Visualizer.
1.6.2.5.1 Detailed Description
Defines the data structure for updating the stream of variables sent to the Data Visualizer.
#include <DVRunTime_types.h>
Data Fields
uint8_t startOfFrame
uint8_t command
uint8_t size
DVRT_VariablePointerTableEntry_t DVPMT [DYNAMIC_VAR_PTR_COUNT]
uint8_t endOfFrame
1.6.2.5.2 Field Documentation
command
uint8_t command
DVPMT
DVRT_VariablePointerTableEntry_t DVPMT[DYNAMIC_VAR_PTR_COUNT]
endOfFrame
uint8_t endOfFrame
size
uint8_t size
startOfFrame
uint8_t startOfFrame
1.6.2.6 DVRT_VariablePointerTableEntry Struct Reference
Defines one entry of the Variable Pointer Table.
1.6.2.6.1 Detailed Description
Defines one entry of the Variable Pointer Table.
Defines one entry of the Variable Pointer Table.
#include <DVRunTime_types.h>
Data Fields
1.6.2.6.2 Field Documentation
address
uint8_t* address
size
uint8_t size
1.6.2.7 DVRT_VariableUpdate Struct Reference
Defines the data structure needed to update the Variable Pointer Table (DVPMT).
1.6.2.7.1 Detailed Description
Defines the data structure needed to update the Variable Pointer Table (DVPMT).
#include <DVRunTime_types.h>
Data Fields
uint8_t startOfFrame
uint8_t command
uint8_t variablePointerTableSize
uint8_t * variableAddress
uint8_t variableValue [5]
uint8_t endOfFrame
1.6.2.7.2 Field Documentation
command
uint8_t command
endOfFrame
uint8_t endOfFrame
startOfFrame
uint8_t startOfFrame
variableAddress
uint8_t* variableAddress
variablePointerTableSize
uint8_t variablePointerTableSize
variableValue
uint8_t variableValue[5]
1.6.2.8 flagS Struct Reference
1.6.2.8.1 Data Fields
1.6.2.8.2 Field Documentation
osr
unsigned osr
ping
unsigned ping
streamOn
unsigned streamOn
1.6.3 File Documentation
1.6.3.1 source/DVRunTime.c File Reference
This file contains the driver implementation for the dvruntime driver module.
#include "../../DVRT/DVRunTime.h" #include "../../uart/uart2.h"
1.6.3.1.1 Data structures
1.6.3.1.2 Functions
void DVRT_UART_RX_CallBack (void)
void DVRT_HandleCommand (void)
void DVRT_UART_WriteByte (uint8_t txData)
This blocking function writes a byte of data to the selected UART.
void DVRT_WritePacket (void)
void DVRT_Error_Callback (void)
void DVRT_Initialize (void)
Initializes the DVRT driver. Sets the variable values to their initial values and registers error callback functions for UART errors.
void DVRT_Process (void)
Processes the DVRT driver. Checks the UART for incoming data and processes the data if it is available. It also checks for time-out conditions and triggers the periodic sending of data, if required. Finally, it executes one-shot readings and ping commands.
1.6.3.1.3 Variables
const uart_drv_interface_t * UART_DV = &UART3
static const struct TIMER_INTERFACE * TIMER_DVRT = &Timer0
static DVRT_error_t error
const DVRT_interface_t DVRT
Declaration of the DVRT interface and its function pointers.
static DVRT_VariablePointerTableEntry_t DVPMT [DYNAMIC_VAR_PTR_COUNT]
static volatile union DVCmds DVRT_ReceivedCmd
static const volatile uint16_t dvIdFw = DV_FW_CODE
static volatile uint8_t rxBufPtr
static volatile uint8_t DVFrameCounter
static uint16_t DVStreamInterval
static uint16_t DVStreamInterval_Counter
static uint16_t DVCmdInterval
static uint16_t DVCmdInterval_Counter
static size_t USART_Error
1.6.3.1.4 Detailed Description
This file contains the driver implementation for the dvruntime driver module.
dvruntime Generated Driver Source File
1.6.3.1.5 Function Documentation
DVRT_Error_Callback()
void DVRT_Error_Callback (void )
DVRT_HandleCommand()
void DVRT_HandleCommand (void )
DVRT_UART_RX_CallBack()
void DVRT_UART_RX_CallBack (void )
Section: Driver Interface
DVRT_WritePacket()
void DVRT_WritePacket (void )
1.6.3.1.6 Variable Documentation
DVCmdInterval
uint16_t DVCmdInterval
DVCmdInterval_Counter
uint16_t DVCmdInterval_Counter
DVflag
struct flagS DVflag[static]
DVFrameCounter
volatile uint8_t DVFrameCounter[static]
dvIdFw
const volatile uint16_t dvIdFw = DV_FW_CODE
DVPMT
DVRT_VariablePointerTableEntry_t DVPMT[DYNAMIC_VAR_PTR_COUNT]
Section: Variables
DVRT_ReceivedCmd
volatile union DVCmds DVRT_ReceivedCmd
DVStreamInterval
uint16_t DVStreamInterval
DVStreamInterval_Counter
uint16_t DVStreamInterval_Counter
error
DVRT_error_t error
rxBufPtr
volatile uint8_t rxBufPtr
TIMER_DVRT
const struct TIMER_INTERFACE* TIMER_DVRT = &Timer0[static]
UART_DV
const uart_drv_interface_t* UART_DV = &UART3
Section: Included Files Section: Macro Declarations
USART_Error
size_t USART_Error[static]
1.6.3.2 source/DVRunTime.h File Reference
#include <stdbool.h> #include <stdint.h> #include "DVRunTime_interface.h" #include "DVRunTime_types.h" #include "DVRunTime_config.h"
1.6.3.2.1 Functions
void DVRT_Initialize (void)
Initializes the DVRT driver. Sets the variable values to their initial values and registers error callback functions for UART errors.
void DVRT_Process (void)
Processes the DVRT driver. Checks the UART for incoming data and processes the data if it is available. It also checks for time-out conditions and triggers the periodic sending of data, if required. Finally, it executes one-shot readings and ping commands.
1.6.3.2.2 Macros
#define EXTERN extern
1.6.3.2.3 Variables
const DVRT_interface_t DVRT
Declaration of the DVRT interface and its function pointers.
1.6.3.2.4 Detailed Description
dvruntime Generated Driver Header File
1.6.3.2.5 Macro Definition Documentation
EXTERN
#define EXTERN extern
1.6.3.3 source/DVRunTime_config.h File Reference
This file contains the macros for the configuration of the dvruntime module.
1.6.3.3.1 Macros
#define DYNAMIC_VAR_PTR_COUNT 8U /* Number of Dynamic Variables Pointers in the Monitor Table */
#define DV_STREAM_TIME 20U /* Streaming time interval (time dependent on main loop tick) */
#define DV_RX_CMD_TIMEOUT 200U /* Command timeout: Timeout after number of times DVRT_process() is called */
#define DV_FW_CODE (uint16_t)261 /* Project Firmware Code */
#define DV_START_OF_FRAME 0x03U /* Start Frame Byte */
#define DV_END_OF_FRAME 0xFCU /* End Frame Byte */
#define DV_RX_CMD_MIN_SIZE 3U /* Minimun number of byte in a RX command */
1.6.3.3.2 Detailed Description
This file contains the macros for the configuration of the dvruntime module.
dvruntime Generated Configuration Header File
1.6.3.3.3 Macro Definition Documentation
DV_END_OF_FRAME
#define DV_END_OF_FRAME 0xFC /* End Frame Byte */
DV_FW_CODE
#define DV_FW_CODE (uint16_t)261 /* Project Firmware Code */
DV_RX_CMD_MIN_SIZE
#define DV_RX_CMD_MIN_SIZE 3 /* Minimun number of byte in a RX command */
DV_RX_CMD_TIMEOUT
#define DV_RX_CMD_TIMEOUT 200 /* Command timeout: Timeout after number of times DVRT_process() is called */
DV_START_OF_FRAME
#define DV_START_OF_FRAME 0x03 /* Start Frame Byte */
DV_STREAM_TIME
#define DV_STREAM_TIME 20 /* Streaming time interval (time dependent on main loop tick) */
DYNAMIC_VAR_PTR_COUNT
#define DYNAMIC_VAR_PTR_COUNT 8 /* Number of Dynamic Variables Pointers in the Monitor Table */
1.6.3.4 source/DVRunTime_interface.h File Reference
Contains the function pointers to the DV Run Time library component.
#include <stdbool.h> #include <stdint.h>
1.6.3.4.1 Data structures
struct DVRT_interface_t
Structure containing the function pointers to the DV Run Time driver APIs.
1.6.3.4.2 Detailed Description
Contains the function pointers to the DV Run Time library component.
dvruntime Generated Interface Header File
1.6.3.5 source/DVRunTime_types.h File Reference
This file contains the data types used for the operation of the dvruntime module.
#include <stdbool.h> #include <stdint.h> #include "../uart/usart3.h" #include "DVRunTime_config.h"
1.6.3.5.1 Data structures
struct DVRT_VariablePointerTableEntry
Defines one entry of the Variable Pointer Table.
struct DVRT_StreamUpdates
Defines the data structure for updating the stream of variables sent to the Data Visualizer.
struct DVRT_VariableUpdate
Defines the data structure needed to update the Variable Pointer Table (DVPMT).
struct DVRT_StreamIntervalUpdate
Defines the data structure for updating the streaming period of frames sent from the DVRT to the Data Visualizer.
struct DVRT_CommandTemplate
Typedef for struct containing the elements needed for a generic DVRT command.
1.6.3.5.2 Typedefs
typedef struct DVRT_VariablePointerTableEntry DVRT_VariablePointerTableEntry_t
typedef struct DVRT_StreamUpdates DVRT_StreamUpdates_t
typedef struct DVRT_VariableUpdate DVRT_VariableUpdate_t
typedef struct DVRT_StreamIntervalUpdate DVRT_StreamIntervalUpdate_t
typedef struct DVRT_CommandTemplate DVRT_CommandTemplate_t
typedef size_t DVRT_error_t
1.6.3.5.3 Enumerations
enum { UPDATE_VARIABLE_POINTER_TABLE = 0, UPDATE_VARIABLE_VALUE = 1, UPDATE_STREAMING_TICK = 2, TURN_STREAMING_OFF = 3, TURN_STREAMING_ON = 4, ONE_SHOT_READ = 5, PING = 6 }
1.6.3.5.4 Detailed Description
This file contains the data types used for the operation of the dvruntime module.
dvruntime Generated Types Header File
1.6.3.5.5 Typedef Documentation
DVRT_CommandTemplate_t
typedef struct DVRT_CommandTemplate DVRT_CommandTemplate_t
DVRT_error_t
typedef size_t DVRT_error_t
DVRT_StreamIntervalUpdate_t
typedef struct DVRT_StreamIntervalUpdate DVRT_StreamIntervalUpdate_t
DVRT_StreamUpdates_t
typedef struct DVRT_StreamUpdates DVRT_StreamUpdates_t
DVRT_VariablePointerTableEntry_t
typedef struct DVRT_VariablePointerTableEntry DVRT_VariablePointerTableEntry_t
DVRT_VariableUpdate_t
typedef struct DVRT_VariableUpdate DVRT_VariableUpdate_t
1.6.3.5.6 Enumeration Type Documentation
anonymous enum
anonymous enum
UPDATE_VARIABLE_POINTER_TABLE | |
UPDATE_VARIABLE_VALUE | |
UPDATE_STREAMING_TICK | |
TURN_STREAMING_OFF | |
TURN_STREAMING_ON | |
ONE_SHOT_READ | |
PING |
1.6.4 Module Documentation
1.6.4.1 DV Run Time Library Use Cases
1.6.4.1.1 DV Run Time Library Use Case Code Snippet Instructions
The use cases show example uses of the Data Visualizer Run Time feature, within an MCC Melody Project.
Add the following components and configure them as described in the specific example. Note: Fairly high system clock is required, but this can be lowered once done with the debugging/verification of application functionality with the DVRT.
-
Add DV Run Time.
-
Clock Control:
-
If DVRT does not work, try increasing system clock speed.
-
Note: For AVRDx set main clock to at least 8 MHz main clock (default clock frequncy of 4 MHz is too slow).
-
-
Pins:
-
Best practice: Enable (weak)pullup on UART Rx pin.
-
1.6.4.1.2 DVRT Hello World: LED Toggle and Count Variables (Timer)
-
Count_msTicksSinceToggle is incremented up to toggle_ms, when LED_ON is toggled
-
Add DV Run Time.
-
Add a second Timer (besides the DVRT dependency).
-
Dependency Selector
-
Select UART PLIB dependency: Check the schematic for the UART connected to the USB CDC UART (UART settings set by DVRT library).
-
Select Timer PLIB dependencies: Any timers can be chosen (leave in default configuration).
-
-
Software Settings:
-
Interrupt Driven: Yes (Timer default).
-
Requested Timer Period: 1 ms (Timer default).
-
-
Clock Control:
-
If DVRT does not work, try increasing system clock speed.
-
Note: For AVRDx set main clock to at least 8 MHz main clock (default clock frequncy of 4 MHz is too slow).
-
-
Pin Grid View:
-
Select a LED pin (check schematic), and configure it as Output.
-
-
Pins View:
-
LED pin: Custom name "IO_LED".
-
UART Rx pin: Enable(weak) pullup.
-
-
MCC Notifications:
-
Check if any notifications, e.g. UART baud rate error less than 1%.
-
After configuring the components as described above click Generate to generate the code. Then add the following code snippets to your application:
-
Add the following variables:
-
uint16_t Count_msTicksSinceToggle.
-
uint16_t LED_period_ms.
-
bool LED_ON.
-
/* Include for PIC16F/18F and AVR*/ #include "mcc_generated_files/system/system.h"
/* Includes for dsPIC and PIC24*/ #include "mcc_generated_files/system/system.h" #include "mcc_generated_files/system/pins.h" #include "mcc_generated_files/DVRT/DVRunTime.h" #include "mcc_generated_files/timer/sccp1.h" /* Replace with appropriate header from: .../timer/timerX.h */ #include "mcc_generated_files/timer/sccp2.h" /* Replace with appropriate header from: .../timer/timerX.h */ #include <stdbool.h>
static volatile bool LED_ON = false; static volatile uint16_t LED_period_ms = 250U; static volatile uint16_t Count_msTicksSinceToggle = 0U;
void Timer_Callback_1ms(void){ Count_msTicksSinceToggle++; if(Count_msTicksSinceToggle >= LED_period_ms){ LED_ON = !LED_ON; // Toggle LED state variable IO_LED_Toggle(); Count_msTicksSinceToggle = 0U; } }
int main(void) { SYSTEM_Initialize(); INTERRUPT_GlobalInterruptEnable(); /* For PIC18F */ /* Comment out for AVR: Enable Global IRQ in Interrupt Manager */ /* Comment out for dsPIC, Global IRQs are enabled by default */ /* Replace X with number of 2nd timer added */ /* From name of const struct TIMER_INTERFACE, path: mcc_generated_files\timer\src\timerX.c */ TimerX.TimeoutCallbackRegister(Timer_Callback_1ms); while(1) { } }