Hi,
If you are a beginner , it is perfect to start with blinking led .This is a very simple project and we need 7 LED and PIC 18F2550 microcontroller .In this project we will use MikroC compiler to code.
If you are a beginner , it is perfect to start with blinking led .This is a very simple project and we need 7 LED and PIC 18F2550 microcontroller .In this project we will use MikroC compiler to code.
Now we are going to Create this project >>
Proteus Project :
Proteus Project :
*Open Proteus and Create new project
You will see as below :
After finishing those step ,You need to follow as below:
Pick all parts from library :
In this way , pick from Library "PIC 18F2550", "crystal" , " 22pf capacitor" , "green LED" ,"Power" and "Ground" .
[ Note :If you are absolutely a new with PIC 18f2550 microcontroller , you need to see Introduction with PIC 18f2550 to understand all ports and pin]
![]() |
Create Blinking LED Project Using PIC Microcontroller [ PIC18F2550 ] [step by step ] |
Now we need the main hex file to operate .Here you need to take a look on here , we selected RB0-RB7 pins and made connection with GND port of each LED .So if portB is 1 , those LED will be on .
MikroC Code :
Open MikroC and Create a new Project :
Now Write the source code given below :
Source Code
//////////////////////////////////////////////////////////////////////
void main(){
TRISB=0x00;
while(1){
PORTB=0x01;
delay_ms(400);
PORTB=0x02;
delay_ms(400);
PORTB=0x04;
delay_ms(400);
PORTB=0x08;
delay_ms(400);
PORTB=0x10;
delay_ms(400);
PORTB=0x20;
delay_ms(400);
PORTB=0x40;
delay_ms(400);
PORTB=0x80;
delay_ms(400);
} }
////////////////////////////////////////////////////////////////////
TRISB is used for selecting PORTB as Input or Output . Here 1 for input and 0 for Output .
If we write TRISB=0xFF; and 0xFF will be in binary "11111111" .By applying this we get portb for input .
If we write TRISB=0x00; and 0xFF will be in binary "00000000" .By applying this we get portb for output. [if you don't understand pinout of PIC 18f2550 please follow the link]
We used delay_ms(400) function .That means microcontroller stop for 400ms .
0x01 is hexadecimal number and in binary "00000001" .Means first pin or RB0 pin of PORTB will be 1 .In this condition 1 means this pin gets +5v[VDD] and 0 means ground(GND) .It is said computer understand 0 and 1 .But it is just an electronic device which calculate something according to instruction.
So,
0x00 <--------------> "all zero" <--------------> RB0,RB1,RB2,RB3,RB4,RB5,RB6,RB7 remain OFF
0x01 <--------------> "00000001" <--------------> Only RB0 is +5v & allothers remain GND
0x02 <--------------> "00000010" <--------------> Only RB1 is +5v & all others remain GND
0x04 <--------------> "00000100" <--------------> Only RB2 is +5v &all others remain GND
0x08 <--------------> "00001000" <--------------> Only RB3 is +5v &all others remain GND
0x10 <--------------> "00010000" <--------------> Only RB4 is +5v &all others remain GND
0x20 <--------------> "00100000" <--------------> Only RB5 is +5v &all others remain GND
0x40 <--------------> "01000000" <--------------> Only RB2 is +5v &all others remain GND
0x80 <--------------> "10000000" <--------------> Only RB2 is +5v &all others remain GND
Why TRISB ?
Listen , A microcontroller can be used for many purposes and the specific purpose we need can be defined by the source code . Basically in blinking led , each led will be on or off in one after one way .That means each pin of PORTB will be on or off .For this purpose we need to initialize PORTB as output.
So we have to use TRISB to define PORTB as Input or Output .
When TRISB=0x00; all pins for OUTPUT.
When TRISB=0xFF; all pins for INPUT.
If in case PORTA , we will have to use TRISA .
Small correction: "If we write TRISB=0x00; and 0xFF will be in binary "00000000" .By applying this we get portb for output."
ReplyDeleteIt should be " RISB=0x00; and 0x00 will be in binary "00000000".
Thank you very much!
DeleteCurrently a single Bitcoin (shown as 1.0000000) is worth £573 or $935. You can purchase Bitcoins at any of the 8 decimal places so for example 0.0100000 would cost you £5.70 and 0.1000000 would cost you £57.00, no surprise where Bitcoin got its name! fake bitcoin sender
ReplyDelete