0% found this document useful (0 votes)
45 views

Lab 4 (35,66)

Uploaded by

ehtishamrazzaq12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Lab 4 (35,66)

Uploaded by

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

Embedded Systems Lab

Lab No: 04

Practicing PIC microcontroller


assembly language programming

Submitted to: Submitted by:


Mr. Asad Mohammad Hussain
(220401035) Syed Mubashir Ali
(220401066)
Objective:
 Familiarization with I/O ports programming
 Introduction to delay routines and timing issues
 Implementing LED flasher counters.

Equipment:
 PIC 16F877A microcontroller
 Computer
 Proteus Software
 MPLAB X IDE Software

Introduction:
There are a total of 5 ports in the PIC 16F877A microcontroller which are named
PORT A, B, C, D and E. In this lab we will program the ports to run several
programs onto it. Firstly, we will program delay routines and implement the LED
flasher counter and secondly, we will implement it with 2 switches which will be
used to increment and decrement the counting. The detailed pinout diagram of the
microcontroller is shown below which shows the ports and the power pins.
Programming the ports of a microcontroller such as the PIC16F877A using
assembly language provides a deep understanding of embedded systems and low-
level hardware interactions. In this introduction, we'll look into the basics of
programming the ports of the PIC16F877A microcontroller, which involves
configuring the Input/Output (I/O) ports to interact with external devices.

The PIC16F877A is a widely used 8-bit microcontroller. Understanding how to


program its ports in assembly language enables us to control various external
devices and interface with sensors, actuators, and other components in embedded
systems.

To begin programming the ports of the PIC16F877A, one must familiarize


themselves with its architecture and register set. Each port of the microcontroller,
such as PORTA, PORTB, PORTC, etc., is associated with specific registers
responsible for controlling its behavior. These registers include TRISA, TRISB,
TRISC for configuring the direction of the ports as input or output, and
corresponding port registers to read from or write to the ports.
The process of programming the ports typically involves the following steps:
 Configuring the direction of the ports: Use the TRIS registers to set whether
each pin of the port is configured as input (logic 1) or output (logic 0).
 Writing data to output ports: To send data to external devices connected to
output ports, write the desired value to the corresponding port register (e.g.,
PORTA, PORTB, PORTC).
 Reading data from input ports: To read data from sensors or other external
devices connected to input ports, read the value from the corresponding port
register.

Assembly language provides direct access to the microcontroller's registers and


allows precise control over hardware interactions. Developers can write efficient
and optimized code tailored to specific requirements, making assembly language
programming essential for embedded systems.

Task 1: Implement an LED Flasher circuit that counts from 0-15.

Procedure:
 Open the MPLAB X IDE software.
 Create a new project and name it LED flasher circuit.
 Create a new source file and select assembly file.
 Write down the code for the LED flasher program.
 Build the program.
 Open the Proteus software and implement the LED flasher circuit.
 Open the HEX file on the microcontroller in the proteus software.
 Run the program.
 Verify the results.
Code:
PORTB EQU 06H
TRISB EQU 86H
VALUE EQU 20H
count1 EQU 21H
count2 EQU 22H
STATUS EQU 03H

LIST P=16F877A
ORG 0
GOTO START
CONFIG 3F79H
DELAY_1S
movlw .255
movwf count1
movlw .255
movwf count2
a
decfsz count1,1
goto a
decfsz count2,1
goto a
RETLW 0
START
BANKSEL TRISB
MOVLW B'00000000'
MOVWF TRISB
BANKSEL PORTB
CLRF PORTB
CLRF VALUE
BEGIN
MOVF VALUE,W
SUBLW .15
BTFSC STATUS,2
CLRF VALUE
MOVF VALUE,W
MOVWF PORTB
CALL DELAY_1S
INCF VALUE
GOTO BEGIN
END
Proteus Circuit:
Count 1:
Count 2:

Count 3:
Continued till Count 15:

Task 2: Modify the LED Flasher circuit program that counts from 0-15
when increment switch is pressed and counts backwards when decrement
switch is pressed.

Procedure:
 Open the MPLAB X IDE software.
 In the same project modify the assembly code with inputs of 2 switches.
 Build the program.
 Open the HEX file on the microcontroller in the proteus software.
 Run the program.
 Verify the results.
Code:
PORTB EQU 06H
TRISB EQU 86H
count1 EQU 20H
count2 EQU 21H
VALUE EQU 22H
STATUS EQU 03H

LIST P=16F877A
ORG 0
GOTO START
CONFIG 3F79H
DELAY_1S
movlw.255
movwfcount1
movlw.255
movwfcount2
a
decfsz count1,1
goto a
decfsz count2,1
goto a
RETLW 0
START
BANKSEL TRISB
MOVLW B'11000000'
MOVWF TRISB
BANKSEL PORTB
CLRF PORTB
CLRF VALUE
BEGIN
BTFSC PORTB,7
INCF VALUE
BTFSC PORTB,6
DECF VALUE
MOVF VALUE,W
SUBLW .15
BTFSC STATUS,2
CLRF VALUE
MOVF VALUE,W
MOVWF PORTB
CALL DELAY_1S
GOTOBEGIN
END

Proteus Circuit:
Count 1 when increment switch is pressed:
Count 2 when increment switch is pressed:

Count 3 when increment switch is pressed:


Continued till Count 15 when increment switch is pressed:

Count 3 when decrement switch is pressed:


Count 2 when decrement switch is pressed:

Count 1 when decrement switch is pressed:


Conclusion: In this lab we looked at the programming of the I/O ports of the
PIC 16F877A microcontroller and practiced on how to run a LED flasher
circuit on the ports of the microcontroller. We also connected 2 switches to the
ports of the microcontroller to count up and down.

You might also like