What you will learn ?
- MPLab as a powerful IDE.
- HI-TECH C for PIC18 MCUs as a powerful C Compiler.
- Creating a new HI-TECH C project in MPLab.
- Write a C Code to blink LED and compile it to get a HEX code.
- Configure the MCU for proper oscillator selection.
- Burn the HEX code to MCU using eXtreme Burner PIC from eXtreme Electronics.
- Use the programmed MCU to actually blink the LED !
First get these stuffs
- Microchip's MPLab IDE or Integrated development Environment. This is the central tool from where you can access most of other tools, like the C Compiler. This also lets you create and edit program files and projects. Download this from Microchips Web site and Install it in your computer.
- HI-TECH C Pro for PIC18 MCUs - This is will compile the high level human readable programs (in C Language) to Machine Language Instructions (contained in a HEX file). You will not interact directly with this software instead the MPLAB will use it internally. Actually this is a commercial software but a fully functional demo is available. The demo has only restriction that codes are not highly optimized. Not a problem for startup hobbyist!
- eXtreme Burner PIC - This hardware + software tool is used for burning(uploading) the HEX file to the microcontroller chip. This is a USB Based programmer with GUI interface so it is very easy to install and use.
- If you have made a Simple Serial Port Based PIC Programmer as discussed here then you need this nice program from Mr Christian Stadler. This is similar to eXtreme Burner PIC but serial port based and the hardware can be made easily.
Creating your first project with MPLAB + HI-TECH C.
After installing the above tools open MPLAB IDE from desktop Icon or Start Menu. You will get a main screen similar to this.
Fig.: Microchip MPLAB IDE Main Screen. |
From the Project Menu Select Project Wizard.
The Project Wizard will come up that will help you easily create a C Project. Click Next.
On the next screen select the Microcontroller you want to use. in our case select "PIC18F4550" and Click Next.
Fig.: Microchip MPLAB IDE - Processor Selection. |
After that select what tool suit you want to use this project. There are many C Compilers for PIC18 (from different vendors) and also many people use assembly language, so this step is required.
As we will be working will HI-TECH C, select that from the list. Do not touch any other fields in this dialog. Just select Active Tool Suit = HI-TECH Universal ToolSuit. as shown in image below.
Fig.: Microchip MPLAB IDE - ToolSuit Selection. |
Now Select select a suitable folder for your new project. I recommend create a Folder Named MPLAB (To save all MPLAB project in one place) and then create subdirectories in this folder for each new project. Like use C:\Your Name\MPLAB\LED\ for this led blinky demo. Now show the project wizard the path to this folder so it can create a project file here. See the next image.
Fig.: Microchip MPLAB IDE - Project Location. |
The next screen asks to add existing files to project. This is useful when you have some ready made and tested code that you can add to this project. Like if you have got a tested LCD interfacing library (which you have got from Net or made yourself) then you can add that now. But since this a simple "hello world" project you can skip this step. So click Next
Fig.: Microchip MPLAB IDE - Adding existing files. |
Fig.: Microchip MPLAB IDE - Project Summary. |
Make Sure that Add File To Project is checked. As shown below.
Fig.: Microchip MPLAB IDE - Saving a C File. |
#include <htc.h>
__CONFIG(1,0x0F24);
__CONFIG(2,0X0000);
void Wait()
{
unsigned char i;
for(i=0;i<100;i++)
_delay(60000);
}
void main()
{
//Initialize PORTD
//PD0 as Output
TRISD=0b11111110;
//Now loop forever blinking the LED.
while(1)
{
LATD=0B00000001; //PORTD0 = HIGH
Wait();
LATD=0B00000000; //PORTD0 = LOW
Wait();
}
}
And don't scratch your head now if you don't get the code, just copy paste, everything will be explained in latter tutorials. So don't forget to register for updates (see Feedburner Sidebar). Now time to convert that source code to machine code. So Select Rebuild form Project Menu.
Fig.: Microchip MPLAB IDE - Rebuild from Project Menu. |
Fig.: HEX file Ready to burn to PIC MCU ! |
Niciun comentariu:
Trimiteți un comentariu