السلام عليكم
لي فترة طويله وانا احاول ان اربط الكيباد مع شاشه matrix interface لمايكروكنترولر 8051 ولكن من غير فائده .. هل هناك اي شخص يستطيع تصحيح الكود تبعي ؟؟
اعتقد انه ناقصه شي بسيط جداً .. وهذا الشي لم استطع التوصل اليه .. هل يجب علي اضافة او مسح اي ايعاز ؟
الكود هو كالتالي:
كود:
rw0 equ P0.4;
rw1 equ P0.5;
rw2 equ P0.6;
rw3 equ P0.7;
cl0 equ P0.0;
cl1 equ P0.1;
cl2 equ P0.2;
cl3 equ P0.3;
;*************************************************
;Main program
org 00h
ljmp main
org 30h
main: mov P0,#0ffh ;Configure input
acall scan_key ;Scan for keypress
acall display ;display the key pressed
sjmp main ;Loop
;*************************************************
;Subroutine to scan keys
scan_key:mov P0,#0ffh
clr cl0
mov a, P0
anl a,#00001111b ;(logical AND)clear the upper nibble and keep the lower
cjne a,#00001111b,Row0 ; compare till all keys released
setb cl0 ; set carry falge
clr cl1
mov a, P0
anl a,#00001111b
cjne a,#00001111b,Row1
setb cl1
clr cl2
mov a, P0
anl a,#00001111b
cjne a,#00001111b,Row2
setb cl2
clr cl3
mov a, P0
anl a,#00001111b
cjne a,#00001111b,Row3
setb cl3
ret
row0: mov dptr,#led_data ; Fetch the first address of table
mov r6,#04h
clr c ; falge=0 no type has been pressed
rww0: rrc a ; shift the port pin into Acc.
jc next0 ;jmp if carry flage is set
sjmp over ;short jump to over
next0:inc dptr
djnz r6,rww0
sjmp scan_key
row1: mov dptr,#led_data+4h
mov r6,#04h
clr c
rww1: rrc a
jc next1
sjmp over
next1:inc dptr
djnz r6,rww1
sjmp scan_key
row2: mov dptr,#led_data+8h
mov r6,#04h
clr c
rww2: rrc a
jc next2
sjmp over
next2:inc dptr
djnz r6,rww2
sjmp scan_key
row3: mov dptr,#led_data+0ch
mov r6,#04h
clr c
rww3: rrc a
jc next3
sjmp over
next3:inc dptr
djnz r6,rww3
sjmp scan_key
over: ret
;*************************************************
;Display subroutine
display:clr a
movc a,*a+dptr
mov P0,a
ret
;*************************************************
;lookup table
led_data:db 0fch,066h,0feh,09dh; For row1:0 1 2 3
db 060h,0b6h,0f6h,0fdh; For row2:4 5 6 7
db 0dah,0beh,0efh,09fh; For row3:8 9 A B
db 0f2h,0e0h,0ffh,08fh; For row4:C D E F
;*************************************************
$include(t89c51cc01.inc)
end