|
Toggle_LED using Microchip MCC Melody |
1. Specifications | Planning | Dev. & test | Prototype | Report |
The circuit will switch ON and OFF a lamp clicking a push-button. The edge event will be detected and handled by an external interrupt.
|
Fig 1. Toggle_LED symbol and waveforms. The button click is detected and the output toggles to indicated this detection. |
Specifications | 2. Planning | Dev. & test | Prototype | Report |
The main focus of this project is placed on how to develop it using the MPLAB Code Configurator Melody tool. The objective is to abstract all the microcontroller resources: External oscillator, reset button, external interrupt, digital output pins. In this fashion, the user will be only in charge of the main program and the particular interrupt service routine.
![]() |
Fig 2. Two pins will be used as outputs. One interrupt input will connect the push-button. |
As usual, we will capture our circuit in Proteus to be able to debug immediately once the software compiled. The circuit is the CSD_PICstick.
Fig 3. Software loop that is interrupted any time by the push-button event. |
Specifications | Planning | 3. Dev. & 4. test | Prototype | Report |
We will capture the circuit "Toggle_LED.pdsprj" in Proteus as usual, ready for simulation and debugging once the software compiled as a COFF.
|
Fig 4. Capturing the circuit in Proteus using some components of the CSD_PICstick board model. |
MCC is used to configure all the resources from a graphical environment and generate the file structure automatically.
![]() |
Fig 5. MCC configuration environment to generate all the peripheral and system files. NOTE: Exclude the automatically generated main() template file from your project before compiling. |
We will keep our "Toggle_LED.c" main file separated form the MCC automations and updates. As shown in Fig. 4, a pointer will indicate to the MPLABX IDE where to find the push-button interrupt service function. We will place it in the same main file. The idea is to set up our software flag once the active INT0 edge is detected.
|
Fig 6. Pointer to the service routine for the INT0 external interrupt. |
Files and zip project Toggle_LED.zip.
Simulation using Proteus.
|
Fig 7. Example simulation watching RAM variables. |
Specifications | Planning | Dev. & Test | 5. Prototype | Report |
Finally we can visualise how our circuit works programming with the MPLAB SNAP the PCI18F46K22 chip. Change the output file format to ELF as shown in Fig. 8.
|
Fig 8. Changing the output file format to program the PCI18F46K22. |
Program the chip and experiment.
|
Fig 9. CSD_PICstick prototype running the application Toggle_LED. |
Therefore, we can successfully completed our first applications using MCC Melody to configure all the microcontroller resources, as an alternative to bare-metal programming as it was used in our introductory subject CSD.
Specifications | Planning | Dev. & Test | Prototype | 6. Report |