0% found this document useful (0 votes)
93 views8 pages

Mpi Assignment 2

This document contains the code for an assignment on microprocessor programming and interfacing. It includes code to read the state of buttons on a microcontroller and display numbers on a 7-segment display. It also includes code for interfacing with a LCD display and keyboard. The code performs operations such as squaring a number input from the keyboard and displaying the result.

Uploaded by

Umair Hameed
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)
93 views8 pages

Mpi Assignment 2

This document contains the code for an assignment on microprocessor programming and interfacing. It includes code to read the state of buttons on a microcontroller and display numbers on a 7-segment display. It also includes code for interfacing with a LCD display and keyboard. The code performs operations such as squaring a number input from the keyboard and displaying the result.

Uploaded by

Umair Hameed
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/ 8

DEPARTMENT OF ELECTRICAL

ENGINEERING,

FAST-NU, LAHORE

Syed Kausain Mehdi

15L-4557

BS-EE-2B

Microprocessor Programing and Interfacing

ASSIGNMENT # 2

Q#1 ; '1' AT ZEROTH BIT LOCATION = ZEROTH


;Q#1 LOCATION
; '1' AT MSB IS AT 7TH LOCATION OR 7TH BIT

; R6 = LOCATION OF FIRST '1' DELAY_25mS:

MOV R1,#50

ORG 0x0 JUMP1:

MAIN: MOV R2,#250

MOV R0 ,#0H JUMP2:

JNB P2.3 ,$ DJNZ R2,JUMP2

CALL DELAY_25mS DJNZ R1,JUMP1

JB P2.3 , $ ret

MOV A,P1

; MOV R7 ,A ;8-BITT DATA

;R0 = COUNT END

CHECK_NEXT:

RRC A

JC FOUND

INC R0

JMP CHECK_NEXT

FOUND:

MOV 50H,R0
Q#2
MOV R6,50H

JMP MAIN
;P1.0 CONTROL SWITCH
RET
;P2.3 = MSB , P2.0 = LSB

;FIRST NUMBER AT 50H


;FIRST NUMBER AT 51H MOV A ,R2

;FIRST NUMBER AT 52H CJNE A, 32H,FINAL_ONE

ORG 0X0 MOV R3 ,A

MOV SP,#49H MOV P3 ,A

MOV R0,#0H ;COUNTER JMP AGAIN_INPUT

AGAIN_INPUT: FINAL_ONE:

JB P1.0 ,$ JC ANSWER

CALL DELAY_25mS MOV R3 ,A

JNB P1.0 ,$ MOV P3 ,A

JMP AGAIN_INPUT

MOV A ,P2 ANSWER:

ANL A ,#00001111B MOV A , 32H

PUSH 0E0H MOV P3 ,A

INC R0 JMP AGAIN_INPUT

MOV A,R0

CJNE A,#3H ,AGAIN_INPUT BIG_ONE:

JC BIG_NUMBER

POP 30H MOV R2 ,30H

POP 31H JMP CHECK_NEXT

POP 32H

MOV A, 30H BIG_NUMBER:

CJNE A,31H,BIG_ONE MOV R2 ,31H

MOV R2, A JMP CHECK_NEXT

CHECK_NEXT: DELAY_25mS:
MOV R6,#50

JUMP1: ; MOV R7 , #0H ;COUNTER

MOV R7,#250 ; MOV 50H,#8H

JUMP2: ; ;2 DIGIT NUMBER * 4 NUMBERS = 8


TOTAL COUNTER
DJNZ R7,JUMP2
NEXT_NUMBER:
DJNZ R6,JUMP1
MOVC A ,@A+DPTR
ret
CLR C

SUBB A,#30H

MOV R0 ,A

MOV B, #10
END
MUL AB

MOV R0 ,A

MOV A , R7 ;COUNTER IS LOADED

INC A

INC R7

MOVC A ,@A+DPTR

CLR C

SUBB A,#30H

MOV R1 ,A

Q#3:
;FOSC = 12MHZ ADD A,0H ;R0 = 0H

MOV P2 , A

ORG 0X0 MOV A , R7 ;COUNTER IS LOADED

MOV DPTR ,#LIST INC A

MOV A ,#0H INC R7


CALL DELAY_1SEC

CJNE A,#8H,NEXT_NUMBER

DELAY_25mS:

MOV R4,#50

JUMP1:

MOV R5,#250

JUMP2:

DJNZ R5,JUMP2

DJNZ R4,JUMP1
Q#4
ret

; KEYBOARD INTERFACING CODE FROM MPI


DELAY_1SEC: LAB.....

MOV R3,#40

HERE1: org 0x0

CALL DELAY_25mS

DJNZ R3,HERE1 mov p1,#0 ; port p1 is for rows (output port)

mov p2,#0ffh ; port p2 is for columns (input


port)

RET
;LCD STARTING

MOV A , #0EH
LIST: DB "12","54","39","89"
CALL COMMAND_WRT

END
;;;;; keypad info
rows equ 4 anl a,r0

cols equ 3

cjne a,0h,key_pressed

;;;; creating mask for checking columns mov a,r1

rl a

mov a,#0h mov r1,a

mov r1,#0h inc r2 ; r2 will


contain the row index
rot_again:
cjne r2,#rows,next_row
setb c
jmp again
inc r1

rlc a
key_pressed:
cjne r1,#cols,rot_again
call delay ; debounce time

again1:
;;;;; start scanning
rrc a
start:
jnc findkey
mov r0,a ; mask is in r0
inc r3 ; r3 contains
again: the column index
mov r1,#0feh ; ground 0th row jmp again1
mov r2,#0

mov r3,#0 findkey:

mov a,#cols
next_row: mov b,r2
mov p1,r1 mul ab
mov a,p2 add a,r3

mov dptr,#key
movc a,@a+dptr MOV B , #2

mov r4,a DIV AB

MOV 63H , B

release_key: MOV B , #2

mov a,p2 DIV AB

anl a,r0 MOV 64H , B

cjne a,0h,release_key

call delay ; debounce time MOV A,64H

MOV A,R4 ADD A,30H

MOV B,R4 CALL DATA_WRITE

MUL AB

MOV A,63H

MOV 60H , A ;SQAURED NUMBER ADD A,30H

;MOV P3,A CALL DATA_WRITE

MOV A, #1H MOV A,62H


; clear display screen
ADD A,30H
CALL COMMAND_WRT
CALL DATA_WRITE

MOV A , 60H
MOV A,61H
MOV B , #2
ADD A,30H
DIV AB
CALL DATA_WRITE
MOV 61H , B

MOV B , #10
jmp again
DIV AB
COMMAND_WRT:
MOV 62H , B
CALL DELAY MOV R5,#45

MOV P3 , A lOOOP:

CLR P0.0 ;RS PIN MOV R6,#255

CLR P0.1 ;R/W PIN DJNZ R6,$

SETB P0.2 ;E PIN DJNZ R5, LOOOP

CLR P0.2 ret

RET DELAY_25mS:

DATA_WRITE: MOV R1,#50

CALL DELAY JUMP1:

MOV P3 , A MOV R2,#250

SETB P0.0 ;RS PIN JUMP2:

CLR P0.1 ;R/W PIN DJNZ R2,JUMP2

SETB P0.2 ;E PIN DJNZ R1,JUMP1

CLR P0.2 ret

RET

org 0x100

DELAY: key: db 1,2,3,4,5,6,7,8,9,10,0,11 /* 1D index =


column index + (row index * total no. of cols)*/

enD

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy