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

Lab Work - 08: Microprocessor Based System

This document contains instructions for a lab assignment on interfacing a microprocessor with a keypad. It discusses two methods for connecting multiple keys to a microcontroller's I/O pins: directly connecting each key or using a multiplexed connection to reduce the number of pins needed. The objective is to write code to display the number on a 7-segment display corresponding to the key pressed. An LED will toggle to indicate the program is running. Example code is provided to initialize timers and ports, set up an interrupt service routine, and scan the keypad in the main loop.

Uploaded by

MuhammadHadi
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
0% found this document useful (0 votes)
28 views

Lab Work - 08: Microprocessor Based System

This document contains instructions for a lab assignment on interfacing a microprocessor with a keypad. It discusses two methods for connecting multiple keys to a microcontroller's I/O pins: directly connecting each key or using a multiplexed connection to reduce the number of pins needed. The objective is to write code to display the number on a 7-segment display corresponding to the key pressed. An LED will toggle to indicate the program is running. Example code is provided to initialize timers and ports, set up an interrupt service routine, and scan the keypad in the main loop.

Uploaded by

MuhammadHadi
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/ 5

Page 1 of 5

Department of Electrical Engineering

LAB WORK - 08
Microprocessor Based System
Spring/Fall/Summer 20__
Student Name SID Marks

Marks Distribution:
CLO_2
Tasks Total Marks
Marks Obtained
Keypad Assembly Code. 3
Task Proteus simulation. 2
Home Assignment. 2
Hardware Working. 3
Total Marks 10

CLASS ID: __________________

DATE: ______________________

Signature of Faculty/Lab Engineer: ___________________________________________

Remarks: ________________________________________________________________
Microprocessor Based System Instructor:
College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology [email protected]
Page 2 of 5

BASIC THEORY CLO_2


Following is one way to interface 8 different switches (keys) with PIC Microcontroller. This
configuration requires more no. of I/O pins and due to more no. of pull-up resistors the overall
system gets bulky.

For 8 keys:
8 I/O pins.
8 Pull-up resistors.

The other technique is by multiplexing. This technique reduces the no. of I/O pins and pull-up
resistors. On the other hand, it increases the programming complexity to an extent.

For 16 keys:
8 I/O pins.
4 Pull-up resistors.

PIC18F452
Microprocessor Based System Instructor:
College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology [email protected]
Page 3 of 5

OBJECTIVE #1
Make a program that shows number on 7-segment display when respective key is pressed. For
example, pressing keypad button 2 should show “2” on the 7-segment display. Interface 4 keys.
Also, toggle an LED on E0 to show if the program is running.

Example Code:
LIST P=PIC18F452, F=INHX32, N=0, ST=OFF, R=HEX ; INCLUDE CONTROLLER TYPE
#INCLUDE P18F452.INC ; INCLUDE CONTROLLER FILE
; FUSE BIT SETTINGS
CONFIG OSC = HS, OSCS = OFF ; HS=HIGH OSCILATOR
CONFIG WDT = OFF ; WATCH DOG TIMER OFF
CONFIG PWRT = ON, BOR = OFF ; POWER UP TIMER ON
; BROWN OUT RESET VOLTAGE OFF
CONFIG DEBUG = OFF, LVP = OFF, STVR = OFF ; DEBUG OFF
; LOW VOLTAGEPROGRAMMING OFF
ORG 0000H ; STARTING ADDRESS
CLRF TRISB ; Setting PORTB as output port
CLRF TRISE ; SETTING PORTE AS OUTPUT PORT
GOTO INITIALIZE ; BYPASS INTERRUPT VECTOR TABLE
;---------------------------------------------------------------------------------------------------------------------------------------
ORG 0008H ; INTERRUPT VECTOR
BTFSS INTCON, TMR0IF ; TIMER0 INTERRUPT SCAN
RETFIE ; NO, RETURN TO INITIALIZE
GOTO ISR ; YES, GO TO TIMER0 ISR
; ----------------------------------- INITIALIZE TIMER0 AND KEEPING CPU BUSY-----------------------------------------
ORG 00100H
INITIALIZE
MOVLW B'00000011'
MOVWF TRISD ; SETTING PORTD AS I/O PORT
MOVLW B'00111111'
MOVWF PORTB ; SEND 0 DIGIT ON PORTB
; -------------------------------------------------------TIMER SETTING-----------------------------------------------------------
MOVLW 0x08 ; TIMER0, 16-BIT, No prescaler
; Internal CLK
MOVWF T0CON ; load T0CON register
MOVLW 0x00 ; 00H TO LETRAL
MOVWF TMR0H ; LOAD TIMER0 TO HIGH BYTE
MOVLW 0x00 ; 00H TO LETRAL
MOVWF TMR0L ; 00H TO LOW BYTE
BCF INTCON, TMR0IF ; CLEAR TIMER0 INTERRUPT FLAG BIT
BSF T0CON, TMR0ON ; START TIMER0
BSF INTCON, TMR0IE ; ENABLE TIMER0 INTERRUPT
BSF INTCON, GIE ; ENABLE INTERRUPT GLOBALLY

Microprocessor Based System Instructor:


College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology [email protected]
Page 4 of 5

; -------------------------------------------------------MAIN LOOP----------------------------------------------------------------
MAIN ; LABEL
BSF PORTE, 0 ; SET BIT E0 HIGH
CALL DELAY_1S ; DELAY OF 1SEC
BCF PORTE, 0 ; SET BIT E0 LOW
CALL DELAY_1S ; DELAY OF 1SEC
GOTO MAIN ; GOTO MAIN
; --------------------------------------------INTERRUPT SERVICES ROUTINE--------------------------------------------------
ISR ; INTERRUPT SERVICES ROUTINE
ORG 200H ; ISR STARTING ADDRESS
BCF PORTD, 2 ; SEND 0 ON COL 1 FOR SCANING
BSF PORTD, 3 ; SEND 1 ON COL 2
BTFSS PORTD, 0 ; TEST ROW 1
CALL NUM_1 ; CALL NUM 1 FUNCTION
BTFSS PORTD, 1 ; TEST ROW 2
CALL NUM_3 ; CALL NUM 3 FUNCTION
BSF PORTD, 2 ; SEND 1 ON SCAN COL 1
BCF PORTD, 3 ; SEND 0 ON SCAN COL 2
BTFSS PORTD, 0 ; TEST ROW 1
CALL NUM_2 ; CALL NUM 2 FUNCTION
BTFSS PORTD, 1 ; TEST ROW 2
CALL NUM_4 ; CALL NUM 4 FUNCTION
; -------------------------------------------------------TIMER SETTING-----------------------------------------------------------
MOVLW 0x00 ; 00H TO LETRAL
MOVWF TMR0H ; LOAD TIMER0 TO HIGH BYTE
MOVLW 0x00 ; 00H TO LETRAL
MOVWF TMR0L ; 00H TO LOW BYTE
BCF INTCON, TMR0IF ; CLEAR TIMER0 INTERRUPT FLAG BIT
RETFIE ; RETURN FROM TNTERRUPT
;---------------------------------------------------------------------------------------------------------------------------------------
NUM_1 ; FOR DIGIT 1
MOVLW B'00000110'
MOVWF PORTB
RETURN
NUM_2 ; FOR DIGIT 2
MOVLW B'01011011'
MOVWF PORTB
RETURN
NUM_3 ; FOR DIGIT 3
MOVLW B'01001111'
MOVWF PORTB
RETURN
NUM_4 ; FOR DIGIT 4
MOVLW B'01100110'
MOVWF PORTB
RETURN
Microprocessor Based System Instructor:
College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology [email protected]
Page 5 of 5

;---------------------------------------------------------------------------------------------------------------------------------------
#include <DELAY_20MHZ.asm> ; INCLUDE DELAY FILE
END ; END PROGRAM

Home Assignment: CLO_2

Make a program that shows number on 7-segment display when respective key is pressed. For
example, pressing keypad button 3 should show “3” on the 7-segment display. Interface 16 keys and
show number from 1 to F (HEX). Also toggle an LED on C0 to show if the program is running.
Submission Details:
• Lab manual
• Print of code in assembly language.
• Proteus simulation circuit bitmap image (print screen and sniping tool’s images are not
acceptable)
• Code simulate on trainer kit.

Microprocessor Based System Instructor:


College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology [email protected]

You might also like