Hi,
Below is a simple keyboard program, where i need to lock in 3 numeric digits only. The user will exit the program by pressing a non-numeric key. Until then, he can press any no. of keys. the program also displays each key properly as each one is pressed.
Problem: the program is unable to lock in the 3 digits from the key board. A similar program minus the keyboard, but using internal stored data works fine. Where is the problem ? I am using 89s52 an uvision ide. Can somebody reply please ?
ENDATA EQU #70H KEYBOARD: MOV R0, #03H ; PICK UP 3 DIGITS ONLY MOV R1, #ENDATA ;WRITE THE DATA IN TO MEMORY KEYBOARDDET: ; ONLY FOR NUMERIC. PRESSING 'D' RETURNS TO MAIN MOV P1, #11111111B ; INPUT FOR KB ;1ST ROW CLR P1.7 // makes row 1 low JB P1.3,NEXT1 // checks whether column 1 is low and jumps to NEXT1 if not low MOV A,#01H // loads a with 0D if column is low (that means key 1 is pressed) LCALL DISPLAYKB LJMP STORE ; STORE DATA IN MEMORY. NEXT1:JB P1.2, NEXT2 // checks whether column 2 is low and so on... MOV A,#02H LCALL DISPLAYKB ; DISPLAYKB IS USED TO DISPLAY THE DIGIT PRESSED LJMP STORE NEXT2:JB P1.1, NEXT3 MOV A,#03H LCALL DISPLAYKB LJMP STORE ;2ND ROW NEXT3:SETB P1.7 CLR P1.6 JB P1.3,NEXT4 MOV A,#04H LCALL DISPLAYKB LJMP STORE NEXT4:JB P1.2,NEXT5 MOV A,#05H LCALL DISPLAYKB LJMP STORE NEXT5:JB P1.1,NEXT6 MOV A,#06H LCALL DISPLAYKB LJMP STORE ;3RD ROW NEXT6:SETB P1.6 CLR P1.5 JB P1.3,NEXT7 MOV A,#07H LCALL DISPLAYKB LJMP STORE NEXT7:JB P1.2,NEXT8 MOV A,#08H LCALL DISPLAYKB LJMP STORE NEXT8:JB P1.1,NEXT9 MOV A,#09H LCALL DISPLAYKB LJMP STORE ;4TH ROW NEXT9: SETB P1.5 CLR P1.4 JB P1.2,NEXT10 MOV A,#00H LCALL DISPLAYKB LJMP STORE NEXT10:JB P1.0, GOBACK LJMP DISPLAY ; press 'D'to exit the program and display 3 digits GOBACK: LJMP KEYBOARDDET STORE: ; STORE 3 numeric digits IN ENDATA MOV @R1, A DEC R1 DJNZ R0, CALLDET LJMP KEYBOARD CALLDET: LJMP KEYBOARDDET
.
"but doesn't work"
When something doesn't work, you don't start by changing the code. You start by making sure you understand what the code is _actually_ doing. First then will you have the knowledge of _what_ you need to change. And _how_ to change.
The whole idea here is that _you_ must undertand your code. If the program doesn't work, then there is a difference between what you think you understand and what the code is actually doing. So you must figure out where you thought wrong.
The listing is still a mess and I for one will not spend much time looking at it.
You start by making sure you understand what the code is _actually_ doing. when 'looking' at a mess (my name for your posted stuff is 'scribbles', not 'code') you do not see what the code is doing you are too busy figuring out the messy stuff.
I guess most (for one I) have had a period early in their career where did more or less messy stuff till they realized that what time you save by "just whacking out some code" is definitely not a time saver, the time lost in trying to debug it is far more than the time 'saved' by making scribbles instead of code