5.6 main.c Modified Code
The main.c
template file has been edited as shown below. Some comments have been
removed.
#include "mcc_generated_files/mcc.h"
#define NUM_EE_VALUES 64
#define INSTR_CYCLE_DELAY 5000
/*
Main application
*/
void main(void)
{
// Initialize the device
SYSTEM_Initialize();
// If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
// If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
// Use the following macros to:
// Enable the Global Interrupts
//INTERRUPT_GlobalInterruptEnable();
// Disable the Global Interrupts
//INTERRUPT_GlobalInterruptDisable();
// Enable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptEnable();
// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();
// Declare RAM array, loop variable (see 5.6.1 EEData Associated Variables)
volatile uint8_t RAMArray[NUM_EE_VALUES];
uint8_t i;
// Write initial values to EEPROM Data (see 5.6.2 Write to EEData)
for(i=0; i<NUM_EE_VALUES; i++){
DATAEE_WriteByte(0x10 + i, i);
}
while (1)
{
// Read from EEPROM and display (see 5.6.3 Read from EEData)
for(i=0; i<NUM_EE_VALUES; i++){
RAMArray[i] = DATAEE_ReadByte(0x10 + i);
LATA = (RAMArray[i] << 1); // RA[4:7] = LED[2:5]
_delay(INSTR_CYCLE_DELAY); // delay value change
}
// Write to EEPROM in reverse order
for(i=0; i<NUM_EE_VALUES; i++){
DATAEE_WriteByte(0x10 + (NUM_EE_VALUES - 1) - i, RAMArray[i]);
}
}
}
/**
End of File
*/