100% found this document useful (1 vote)
162 views21 pages

Pin Configuration of PIC16F877A

The document summarizes key registers and instructions for the PIC16F877A microcontroller. It describes the STATUS register, which stores status bits like carry, zero, and digit carry. It also describes other important registers like FSR, INDF, PCL, and PCLATH. The instruction set is summarized with 35 instructions, including MOVWF to move data and BSF/BCF to set/clear bits. Example assembly code is provided to blink an LED and implement an 8-bit down counter on the ports.

Uploaded by

Aditya Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
162 views21 pages

Pin Configuration of PIC16F877A

The document summarizes key registers and instructions for the PIC16F877A microcontroller. It describes the STATUS register, which stores status bits like carry, zero, and digit carry. It also describes other important registers like FSR, INDF, PCL, and PCLATH. The instruction set is summarized with 35 instructions, including MOVWF to move data and BSF/BCF to set/clear bits. Example assembly code is provided to blink an LED and implement an 8-bit down counter on the ports.

Uploaded by

Aditya Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Pin Configuration of PIC16F877A

Functions of Various Port Pins


An Instruction Cycle
Basic Architecture of PIC16F877A
STATUS Register
The STATUS register is a 8-bit register that stores the status
of the processor. This also stores carry, zero and digit carry
bits.
STATUS – address 03H, 83H

Figure: STATUS register


C = Carry bit
DC = Digit carry (same as auxiliary carry)
Z = Zero bit
NOT_TO and NOT_PD – Used in conjunction with PIC's sleep
mode
RP0– Register bank select bit used in conjunction with
direct addressing mode.
FSR Register

(File Selection Register, address = 04H, 84H)


FSR is an 8-bit register used as data memory address pointer. This is used in
indirect addressing mode.

INDF Register

(INDirect through FSR, address = 00H, 80H)


INDF is not a physical register. Accessing INDF access is the location
pointed to by FSR in indirect addressing mode.
PCL Register

(Program Counter Low Byte, address = 02H, 82H)


PCL is actually the lower 8-bits of the 13-bit program counter. This is a both
readable and writable register.

PCLATH Register

(Program Counter Latch, address = 0AH, 8AH)


PCLATH is a 8-bit register which can be used to decide the upper 5bits of the
program counter. PCLATH is not the upper 5bits of the program counter.
PCLATH can be read from or written to without affecting the program
counter. The upper 3bits of PCLATH remain zero and they serve no purpose.
When PCL is written to, the lower 5bits of PCLATH are automatically loaded
to the upper 5bits of the program counter, as shown in the figure.
Register File Map
Instruction Set:
The instruction set for PIC16C74A consists of only 35 instructions. Some of
these instructions are byte oriented instructions and some are bit oriented
instructions.
The byte oriented instructions that require two parameters (For example,
movf f, F(W)) expect the f to be replaced by the name of a special purpose
register (e.g., PORTA) or the name of a RAM variable (e.g., NUM1), which
serves as the source of the operand. ‘f' stands for file register. The F(W)
parameter is the destination of the result of the operation. It should be
replaced by:
F, if the destination is to be the source register.
W, if the destination is to be the working register (i.e., Accumulator or W
register).
The bit oriented instructions also expect parameters (e.g., btfsc f, b). Here
‘f' is to be replaced by the name of a special purpose register or the name of
a RAM variable. The ‘b' parameter is to be replaced by a bit number ranging
from 0 to 7.
For example:
Z equ 2
btfsc STATUS, Z
Z has been equated to 2. Here, the instruction will test the Z bit of the
STATUS register and will skip the next instruction if Z bit is clear.
The literal instructions require an operand having a known value (e.g., 0AH)
or a label that represents a known value.
For example:
NUM equ 0AH ; Assigns 0AH to the label NUM ( a constant )
movlw NUM ; will move 0AH to the W register.
Instruction
Mnemonics Description
Cycles
bcf f, b Clear bit b of register f 1
bsf f, b Set bit b of register f 1
clrw Clear working register W 1
clrf f Clear f 1
movlw k Move literal 'k' to W 1
movwf f Move W to f 1
movf f, F(W) Move f to F or W 1
swapf f, F(W) Swap nibbles of f, putting result in F or W 1
andlw k And literal value into W 1
andwf f, F(W) And W with F and put the result in W or F 1
andwf f, F(W) And W with F and put the result in W or F 1
iorlw k inclusive-OR literal value into W 1
iorwf f, F(W) inclusive-OR W with f and put the result in F or W 1
xorlw k Exclusive-OR literal value into W 1
xorwf f, F(W) Exclusive-OR W with f and put the result in F or W 1
addlw k Add the literal value to W and store the result in W 1
addwf f, F(W) Add W to f and store the result in F or W 1
sublw k Subtract the literal value from W and store the result in W 1
subwf f, F(W) Subtract f from W and store the result in F or W 1
rlf f, F(W) Copy f into F or W; rotate F or W left through the carry bit 1
rrf f, F(W) Copy f into F or W; rotate F or W right through the carry bit 1
Test 'b' bit of the register f and skip the next instruction if bit is
btfsc f, b 1/2
clear
Test 'b' bit of the register f and skip the next instruction if bit is
btfss f, b 1/2
set
Decrement f and copy the result to F or W; skip the next
decfsz f, F(W) 1/2
instruction if the result is zero
Increment f and copy the result to F or W; skip the next
incfcz f, F(W) 1/2
instruction if the result is zero
goto label Go to the instruction with the label "label" 2
Go to the subroutine "label", push the Program Counter in the
call label 2
stack
Return from the subroutine, POP the Program Counter from
retrun 2
the stack
Retrun from the subroutine, POP the Program Counter from
retlw k 2
the stack; put k in W
retie Return from Interrupt Service Routine and re-enable interrupt 2
clrwdt Clear Watch Dog Timer 1
sleep Go into sleep/ stand by mode 1
nop No operation 1
Experiment No 6 (Experiments with PIC16F877A Microcontroller)
Objectives:
(a) Familiarization with MPLAB IDE and PIC Microcontroller Programming
(b) To light up an LED and realize an 8-bit binary UP counter

PART A) Familiarisation with MPLAB IDE PIC Microcontroller Programming


Go through the tutorial of MPLAB IDE and PIC Programmer. Get familiarized with various features of
MPLAB.

We use the MPLAB IDE Software for designing, editing & compiling codes. Look out for the MPLAB Tutorial
for details, on how to begin with a new project & end up with a .hex file of the required code (after simulator
testing.)

Read the PICPgm Tutorial to know, how to feed the code ( .hex file) into the microcontroller.
Feed the Test File into the MicroController to understand the process.
Pin Diagram of PIC16F877A
PART B) To Light up an LED
Problem Statement:
Connect an LED to the RB0 of PORTB (Pin No. 33 of the IC), and write a code that will light up the given LED.

Hints for writing the program:


Write codes sequentially for each of the following
a) Select the Register Bank that contains the TRISB Register
b) Clear (equate to 0) the 0th Bit of TRISB Register (to configure RB0 as an Output Pin)
c) Select the Register Bank that contains the PORTB Register
d) Set (equate to 1) the 0th Bit of PORTB Register, so that RB0 outputs a High voltage and lights up the LED.

Compile the code, test it using the MPLAB Simulator, and feed the .hex file into the IC.

PART C) To realize a software 8-bit DOWN counter using PIC Microcontroller


Problem Statement
To realize an 8-bit UP counter through PORTB

Procedure:
Connect 8 LEDs to the port pins of PORTB through current limiting resistors (220 Ohm each). Write a delay routine
to generate approximately 0.5 s delay. Define an 8-bit variable ‘Counter’. Initialize ‘Counter’ to FFH. Use the
instruction ‘decf Counter, W’ to decrement the counter. Output the content of W to PORTB. Introduce a delay of 0.5
s and repeat in an infinite loop.
Circuit Diagram of the Microcontroller Circuit for LED Lighting
Blinking of LED with a Delay

MAIN_PROG CODE

start

bsf STATUS, RP0


bcf STATUS, RP1
bcf TRISB, 0

bcf STATUS, RP0

Loop

bsf PORTB, 0

movlw 0xFF
movwf count
Delay1
nop
decfsz count
goto Delay1

bcf PORTB, 0

movlw 0xFF
movwf count
Delay2
nop
decfsz count
goto Delay2

goto Loop

END ; directive 'end of program'


Blinking of LED with More Delay (Using Two Nested Loops)

MAIN_PROG CODE

start

bsf STATUS, RP0


bcf STATUS, RP1
bcf TRISB, 0

bcf STATUS, RP0

Loop

bsf PORTB, 0

movlw 0xFF
movwf count2
Delay11 movlw 0xFF
movwf count1
Delay12
nop
decfsz count1
goto Delay12
decfsz count2
goto Delay11

bcf PORTB, 0

movlw 0xFF
movwf count2
Delay21 movlw 0xFF
movwf count1
Delay22
nop
decfsz count1
goto Delay22
decfsz count2
goto Delay21
goto Loop

END ; directive 'end of program'

You might also like