Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/19/06 13:40
Read: times


 
#120582 - hex key pad code not working
                      ROW0             EQU          P1.3
                      ROW1             EQU          P1.2
                      ROW2             EQU          P1.1  
                      ROW3             EQU          P1.0

                      CLMN0            EQU          P1.7
                      CLMN1            EQU          P1.6
                      CLMN2            EQU          P1.5
                      CLMN3            EQU          P1.4

					              



org  0000h

    ljmp ks_main

org 0030h

;_________________________________________________________________
;---------------SERIAL PORT INITIALISATION STARTS HERE------------------------
;_________________________________________________________________


s9k_main:                  mov tmod,#20h         ;timer_0 in mode2 (8bit auto reload)
                           mov th1,#0fdh           ;set baud to 9600
                           mov scon,#50h         ;serial mode1 (8bit data varialble baud)
                           setb tr1                    ;start timer_0
                           ret


;--------------SERIAL TRANSMIT SUBROUTINE-------------------------



tx_main:                  mov sbuf,a
tx_loop:                  jnb TI,tx_loop
                          clr TI
                          ret


;--------------SERIAL RECIEVE SUBROUTINE--------------------------



rx_main:                  clr a
rx_loop:                  jnb ri,rx_loop
                          mov a, sbuf
	                      clr ri
	                      ret

;------------------------------20ms delay----------------------------------

delay_20ms:         push 00
                    push 01
                    mov r0,#36
delay_20ms_loop1:   mov r1,#255
delay_20ms_loop2:   djnz r1,delay_20ms_loop2
                    djnz r0,delay_20ms_loop1 
                    pop 01
                    pop 00
                    ret

;_________________________________________________________________
;-------------------------main code------------------------------
;_________________________________________________________________


ks_main:    mov p1,#0ffh
            mov p1,#0fh                            ;all columns high n rows low
            mov a,p1
	    acall s9k_main
            anl a,#00001111b                      ;consider only columns
            cjne a,#00001111b,ks_main            ;initially check for all keys released
;-------------------------------------------------------------------                      
ks_loop1:   acall delay_20ms
            mov a,p1
            anl a,#00001111b                            ;scan columns
            cjne a,#00001111b,debounce         ;if key pressed, check debounce
            sjmp ks_loop1                       ;if not, keep checking for key pressed
;-------------------------------------------------------------------
debounce:   acall delay_20ms
            mov a,p1
            anl a,#00001111b 
            cjne a,#00001111b,check_row
            sjmp ks_loop1
;--------------------------------------------------------------------
check_row:  clr ROW0
            setb ROW1
            setb ROW2
            setb ROW3
			
	    mov a,p1
            anl a,#00001111b 
            cjne a,#00001111b,row_0
;--------------------------------------------------------------------			
  	    setb ROW0
            clr ROW1
            setb ROW2
            setb ROW3

            mov a,p1
            anl a,#00001111b 
            cjne a,#00001111b,row_1
;---------------------------------------------------------------------
            setb ROW0
            setb ROW1
            clr ROW2
            setb ROW3

            mov a,p1
            anl a,#00001111b
            cjne a,#00001111b,row_2
;--------------------------------------------------------------------- 			
	    setb ROW0
            setb ROW1
            setb ROW2
            clr ROW3

            mov a,p1
            anl a,#00001111b  
            cjne a,#00001111b,row_3
;----------------------------------------------------------------------
            sjmp ks_loop1
;----------------------------------------------------------------------
row_0:      mov dptr,#disp_kcode0
             sjmp find_num

row_1:      mov dptr,#disp_kcode1
             sjmp find_num

row_2:      mov dptr,#disp_kcode2
             sjmp find_num
			
row_3:      mov dptr,#disp_kcode3
             sjmp find_num
;----------------------------------------------------------------------
find_num:   rrc a
            jnc found_num                   ;which column is pressed/grounded
            inc dptr
            sjmp find_num
;----------------------------------------------------------------------
found_num:  clr a
            movc a,@a+dptr
            acall tx_main                   ;send pressed button to serial port
;-----------------------------------------------------------------------
            jmp ks_main
;-----------------------------------------------------------------------
disp_kcode0:     DB      ' 0 ', ' 1 ', ' 2 ', ' 3 '
disp_kcode1:     DB      ' 4 ', ' 5 ', ' 6 ', ' 7 ' 
disp_kcode2:     DB      ' 8 ', ' 9 ', ' A ', ' B ' 
disp_kcode3:     DB      ' C ', ' D ', ' E ', ' F ' 
;-----------------------------------------------------------------------

end                


List of 27 messages in thread
TopicAuthorDate
hex key pad code not working            01/01/70 00:00      
   Explanation            01/01/70 00:00      
   what, how            01/01/70 00:00      
      each line of code must be justified            01/01/70 00:00      
         correction made, still not workin            01/01/70 00:00      
            Lookup table            01/01/70 00:00      
               hyperlink            01/01/70 00:00      
            of course not,            01/01/70 00:00      
      shall I spoil the fun?            01/01/70 00:00      
         code workin partially            01/01/70 00:00      
            be specific            01/01/70 00:00      
               specific            01/01/70 00:00      
                  check it in the simulator            01/01/70 00:00      
            Use serial port for debugging            01/01/70 00:00      
            confidence            01/01/70 00:00      
         I wouldn't do that            01/01/70 00:00      
   problem with find_num subroutine?            01/01/70 00:00      
   Code presentation            01/01/70 00:00      
   sorry it's 'hyper terminal'            01/01/70 00:00      
   Problem solved            01/01/70 00:00      
      which conclusion, please tell            01/01/70 00:00      
      Problem is NOT solved.            01/01/70 00:00      
         Post the solution please            01/01/70 00:00      
            solution            01/01/70 00:00      
               a 'killer solution'            01/01/70 00:00      
                  killer????            01/01/70 00:00      
                     you 'eat' the main            01/01/70 00:00      

Back to Subject List