Hi friends…………….my first step in the field of microcontrollers is blinking an LED using PIC microcontroller and MikroC. I used PIC 16F877A for that. It is the one of the most popular PIC microcontroller and comes in a 40 pin DIP pinout. I use MikroC Pro for PIC as the C compiler because it has a lot of built in functions which makes our task very simpler.
Using MikroC
You can buy mikroC form mikroElectronika or download a trial version form here. Trial Version is sufficient for most of our needs.
1. Download and Install mikroC.
2. Open microC Pro For PIC
3. Click on Project>> New Project 4. Click NEXT 5. Select PIC16F877A and Click NEXT 6. Set Device Clock as 8Mhz and Click NEXT 7. Set path of your project folder. It is better to create a new folder for each project. Click NEXT 8. In this step you can add your on header files etc… if you want to use them in this project, otherwise leave it. Click NEXT 9. It is better to select ‘Include All’ for beginners. Click NEXT 10. Thus you have successfully completed New Project Wizard in mikroC
Circuit Diagram and MikroC Programming
mikroC Source Code:
Code: Select all
void main()
{
TRISB.F0 = 0 // set direction of RBO to output
//or TRISB = 0xFE (0xFE = 11111110)
/* 0 at a bit of TRIS register makes corresponding
pin output while 2 makes it input*/
do // To set infinite loop
{
PORTB.F0 = 1; // Set RB0 to high
Delay_ms(500); // 500 mili seconds delay
PORTB.F0 = 0; // Set RB0 to low
Delay_ms(500); // 500 mili seconds delay
}while(1); // To set infinite loop
}
12. Save it
13. Then Compile it. Click Build>>Build (or Ctrl+F9)
The hex file will be generated in you Project Folder.
Circuit Diagram:
Note: VDD and VSS of the pic microcontroller is not shown in the circuit diagram. VDD should be connected to +5V and VSS to GND.
PIC 16F877A has no internal oscillator, so we should connect external oscillator. Two 22pF capacitors are used to stabilize the operation of the Crystal Oscillator. A low on MCLR pin will reset the PIC, so we tie it to VDD to avoid accidental RESET.
Simulating in Proteus
The project can be simulated in your PC by using the software Proteus. You can buy Proteus from Labcenter Electronics.
1. Download and Install Proteus
2. Open Proteus, named as ISIS Professional
3. Click P (Pick from Libraries) in the Devices column on the Left side of the IDE
4. From here you can add the devices that you uses in the project. You can easily find out the devices using the keyword search on the top left side. Add all the devices 16F877A, Crystal, 22pF, Battery, LED, resistor. 5. Select components from the Devices List and place it on the Root Sheet, then you can easily wire them using your mouse. You can edit the properties of each devices by double clicking on it. Note: VDD and VSS pins of PIC are hidden, so for the proper working we should define VDD and VSS as shown above by placing wire label (you can place this by right clicking on a wire).
6. Then give the path of hex file to the PIC, by double clicking on it.
7. Click on the play button on the bottom left side of the IDE to simulate the circuit. Here is a video tutorial too..
[media]http://www.youtube.com/watch?v=h5FlUZdQo-M[/media]
Article courtesy of electrosome.com