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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/21/06 04:34
Read: times


 
#118674 - have look again to the code ...
Responding to: ???'s previous message
Hello ...

The problem I am encountering is

As soon as the development board is powered ON, all LEDs are ON.
If switch 1 is pressed, LED1 goes OFF and remaining 7 LEDs remains ON
If any other switch is pressed, nothing happens, untill unless the switch 1 is pressed again and all 8 LEDs are ON.

In short, you can only Switch ON one LED only, if you
want to switch On other LEDs you can not.

I wanted to do is something different ... WHEN A SWITCH IS PRESSED LED IS ON AND ON THE SECOND HIT OF THE SAME SWITCH THE LED IS OFF ...

;***************************************************************

DELAY_HIGH EQU 003H
DELAY_LOW EQU 018H
FLAG_FIRST EQU 031H
FLAG_SECOND EQU 032H
FLAG_INVALIDKEY EQU 033H
FLAG_ALTER EQU 034H
NEWKEY EQU 034H

ORG 000H
MOV SP,#050H
SJMP START

ORG 001BH
INTERRUPT_1:
PUSH ACC
PUSH PSW
CLR TR1
MOV PSW,#00H
ACALL KEYPRESSED
JNZ CALCULATE
JB FLAG_SECOND,HALT1
; if no key is pressed and earlier the key were presed taking into
JB FLAG_FIRST,COOL ;account the 1st & 2nd press, then jump to HALT1 and only once key
JMP AGAIN ;is pressed then jump to COOL or jump to AGAIN

CALCULATE:
ACALL KEYPRESSED
; again check whether any key is pressed or not
JZ HALT ;if no key is pressed then jump to halt for checking the key is pressed ;before or not by cheking the flag ... FLAG_FIRST
ACALL CONVERT ;check the validity of the key pressed
JBC FLAG_INVALIDKEY,HALT; if the key pressed is invalid then jump to HALT
INC R0 ;increment R0 fro checking whether the key is pressed first time or not
CJNE R0,#01,COMPARE ;if the key is not pressed for the first time then jump to COMPARE
MOV NEWKEY,A ;here it shows the key is pressed for the first time and so the fresh key ;is taken to a new flag named NEWKEY for further checking on ;second time key hit
SETB FLAG_FIRST ;set this flag which shows the key is pressed 1st time, this flag is used ;while the checking the in the subroutine HALT
JMP OUTPUT ; jump to output the 1st time keypressed

COMPARE:
CJNE A,NEWKEY,HALT
;if the key is kept pressed or the second time is pressed is not the ;same key then jump to HALT
JB FLAG_ALTER,RUN ;If after the 1st time key pressed is released then FLAG_ALTER is set ;and checked here whether the condition is true or not
JMP OUTPUT ;jump to output for the 1st time key pressed
RUN:
SETB FLAG_SECOND
;this flag indicated that the key is pressed 2nd time
JMP OFF ;so jump to OFF


OUTPUT:
MOV P2,A
;output the value of A to the LED's
JMP AGAIN ;jump to AGAIN subroutien
OFF:
MOV P2,#00H
;make the LED off
JMP AGAIN ;jump to AGAIN

COOL:
SETB FLAG_ALTER
;if there is no key is pressed but a key is pressed for the 1st time before
MOV P2,NEWKEY ;then FLAG_ALTEr shows that the key next that will be pressed is ;being pressed second time and so the FLAG_SECOND flag should be ;set accordingly ahead in the program
JMP AGAIN

HALT:
JB FLAG_FIRST,AGAIN
;this flag shows that previously a key is pressed for the 1st time so the ;previuos conditions should be preserved otherwise the a fresh ;counting is taken into account
HALT1:
CLR FLAG_FIRST
;all the flags are cleared for a new key to be pressed

CLR FLAG_SECOND
CLR FLAG_ALTER
CLR NEWKEY
MOV P2,#00H
MOV R0,#00
AGAIN:
ACALL TIMER_1
POP PSW
POP ACC
RETI

KEYPRESSED:
MOV A,P1
CPL A
RET

START:
MOV IE,#088H
MOV TMOD,#010H
MOV P1,#0FFH
MOV P2,#00H
MOV R0,#00H
MOV R7,#00H
CLR FLAG_FIRST
CLR FLAG_SECOND
ACALL TIMER_1

KEY:
INC R7
JMP KEY

TIMER_1:
MOV TL1,#DELAY_LOW
MOV TH1,#DELAY_HIGH
SETB TR1
RET

CONVERT:
CLR FLAG_INVALIDKEY

CJNE A,#01H,SECOND
RET
SECOND:
CJNE A,#02H,THIRD
RET
THIRD:
CJNE A,#04H,FOURTH
RET

FOURTH:
CJNE A,#08H,FIVE
RET
FIVE:
CJNE A,#010H,SIX
RET
SIX:
CJNE A,#020H,SEVEN
RET
SEVEN:
CJNE A,#040H,EIGHT
RET
EIGHT:
CJNE A,#080H,BAD
RET
BAD:
SETB FLAG_INVALIDKEY
RET

END

;***************************************************************

regards
Arvind Shrivastava ...

List of 10 messages in thread
TopicAuthorDate
Program not working ...            01/01/70 00:00      
   Okay            01/01/70 00:00      
      and what happens when tested            01/01/70 00:00      
      How to post code            01/01/70 00:00      
   LED problem            01/01/70 00:00      
      Debugging            01/01/70 00:00      
         flickering            01/01/70 00:00      
   have look again to the code ...            01/01/70 00:00      
      Code is still unreadable            01/01/70 00:00      
      at least you tried            01/01/70 00:00      

Back to Subject List