In this tutorial, you will learn how to program a PIC Microcontroller compiler software called MikroC. This is a simple and user-friendly software designed to convert the C-language code into a hex file, which can then be fed to the microcontroller to perform specific tasks. After completing this tutorial, you will be able to generate the hex code of a program in the C language using any PIC Microcontroller and simulate it.
The hex code is loaded into the flash memory of the microcontroller in the form of zeros and ones, interpreted by the CPU as commands that are executed. To understand how the hex file is generated, let us take the example of a simple program to set all eight port pins of PORTC to logic 1.
If you have not used MikroC for Pic before, you can follow this tutorial:
Compiler Code with MikroC for PicOpen the mikroC PRO software by double-clicking the icon on your desktop. From the menu on the top, select Project à New Project.
Mikro c tutorialA New Project Wizard window will appear. Click “Next” to reach the “Project Settings” window. Specify a unique name for the project, select the device name as PIC16F877A, and browse the project folder where the hex file will be saved. Choose the device clock according to the one used in the design, and then press “Next.”
Mikro c tutorialStep 2 allows you to add a file to the project, while Step 3 allows you to include all or select libraries. Press Next without making any changes on both windows and then press Finish to end the wizard. The Code Editor Window will be displayed with “void main()” written on the first line. This is where you have to write your program. Write the code and press BUILD on the horizontal toolbar at the top.
Mikro c tutorialHere we have a two-liner code where all pins of Port C are set to high.
On successful completion of the Building process, a message would appear in the ‘Message’ window at the bottom of the screen, indicating that the code has been compiled without any errors and the hex file is ready.
Mikro c for pic tutorial Upload and Debug CodeThe above-mentioned program is then simulated to ensure its proper functioning. To carry out the simulation, the required steps are as follows:
The Debugger feature goes through all instructions one at a time and reflects the step-by-step changes caused to the port pins, registers, etc. The variables that you want to display can be selected from the ‘Watch Value’ window on the right side of the screen.
Select the variable PORTC by clicking on “Select Variable from list” and then click on the Add button to add it to the watchlist.
MikroC for picPress F8 to move the blue line onto the next instruction, the blue line highlights the instruction that will be executed next. The point to note in the ‘Watch Value’ window is that the value of PORTC is still zero since the third instruction has not been executed yet.
Press F8 again, and now the value of PORTC has been changed to 255 i.e. all highs
Mikro c for pic tutorialIf you want to upload code to a Pic microcontroller, you can follow this guide:
ConclusionIn summary, follow these step to flash code to a PIC microcontroller using the MikroC for PIC compiler, follow these steps:
Remember to double-check the specific microcontroller model and connections to ensure compatibility and successful flashing of the code.
Related content:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4