Professional Documents
Culture Documents
PIN 1: MCLR:The first pin is the master clear pin of this IC. It resets the
microcontroller and is active low, meaning that it should constantly be
given a voltage of 5V and if 0 V are given then the controller is reset.
Resetting the controller will bring it back to the first line of the program that
has been burned into the IC.
A push button and a resistor is connected to the pin. The pin is already
being supplied by constant 5V. When we want to reset the IC we just have
to push the button which will bring the MCLR pin to 0 potential thereby
resetting the controller.
PIN 2: RA0/AN0:PORTA consists of 6 pins, from pin 2 to pin 7, all of these
are bidirectional input/output pins. Pin 2 is the first pin of this port. This pin
can also be used as an analog pin AN0. It is built in analog to digital
converter.
PIN 3: RA1/AN1:This can be the analog input 1.
PIN 4: RA2/AN2/Vref- :It can also act as the analog input2. Or negative
analog reference voltage can be given to it.
PIN 5: RA3/AN3/Vref+:It can act as the analog input 3. Or can act as the
analog positive reference voltage.
PIN 6: RA0/T0CKI:To timer0 this pin can act as the clock input pin, the
type of output is open drain.
PIN 7: RA5/SS/AN4:This can be the analog input 4. There is synchronous
serial port in the controller also and this pin can be used as the slave
select for that port.
PIN 8: RE0/RD/AN5: PORTE starts from pin 8 to pin 10 and this is also a
bidirectional input output port. It can be the analog input 5 or for parallel
slave port it can act as a ‘read control’ pin which will be active low.
PIN 9: RE1/WR/AN6: It can be the analog input 6. And for the parallel slave
port it can act as the ‘write control’ which will be active low.
PIN 10: RE2/CS/A7: It can be the analog input 7, or for the parallel slave port
it can act as the ‘control select’ which will also be active low just like read
and write control pins.
PIN 11 and 32: VDD: These two pins are the positive supply for the
input/output and logic pins. Both of them should be connected to 5V.
PIN 12 and 31: VSS: These pins are the ground reference for input/output
and logic pins. They should be connected to 0 potential.
PIN 13: OSC1/CLKIN: This is the oscillator input or the external clock input
pin.
PIN 14: OSC2/CLKOUT: This is the oscillator output pin. A crystal resonator is
connected between pin 13 and 14 to provide external clock to the
microcontroller. ¼ of the frequency of OSC1 is outputted by OSC2 in case
of RC mode. This indicates the instruction cycle rate.
{
{
}while(1);
}
This code is used to toggle PORTC pin number zero with the delay of five
hundred mili seconds. Inside the main function this line initialize the RB0 as
digital output pin.
TRISB.F0 = 0
After that do while loop is used, because we want to toggle LED again and again.
Inside the do while loop, these line make the RB0 digital high for 500ms.
PORTB.F0 = 1; // setting the RB0 pin to high
Delay_ms(500); // delay of 500 milli seconds
And similarly these lines, turn off the LED for 500ms.
PORTB.F0 = 0; // setting the RB0 pin to low
Delay_ms(500); // again a delay of 500 milli seconds
Circuit Diagram For Flashing LED WITH
PIC16F877A
Design this circuit in proteus. Connect the pins with the source, ground and
oscillator as explained in the pin description section.
Connect 8MHz oscillator with OSCI and OSC2 through two 22 pico farad
capacitors.
Provide 5 volt to Reset pin through 10k ohm resistor. Resistor is not shown
in simulation, but you should connect resistor while making circuit
practically.
An LED is connected on pin 33 RB0, a resistor is used to limit the current
and to prevent the LED from burning up. Write and compile the program in
mikro C pro.
Burn the microcontroller with the hex file by double clicking on the
controller in proteus and run the circuit successfully. best way to learn any
microcontroller is to check its data sheet.
Pic kit3 is a famous programmer used to upload code to microchip
chips, How to program using Pic kit3 is a good source to read.
you may also like to read tutorials on PIC16F877A microcontroller
LED blinking with pic16f877a microcontroller
LCD interfacing with pic16f877a microcontroller
keypad interfacing with pic16f877a microcontroller
serial communication using pic16f877a microcontroller
timers of pic16f877a microcontroller
interrupts
stepper motor interfacing
servo motor interfacing with pic16f877a
dc motor interfacing with pic16f877a
Complete list of pic microcontroller tutorials
SERVO MOTOR interfacing with PIC16F877A MICROCONTROLLER
It has a very simple circuit diagram. The control wire of the servo motor is directly
connected to the RB0 pin of the microcontroller. This pin will provide the required
angular displacement of the motor. In this project, suppose we are working with a
servo motor whose angular rotation is limited to 0° – 180°.We can control the
rotation of the motor within this limit with utmost precision by using a pulse whose
width is varied to attain the desired angle.
A pulse is fed to the servo motor after every 20ms (or 20,000us). The angular
position of the motor is determined by the length of this pulse. The angular
positions 0°, 90° and 180° are demonstrated in the code.
C-CODE FOR SERVO MOTOR INTERFACING WITH PIC MCU
Write the following code of servo motor interfaced with PIC in mikroC Compiler.
Void Rotation0() //0 Degree
{
unsigned int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
Delay_us(800); // pulse of 800us
PORTB.F0 = 0;
Delay_us(19200);
}
}
void Rotation90() //90 Degree
{
unsigned int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
Delay_us(1500); // pulse of 1500us
PORTB.F0 = 0;
Delay_us(18500);
}
}
void Rotation180() //180 Degree
{
unsigned int i;
for(i=0;i<50;i++)
{
PORTB.F0 = 1;
Delay_us(2200); // pulse of 2200us
PORTB.F0 = 0;
Delay_us(17800);
}
}
void main()
{
TRISB = 0; // PORTB as Ouput Port
do
{
Rotation0(); //0 Degree
Delay_ms(2000);
Rotation90(); //90 Degree
Delay_ms(2000);
Rotation180(); //180 Degree
}while(1);
}
Individual functions for angular rotation of the motor by 0°, 90° and 180° have
been declared in the beginning of the code.In this tutorial, we have not used the
actual Pulse Width Modulation feature of PIC16F877A to generate a
pulse.Instead, the pulse has been created with the help of delays in the program.
The delay duration for a particular angle is equivalent to the length of the pulse
required for the motor to rotate up to thatcorresponding angle. That is, for 0°
angle, the pulse width is approx. 800ms, so a delay of 800ms is introduced with
the PORT pin RB0 set to high. Similarly,a pulse of 1500ms is required for a
rotation up to 90° and 2200ms for a180° angle.
In the main program, PORTB is set as an output port and all the three functions
are called, separated by a delay of 2000ms between them. The program causes
the motor to rotate in a pattern; 0° – 90° – 180° – 0° and so on. This continues in
an infinite ‘do-while’ loop, until the program is aborted.
APPLICATION
Servo motor has a large number of application in industries. In industrial
manufacturing, the conveyor belt uses servo motors to control the precise
movement of the belt. Servo motors are most popular in robotics. The precise
angular displacement of a robot’s arm is controlled by a servo motor. The
physicalmovement of the solar panel with respect to the sun is also carried out by
servo motors in a solar tracking system.