Tip:
Highlight text to annotate it
X
Hi guys! Mouad's here and welcome
to this new tutorial on how to program
the PIC microcontrollers. We'll use for this tutorial the MikroC for PIC
and the Software Proteus
Isis professional to simulate our project
today we will use the PIC16F84A
to blink a LED which is connected to
to a pin of this microcontroller, in our tutorial
it will be the RB1
which is connected to our LED via
a resistor
so let's start by making our program
go to project, new project, next
give a name to your project
choose the directory
choose the PIC16F84A
choose the Clock
device clock 4 Mhz
next,next and finish
in MikroC environment will give you directly
the void main function
which is
the function of the main program
and you will find it in every. it must be
in every program you develop
in mikroC there are two instructions
you have to know by heart. the first one is the TRIS
and the second one is PORT
in the first one you
will add for example
TRISB which means to configure
the portB as an input or an output
and if we want to use portA
you will make TRISA
in our project we have the LED connected
to the B port
we will make TRISB=
so in MikroC if you want to configure to your
pins as an output
you have to set TRISB register to zero
if not, you want to make it as an input
you have to give it the value 1
so let's give it value
zero
give it type "b" for binary
and I will type
00000000
why 8 numbers
so if you see here
you will find that the B-port
have 8-pins
RB0 to RB7
which means it has 8 bits
8 pins
our LED is connected to RB1
here, and we want
to make it as an output
we've made a mistake here
it should be the opposite
so, the Zero means
as I've told you
that 0 means that our pin will be
an output and the other will be as an input
here is the RB0
RB1,... RB7
the second one is
the PORTB
instruction, in our tutorial
we will use the PORTB, if you give
the PORTB for example
will give it
in our
simulation you can see that
the LED is connected to portB1
so if I want you change the status
of the LED I should use
PORTB.F1
why F1? F1 means
that I will affect the value
of the first pin here, and not pin0 or other pins
and I give it for example the value 1
this means that our LED will be ON
if I make PORTB.F1=0
that mean that our LED will be OFF
so in order to make will LED blinking
I will need to
to add a while(1)
which means that our program will be
executed infinitely
so you can see that our LED
will at first be ON the OFF
but our program is executed
fastly so I will not see the changes
of the LED status
I will have to add a delay
I will use
the instruction delay
milliseconds
for example 500ms
so our LED will be ON then Delay
and OFF
and I should add a delay here
500ms
as I told you, our program will be executed
in infitive time
our LED will be ON, Delay, OFF, Delay
here is our program
you have finished your first program
last step is to build our project, to compile it
so in order to do that click here
and you can see that your project is
built successfully and
you can find a different information about the used RAM and ROM
free RAM and free ROM
so now let's simulate our project by going to
ISIS professional , double thick
on your microcontroller
let's set our clock to 4Mhz
LEDBlinking
you have to choose the HEX file
okay click on Play
here is the LED blinking
and it will do that in an infinitely
so I hope it was useful for you
if you like it subscribe to our channel:
there will be more videos in the future
good luck and bye!