Sunteți pe pagina 1din 13

Laboratory Experiment 1

Basic I/O Ports Manipulation for PIC

ECE 542/L Microprocessor Systems


Objectives:
• To be able to determine the different
ports of the PIC16F877a.

• To be able to manipulate the port status


of the PIC16F877a.

• To be able to code a program for the


PIC16F877a.
Before going to the programming you should understand
the following things:

• Output pins of a PIC Microcontroller is divided in to


different PORTS containing a group of GPIO (General
Purpose Input Output Pins) pins.

• In 16F PIC Microcontrollers, there are two registers


associated with a port, TRIS and PORT. eg: TRISB,
PORTB, TRISC, PORTC
• TRIS stands for Tri-State, which determines the
direction of each GPIO pin. Logic 1 at a particular
bit of TRIS register makes the corresponding pin
Input and Logic 0 at a particular bit of TRIS register
makes the corresponding pin Output. An Input pin
of PIC Microcontroller have very high input
impedance, thus it may said to be in Hi-Impedance
state.
• PORT register is used to read data from or write
data to GPIO pins. Logic 1 at a particular bit of
PORT register makes the corresponding pin at
Logic High (VDD) and Logic 0 at a particular bit of
PORT register makes the corresponding pin at
Logic Low (VSS) if that pin is an Output pin (TRIS
bit is 0).

• PORT register can be used to read digital data from


an Input pin. Logic 1 indicates the pin is at Logic
High and Logic 0 indicates that the pin is at Logic
Low.
PIC16F877A Pin Outs
Circuit Design for Blinking LEDs
Laboratory Exercise 1: Blinking LEDs

Exercise details:
• When PORT RB0 is Low, LEDs connected to RC0-
RC3 must blink
• When PORT RB0 is High, LEDs connected to
RC4-RC7 must blink
• When PORT RB1 is High, LEDs connected to
RC0-RC7 must blink
Laboratory Exercise 1: Blinking LEDs
Open your mikroC and create a project for this
experiment.
int x=1;
void main() {
TRISB = 0b111; //set port B to input
TRISC = 0b0000; //set port C to output
PORTC = 0; //initialize port C
PORTB = 0; //initialize port C
while(x=1){
if (PORTB.RB0 == 1) //check status of PORTB pin RB0
{
PORTC = 0; //set port C to low
delay_ms(50);
PORTC = 0xF0; //set port C to high
delay_ms(50);
}
…continued

else if (PORTB.RB1 == 1)
{
PORTC = 0; //set port C to low
delay_ms(50);
PORTC = 0xFF; //set port C to high
delay_ms(50);
}
else
{
PORTC = 0; //set port C to low
delay_ms(50);
PORTC = 0xF; //set port C to high
delay_ms(50);
}

}
}
Design Exercise 1: Walking LED

Exercise details:
• Utilize the previous circuit design for this activity.
• When PORT RB0 is High and RB1 is Low, lighted
LED must shift to the left
• When PORT RB0 and RB1 are Low, lighted LED
must shift to the right
• When PORT RB0 and RB1 are High, LEDs must
blink
• When PORT RB0 is Low and RB1 is High, LEDs
must stay lighted
Copy your codes and circuitry in an A4 sized PDF file
together with your name and subject details. Content
of the file must be the result of Laboratory Exercise
and Design Exercise.

Attach the file in the your Schoology account under


the “Laboratory Experiment 1” activity found at the
Materials section.
Laboratory Experiment 1
Basic I/O Ports Manipulation for PIC

ECE 542/L Microprocessor Systems

S-ar putea să vă placă și