Académique Documents
Professionnel Documents
Culture Documents
Date:19.3.2015
LED INTERFACING
AIM:
To design and set up a circuit to interface an LED with PIC 16F877A
SOFTWARE USED:
MPLAB_IDE_8_40
COMPONENTS REQUIRED:
Microcontroller: PIC16F877A
led
ALGORITHM
1. Start
2. Set PORT B as output port
b. End
4. Stop
THEORY
An LED is connected to RB0 pin of Port B. This pin has built-in internal pull-up which
can source a current of up to 25mA. The circuit diagram is shown as follows
PORTB is an 8-bit wide, bi-directional port. The corresponding data direction register
is TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input (i.e., put
the corresponding output driver in a Hi-Impedance mode). Clearing a TRISB bit (= 0) will make
the corresponding PORTB pin an output (i.e., put the contents of the output latch on the selected
pin). TRISB register belongs to register bank1 and PORTB belongs to bank 0
PROGRAM IN ASSEMBLY
PROGRAM IN C
#include<pic.h>
void delay(long g)
{
int i,j;
for(i=0;i<=g;i++)
{
for(j=0;j<255;j++);
}
}
// main progam
void main()
{
TRISB=0x00;
while(1)
{
PORTB=0XF0;
delay(300);
PORTB=~PORTB;
delay(300);
}
PROGRAM WINDOW
IN ASSEMBLY
IN C
INTERFACING DIAGRAM
RESULT
LED was interfaced successfully to PIC16F877A.
Expt No: 7 b
Date:21.3.2015
AIM:
To design and setup a circuit to interface PIC microcontroller with 7 segment display.
SOFTWARE USED:
MPLAB_IDE_8_40
COMPONENTS REQUIRED
Microcontroller: PIC16F877A
7 segment display [common anode]
ALGORITHM
1. Start
2. Assign {0X03,0X9F,0X25,0X0D,0X99,0X49,0XC1,0X1F,0X01,0X19}to character array a[]
3. Set PORT B as output port
4. Begin Infinite loop
a. Begin
i. for value of K upto 10
1. Begin
a. Assign a[k] to PORT B
b. Call delay
2. End
b. END
5. Stop
THEORY
The segments in a 7-segment display are arranged to form a single digit from 0 to F. We
can display a multi-digit number by connecting additional displays. Even though LCD displays
are more comfortable to work with, 7-segment displays are still standard in the industry. This is
due to their temperature robustness and visibility.
Segments are marked with non-capital letters: a, b, c, d, e, f, g and dp , where dp is the decimal
point. The 8 LEDs inside each display can be arranged with a common cathode or common
anode. With a common cathode display, the common cathode must be connected to the 0V rail
and the LEDs are turned on with a logic one. Common anode displays must have the common
anode connected to the +5V rail. The segments are turned on with a logic zero. 7-segment
displays come in different colors, including: red, orange, and green.
1 Interfacing :
1- Use a display driver such as the 7447 IC which convert the BCD number to it's seven segment
code with the PIC (number of pins used is 4).
2- Alternatively displays can be driven by a micro-controller (number of pins used is 7 plus the
decimal point).
3- Use 7447 with a decade counter (counter counts from 0 to 9) with the microcontroller (uses
one pin but is not so fast)
DESIGN
PROGRAM
#include<pic.h>
void delay(long g)
{
int i,j;
for(i=0;i<=g;i++)
{
for(j=0;j<255;j++);
}
}
void main()
{
int i,a[10]={0x03,0x9F,0x25,0x0D,0x99,0x49,0xC1,0x1F,0x01,0x19};
TRISB=0x00;
TRISA=0x00;
PORTA=0xFF;
while(1)
{
for(i=0;i<=9;i++)
{
PORTB=a[i];
delay(100);
}
}
}
PROGRAM WINDOW
INTERFACING DIAGRAM
RESULT
7 Segment display was interfaced successfully to PIC16F877A.
Expt No: 7c
Date:21.3.2015
AIM:
To design and setup a circuit to interface PIC microcontroller with 16*2 LCD display.
SOFTWARE USED:
MPLAB_IDE_8_40
COMPONENTS REQUIRED
Microcontroller: PIC16F877A
ALGORITHM
1. Start
7. Assign string value to the function print _lcd () and .Send each character of string to data
register
8 . Stop
THEORY
Liquid Crystal Display (LCD) is very commonly used electronic display module and having a
wide range of applications such as calculators, laptops, mobile phones etc. 162 character lcd
display is very basic module which is commonly used in electronics devices and projects. It can
display 2 lines of 16 characters. Each character is displayed using 57 or 510 pixel matrix.
PROGRAM
// LCD interfacing
#include <pic.h>
int lcd_i,lcd_j;
for(lcd_i=0;lcd_i<=lcd_g;lcd_i++)
for(lcd_j=0;lcd_j<250;lcd_j++) ;
delay(1);
RE2=0;
PORTD=lcd_c;
delay(1);
RE2=0;
}
}
void lcd_initiltn()
TRISE1=0;
TRISE2=0;
delay(15);
lcd_cmd(0x30); //initialize
delay(5);
lcd_cmd(0x30);
delay(1);
lcd_cmd(0x30);
delay(1);
lcd_cmd(0x01); //clear
lcd_cmd(0x80);
void main()
lcd_initiltn();
while(1);
}
PROGRAM WINDOW
INTERFACING DIAGRAM
RESULT
LCD display was successfully to PIC16F877A
Expt No: 7d
Date:26.3.2015
DC MOTOR INTERFACING
AIM
SOFTWARE USED:
MPLAB_IDE_8_40
COMPONENTS REQUIRED
Microcontroller: PIC16F877A
ALGORITHM
1. Start
2. Set Port B as output port and port D as input port
3. Begin infinite loop
a. check if RD0=0 & RD1=0
ON ON CLOCKWISE
ON OFF STOP
OFF ON STOP
}
PROGRAM WINDOW
INTERFACING DIAGRAM
RESULT
DC motor was interfaced successfully to PIC16F877A
Expt No: 8
Date:26.3.2015
AIM:
To design and setup a circuit to turn ON and turn OFF an LED with External interrupt.
SOFTWARE USED:
MPLAB_IDE_8_40
COMPONENTS REQUIRED
Microcontroller: PIC16F877A
Push Button
ALGORITHM
1. Start
2. Initialize flag=0
3. Make RC 4 pin output and RB) pin input
4. Enable internal pull up
5. Set Global interrupt enable as 1
THEORY
The interrupt is triggered by an input on RB0, either as the signal goes from 0 to 1, called rising
edge, or as falling edge. This sets the interrupt flag ,and if the interrupt is enabled the
microcontroller goes to the interrupt subroutine ,The use of the RB0/Into to manage interrupt
externally generated requires the setting of a couple of registers of the PIC microcontroller that
are INTCON and OPTION_REG.
PROGRAM
#include<pic.h>
bit flag=0;
void interrupt intt()
{
INTF=0; // clear interrupt flag
if(flag==1)
{
RC4=1; // LED ON
flag=0;
}
else
{
RC4=0; // LED OFF
flag=1;
}
}
void main()
{
TRISC4=0; // Make Portc 4 output
// Make Portb 0 input
TRISB0=1;
RBPU=0; // enable internal pull up ( only for portb in INPUT mode)
GIE=1; // global interrupt enable
INTE=1; // external interrupt enable
ADCON1=0X07;
while(1);
}
PROGRAM WINDOW
INTERFACING DIAGRAM
RESULT
AIM:
SOFTWARE USED:
MPLAB_IDE_8_40
COMPONENTS REQUIRED
Microcontroller: PIC16F877A
ALGORITHM
Transmitter
1 .start
2. Assign string ASIET to a
3. Assign PORT D as input and RC6 as TX output
4. Enable transmission bits
5. Set Baud rate 9600 by assigning SPBRG=129
6. Begin infinite loop
A, Check if RD0=0
i.Transmit each character
ii call delay
7. stop
Receiver
1. Start
2. Assign RC7 as RX input
3. Enable reception bits
THEORY
PROGRAM
TRANSMITTER
#include<pic.h>
char a[6]="ASIET";
void delay(long g) // delay function
{
int i,j; for(i=0;i<=g;i++)
{
for(j=0;j<255;j++);
}
}
void data(char k)
{
TXREG=k; // load 8 bit data transmission register
while(TRMT==0);
// wait till 8th bit of data transmit serially
}
void main()
{
TRISD=0xFF; // for connecting switch
while(1)
{
if (RD0==0)
{
for(int i=0;i<6;i++)
{
data(a[i]);
delay(300);
}
}
}
}
PROGRAM WINDOW
INTERFACING DIAGRAM
RECIEVER
PROGRAM:
#include<pic.h>
void delay(long g)
{
int i,j;
for(i=0;i<=g;i++)
{
for(j=0;j<255;j++);
}
RE2=0;
}
RE0=1;
RE1=0;
PORTD=lcd_c;
RE2=1;
delay(1);
RE2=0;
void lcd_initiltn()
{
ADCON1=0X82;
TRISE0=0;
TRISE1=0;
TRISE2=0;
TRISD=0;
delay(15);
lcd_cmd(0x30);
delay(5);
lcd_cmd(0x30);
delay(1);
lcd_cmd(0x30);
delay(1);
lcd_cmd(0x38);
lcd_cmd(0x0c);
lcd_cmd(0x06);
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_data(b);
}
void main()
{
TRISC7=1; // make RX pin as input
RX9=0;
SYNC=0;
BRGH=1;
SPBRG=129; // baudrate=9600
SPEN=1;
CREN=1;
lcd_initiltn();
GIE=1; // enable USART interrupt
PEIE=1;
RCIE=1;
while(1);
}
PROGRAM WINDOW
INTERFACING DIAGRAM
RESULT
USART was interfaced successfully to PIC16F877A.
Expt No: 10
Date:28.3.2015
AIM
To design and setup a circuit to generate a square wave with sec on time using timer.
SOFTWARE USED
MPLAB_IDE_8_40
Components Required
Microcontroller: PIC16F877A
ALGORITHM
1. Start
THEORY
PIC 16F877 has 3 different timers PIC Timer0, PIC Timer1, PIC Timer2.We can use
these timers for various important purposes. So for we used delay procedure to implement
some delay in the program, that was counting up to a specific value, before the program could
be continued. Delay procedure had two disadvantages. Now using Timers we can build a very
precise time delays which will be based on the system clock and allow us to achieve our desired
time delay well known in advance PIC Timer Timer 0.
Design
// = 200ns * 255(TMR0)
// = 51.2us
// Max. time with prescalar : 200ns * 255(TMR0) *
256(prescalar)
// = 13.1ms
// For 10ms prescalar value must be 256
// = 200ns * 256(prescalar) * x(TMR0) = 10ms
// x(TMR0) = 10ms / (200ns * 256(prescalar))
// = 195.31
// Value to TMR0 = 255 - 195
// = 60 ( 3C in HEX)
PROGRAM
#include<pic.h>
unsigned int a;
void interrupt time()
{
TMR0IF=0; // clear Timer0 flag
a=a-1;
if (a==0)
{
PORTB=~PORTB;
a=100;
}
TMR0=0x3c; // Reload the initial value to the
counter whenever the overflow occurs
}
void main()
{
a=100;
TRISB=0x00;
T0CS=0; // Timer 0 clock source select
PS1=2;
PS0=1;
GIE=1; // Interrupt enable
PEIE=1;
TMR0IE=1;
PORTB=0xFF;
TMR0=0x3c; // Initial value loaded for
10mS.
while (1);
}
PROGRAM WINDOW
INTERFACING DIAGRAM
OUTPUT WINDOW
RESULT
Square wave is generated using PIC16F877A with time period 20ms