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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/25/07 08:33
Read: times


 
#144960 - ISR Keyboard
I use the AR89C51RB2 and i want to use its keyboard interrupt funktinallity. I have 3 keys on Port1 pins:7,6,5. I connected the pins with pull up resistor 10K and i grounded the pin with each key press. The pin5 is for addition the pin7 for subtraction.
I see that the subtraction funktion(key press) has faster respond than the adition. The addition key has no result -scarsly. Maybe you could help me. Thanks you for every help.
My code is following


KBE EQU 9Dh
KBLS EQU 9Ch
KBF EQU 9Eh
IEN0 EQU 0A8h
IEN1 EQU 0B1h

MAXTH EQU 37h ;maximum temperature seted
MINTH EQU 1Eh ;minimum "

LCD DATA P2 ;define LCD data port on port 1
BUSY BIT LCD.7 ;define LCD busy flag
;*************************************************************
DATA_SEG SEGMENT DATA
MAIN_SEG SEGMENT CODE
BITS_SEG SEGMENT BIT

RSEG DATA_SEG
Temp: DS 1
BitCnt: DS 1
Thermk: DS 1

RSEG BITS_SEG
FLAG1: DBIT 1
Buncb_7: DBIT 1
Buncb_6: DBIT 1
;***************************************************
; INTERRUPT VECTOR DEFINITIONS
;---------------------------------------------------

CSEG AT 0000H ; reset vector
JMP POWER_UP ; power-on entry point

CSEG AT 0003H ; intr 0 vector
RETI ; not used

CSEG AT 000BH ; timer 0 vector
RETI ; not used

CSEG AT 0013H ; intr 1 vector
CLR EX1 ; external int 1
RETI ; not used

CSEG AT 001BH ; timer 1 vector
RETI ; NOT used

CSEG AT 003BH ; Kyeboard vector
JMP SCANK ; used
;***************************************************
; MAIN PROGRAM INITIALIZATION
;---------------------------------------------------
RSEG MAIN_SEG
USING 0 ; use register block 0

POWER_UP:
MOV SP,#7Fh ; set stack pointer

CALL Keyb_Init
mov Temp,#3Ch ;a number which i make some
MOV IEN0,#80h ;EA=1 and ET1=1
MOV IEN1,#01h ;KBD=1 Keyboard enable bit

AgainSc:
MOV A,KBF
ANL A,#0A0h
JZ Nokey
MOV IEN1,#00h ;disable key inderrupt
MOV A,#03h ;start delay
ly3: DEC A
JNZ ly3
MOV A,#0FFh
ly4: DEC A
JNZ ly4 ;end delay
CLR A
MOV KBF,A ;enable detection
MOV IEN1,#01h
Nokey: JMP AgainSc
;*****************************************************************************
Keyb_Init:
MOV KBE,#0E0h;enable interrupt of the last 3 bits
MOV KBLS,#00h;enable bit only by low level (zero)
MOV KBF,#00h
RET
;===============================================================
;ISR routine for scanning and showing on the dispaly the user ;preferences and the
;actual temperature
;===============================================================
SCANK:

DISPLAY:push acc
MOV A,#80h
CALL COMMAND ;where to be schowed
MOV DPTR,#TEST
ACALL DISP_STRING
MOV A,#85h
CALL COMMAND

CALL Show
MOV A,#0C1h
CALL COMMAND
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;the following assemby code is for subtraction of the stored number
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MOV A,KBF ;check which key used ,only the key Number 5
ANL A,#20h
JZ Next_Key

MOV A,Temp
CJNE A,#MINTH,KNex1 ;no smaller than the MINTH
KNex1: JC KExod

CLR C
SUBB A,#01 ;decriment 1
MOV Temp,A
CALL Hex_to_Dec ;reform the data to decimal
CALL Show
KExod:
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;the following assemby code is for addition the stored number
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Next_Key:

MOV A,KBF ;only the key Number 7
ANL A,#80h
JZ Out

MOV A,Temp
CJNE A,#MAXTH,Nex1 ;value no biger than the MAXTH
Nex1: JNC Out

CLR C
ADDC A,#01 ;increment 1
MOV Temp,A
CALL Hex_to_Dec ;reform the data to decimal
CALL Show
Out: POP acc
RETI

END

...replace this with your code...


List of 6 messages in thread
TopicAuthorDate
ISR Keyboard            01/01/70 00:00      
   How to use the 'Insert Code' button            01/01/70 00:00      
      much better view            01/01/70 00:00      
         Debouncing            01/01/70 00:00      
   Debouncing etc is far easier handled            01/01/70 00:00      
   see the FAQ            01/01/70 00:00      

Back to Subject List