| ??? 11/09/03 02:53 Read: times |
#58123 - RE: Want to insult us? -100 points! Responding to: ???'s previous message |
i tested my code, it could move data from micro to LCD
now only problem is it could not receive data from keyboard (it does not recognize the pressed switch) for example: this subroutine checked the pressed key and it jump to another subroutine when recognize the correspond pressed key: main: jnb 90h, button1 jnb 91h, button2 jnb 93h, button3 jnb 92h, main button1:...... button2:...... button3:...... but it doesnot recognize the pressed key when i pressed, it jump to button1 subrotine at one when never key was pressed. I change that code to "key state machine" to scan what key was pressed as some example in the net,and used Timer 0 interupt routine to call but it does not work yet. when i tested i found Timer 0 interrupt even does not occur The only problem i still face to are it does not recognize data from key board Moving data from micro to LCD is Ok The code list here:
;btw, just if you are interesting with usage of timer as debounce/control routine, here is an example how to detect buttons` actions. Here eight buttons are connected to port 1 and controled via timer 0.
#include "C:RigelReads51includesfr51.inc"
; variables
T0_TEMP DATA 0x20 ; temporal buffer
T0_STATE DATA 0x21 ; unbounced state of buttons
T0_FLAGS DATA 0x22 ; button action (bit addressable)
BUTTON8 BIT T0_FLAGS.7
BUTTON7 BIT T0_FLAGS.6
BUTTON6 BIT T0_FLAGS.5
BUTTON5 BIT T0_FLAGS.4
BUTTON4 BIT T0_FLAGS.3
BUTTON3 BIT T0_FLAGS.2
BUTTON2 BIT T0_FLAGS.1
BUTTON1 BIT T0_FLAGS.0
; reload value for 50Hz at 11.059Mhz is 11059200/12/50/256 = 72
T0_SCALE EQU (256-72)
;----------------------------------------------------------------
; reset vectors
ORG 00H
LJMP START
ORG 0BH ; timer 0 ISR
LJMP T0_ISR
;----------------------------------------------------------------
; Button control based on Interupt service routine of timer 0
T0_ISR:
MOV TH0,#T0_SCALE ; reload timer divider
PUSH ACC
PUSH PSW
MOV A,P1 ; load current buttons` state
XCH A,T0_TEMP ; keep it
XRL A,T0_TEMP ; compare with previous one
JNZ T0_ISR_END ; state is changed: debounce...
; two read attemps are with the same result - process it
MOV A,T0_TEMP
XCH A,T0_STATE ; hold stable state
XRL A,T0_STATE ; detect changed bits
ANL A,T0_STATE ; detect realised buttons
ORL T0_FLAGS,A ; indicate changed buttons
T0_ISR_END:
POP PSW
POP ACC
RETI
;----------------------------------------------------------------
; main entrance
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
START:
; set timer 0 to 16-bit mode
CLR EA
MOV TCON,#00000000b ; stop timer 0
MOV TMOD,#00000010b ; timer 0 is 16-bit divider
MOV TH0,#T0_SCALE
; prepare initial values
MOV T0_TEMP,P1
MOV T0_STATE,T0_TEMP
MOV T0_FLAGS,#00000000b
; run button control
SETB EA
SETB ET0
;MOV IE,#10000001b ; allow timer 0 interrupt
SETB TR0 ; start timer 0
; main cycle: sleep till event occures
RUN:
MOV PCON,#00000001b ; idle mode
NOP ; some parts require it
LCALL BUTTON1_PROCESS
LCALL BUTTON2_PROCESS
LCALL BUTTON3_PROCESS
LCALL BUTTON4_PROCESS
; the rest calls...
SJMP RUN
BUTTON1_PROCESS:
JNB BUTTON1,BUTTON1_END
; button 1 was pressed and realised: process it here
CLR BUTTON1
BUTTON1_END:
RET
BUTTON2_PROCESS:
JNB BUTTON2,BUTTON2_END
; button 2 was pressed and realised: process it here
CLR BUTTON2
BUTTON2_END:
RET
; the rest buttons` subroutines
BUTTON3_PROCESS:
JNB BUTTON3,BUTTON3_END
; button 2 was pressed and realised: process it here
CLR BUTTON3
BUTTON3_END:
RET
BUTTON4_PROCESS:
JNB BUTTON4,BUTTON4_END
; button 2 was pressed and realised: process it here
CLR BUTTON4
BUTTON4_END:
RET
END
|
| Topic | Author | Date |
| Timer 0 interrupt problem ? | 01/01/70 00:00 | |
| RE: Timer 0 interrupt problem ? | 01/01/70 00:00 | |
| Want to insult us? -100 points! | 01/01/70 00:00 | |
| RE: Want to insult us? -100 points! | 01/01/70 00:00 | |
| RE: Want to insult us? -100 points! | 01/01/70 00:00 | |
| RE: Want to insult us? -100 points! | 01/01/70 00:00 | |
| RE: Want to insult us? -100 points! | 01/01/70 00:00 | |
RE: Want to insult us? -100 points! | 01/01/70 00:00 | |
| RE: Timer 0 interrupt problem ? | 01/01/70 00:00 |



