UPC EETAC Bachelor's Degree in Telecommunications Systems and in Network Engineering EEL

 

Toggle_LED using Microchip MCC Melody

MCC 


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.

Symbol

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

A) Planning hardware

 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.

Hardware and software

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.

 


B) Planning software

 

Software

Fig 3. Software loop that is interrupted any time by the push-button event.

 


Specifications Planning 3. Dev. & 4. test Prototype Report

A) Developing hardware

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.


B) Developing software

MCC is used to configure all the resources from a graphical environment and generate the file structure automatically.

MCC coonfiguration files

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.

Pointer to the interrupt service routine

Fig 6. Pointer to the service routine for the INT0 external interrupt.

Files and zip project Toggle_LED.zip.

 


C) Step-by-step testing

Simulation using Proteus.

Simulation watching RAM variables

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.

Programming options

Fig 8. Changing the output file format to program the PCI18F46K22.  

Program the chip and experiment.

Prototype running

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