Maker Pro
Maker Pro

microcontroller 8051

bound2u

Nov 13, 2012
4
Joined
Nov 13, 2012
Messages
4
Hello all,

I am trying to connect my keypad to the matrix dot screen of the microcontroller 8051 by using the assembly language, but I dont know what it is the wrong with the code, can anyone help me with it ?? thanks


keyport equ P2 ;Keypad port connected here
col1 equ P2.0 ;Column 1
col2 equ P2.1 ;Column 2
col3 equ P2.2 ;Column 3
col4 equ P2.3 ;Column 4
ORG 0000H
LJMP MAIN
MAIN:
keyval equ 30H ;To store key number
pressed bit 0H ;Flag

key_init:
mov keyport,#0FH ;Make rows as o/p and col as i/p
ret

get_key:
mov keyval,#0 ;reset the number
mov keyport,#7FH ;make Row1 low
acall read_col ;read columns
jb pressed, done ;check if flag is set
mov keyval,#4 ;if not then read next row
mov keyport,#0BFH ;make Row2 low
acall read_col ;read columns

jb pressed, done ;check if flag is set

mov keyval,#8 ;if not then read next row
mov keyport,#0DFH ;make row3 low
acall read_col ;read columns

jb pressed, done ;check if flag is set

mov keyval,#12 ;if not read row4
mov keyport,#0EFH ;make row4 low
acall read_col ;read columns

done:
ret

read_col: ;read columns routine
clr pressed ;reset the flag

jb col1, nextcol ;check if first key is pressed
jnb col1,$ ;if yes then wait for key release
setb pressed ;set the flag
ret

nextcol: ;read col2
jb col2, nextcol1 ;check if second key is pressed
jnb col2,$ ;if yes then wait for key release
inc keyval ;its key number 2
setb pressed ;set the flag
ret

nextcol1: ;read col3
jb col3, nextcol2 ;check if third key is pressed
jnb col3,$ ;if yes then wait for key release
inc keyval ;its key 3
inc keyval
setb pressed ;set the flag
ret

nextcol2: ;read column 4
jb col4, exit ;check if fourth key pressed
jnb col4,$ ;if yes then wait for key release
inc keyval ;its key 4
inc keyval
inc keyval
setb pressed ;set the flag
ret
exit: ;if no key is pressed
clr pressed ;clr the flag
clr keyval ;reset the number
ret


LJMP MAIN
$include(t89c51cc01.inc)
end
 

bound2u

Nov 13, 2012
4
Joined
Nov 13, 2012
Messages
4
Hello all,

I am trying to connect my keypad to the matrix dot screen of the microcontroller 8051 by using the assembly language, but I dont know what it is the wrong with the code, can anyone help me with it ?? thanks


keyport equ P0 ;Keypad port connected here
col1 equ P0.0 ;Column 1
col2 equ P0.1 ;Column 2
col3 equ P0.2 ;Column 3
col4 equ P0.3 ;Column 4
ORG 0000H
LJMP MAIN
MAIN:
keyval equ 30H ;To store key number
pressed bit 0H ;Flag

key_init:
mov keyport,#0FH ;Make rows as o/p and col as i/p
ret

get_key:
mov keyval,#0 ;reset the number
mov keyport,#7FH ;make Row1 low
acall read_col ;read columns
jb pressed, done ;check if flag is set
mov keyval,#4 ;if not then read next row
mov keyport,#0BFH ;make Row2 low
acall read_col ;read columns

jb pressed, done ;check if flag is set

mov keyval,#8 ;if not then read next row
mov keyport,#0DFH ;make row3 low
acall read_col ;read columns

jb pressed, done ;check if flag is set

mov keyval,#12 ;if not read row4
mov keyport,#0EFH ;make row4 low
acall read_col ;read columns

done:
ret

read_col: ;read columns routine
clr pressed ;reset the flag

jb col1, nextcol ;check if first key is pressed
jnb col1,$ ;if yes then wait for key release
setb pressed ;set the flag
ret

nextcol: ;read col2
jb col2, nextcol1 ;check if second key is pressed
jnb col2,$ ;if yes then wait for key release
inc keyval ;its key number 2
setb pressed ;set the flag
ret

nextcol1: ;read col3
jb col3, nextcol2 ;check if third key is pressed
jnb col3,$ ;if yes then wait for key release
inc keyval ;its key 3
inc keyval
setb pressed ;set the flag
ret

nextcol2: ;read column 4
jb col4, exit ;check if fourth key pressed
jnb col4,$ ;if yes then wait for key release
inc keyval ;its key 4
inc keyval
inc keyval
setb pressed ;set the flag
ret
exit: ;if no key is pressed
clr pressed ;clr the flag
clr keyval ;reset the number
ret


LJMP MAIN
$include(t89c51cc01.inc)
end
 

Attachments

  • Untitled.png
    Untitled.png
    96.9 KB · Views: 171

screwball

Jan 9, 2012
89
Joined
Jan 9, 2012
Messages
89
I take it there are no errors/warnings?

Have you tried a simple test for the matrix pad? For example pressing number 1 to just light an LED?

If youve got a spare output pin, you could use an LED to kind of debug. connect the LED to the output pin, and in get key loop for example, create a quick loop (like 500ms) to turn the LED on, if the LED goes on then you know its getting to that point etc dont have a clue how to word that haha but i can try explain in detail if you wish

Codes a little messy without being in program haha
 
Top