Sie sind auf Seite 1von 6

Interfacing Keypad with PIC 16F877A Microcontroller

Write and implement assembly code to add any two single digit number (0-4) from the key pad and
display the result on 7-segment.

CODE
STATUS EQU 03H

PORTB EQU 06H

TRISB EQU 86H

PORTD EQU 08H

TRISD EQU 88H

;***************************

LIST P=16F877A

ORG 0

GOTO START

__CONFIG H'3F72'

;***************************

START

BANKSEL TRISB

MOVLW B'11111000'

MOVWF TRISB

MOVLW B'11110000'

MOVWF TRISD
BEGIN

BANKSEL PORTB

MOVLW B'11111000'

CLRF PORTB

BSF PORTB,0

BCF PORTB,1

BCF PORTB,1

BTFSC PORTB,4

CALL OUT1

BTFSC PORTB,5

CALL OUT4

BTFSC PORTB,6

CALL OUT7

BTFSC PORTB,7

CALL OUT10

BCF PORTB,0

BCF PORTB,2

BSF PORTB,1

BTFSC PORTB,4

CALL OUT2

BTFSC PORTB,5

CALL OUT5

BTFSC PORTB,6

CALL OUT8

BTFSC PORTB,7
CALL OUT11

BCF PORTB,0

BCF PORTB,1

BSF PORTB,2

BTFSC PORTB,4

CALL OUT3

BTFSC PORTB,5

CALL OUT6

BTFSC PORTB,6

CALL OUT9

BTFSC PORTB,7

CALL OUT12

GOTO BEGIN

OUT1

MOVLW B'00000001'

MOVWF PORTD

RETLW 0

OUT2

MOVLW B'00000010'

MOVWF PORTD

RETLW 0

OUT3

MOVLW B'00000011'

MOVWF PORTD

RETLW 0
OUT4

MOVLW B'00000100'

MOVWF PORTD

RETLW 0

OUT5

MOVLW B'00000101'

MOVWF PORTD

RETLW 0

OUT6

MOVLW B'00000110'

MOVWF PORTD

RETLW 0

OUT7

MOVLW B'00000111'

MOVWF PORTD

RETLW 0

OUT8

MOVLW B'00001000'

MOVWF PORTD

RETLW 0

OUT9

MOVLW B'00001001'

MOVWF PORTD

RETLW 0

OUT10
MOVLW B'00001010'

MOVWF PORTD

RETLW 0

OUT11

MOVLW B'00001011'

MOVWF PORTD

RETLW 0

OUT12

MOVLW B'00001100'

MOVWF PORTD

RETLW 0

END

ISIS diagram
C1

1nF U1
X1 13
OSC1/CLKIN RB0/INT
33
CRYSTAL 14 34
C2 OSC2/CLKOUT RB1
35
RB2
2 36
RA0/AN0 RB3/PGM
3 37
RA1/AN1 RB4
1nF 4 38
RA2/AN2/VREF-/CVREF RB5
5 39

3
RA3/AN3/VREF+ RB6/PGC
6 40
RA4/T0CKI/C1OUT RB7/PGD
7
RA5/AN4/SS/C2OUT
RC0/T1OSO/T1CKI
15
A 1 2 3
8 16
RE0/AN5/RD RC1/T1OSI/CCP2
9 17
RE1/AN6/WR RC2/CCP1
10 18
RE2/AN7/CS RC3/SCK/SCL
RC4/SDI/SDA
23
B 4 5 6
1 24
MCLR/Vpp/THV RC5/SDO
25
RC6/TX/CK
V1 RC7/RX/DT
26
C 7 8 9
5V
19
RD0/PSP0
20
RD1/PSP1
21
RD2/PSP2
RD3/PSP3
22
D 0 #
27
RD4/PSP4
28
RD5/PSP5
29
RD6/PSP6
30
RD7/PSP7
PIC16F877A