??? 06/20/06 04:02 Read: times Msg Score: -1 -1 Non-Specific question |
#118570 - Program not working ... |
Hello All,
I have written a program which has the functunality that when a switch is pressed one LED becomes ON and remains on ... and when the same switch is again pressed the same LED gets OFF ... The program is not working properly ... could any one help me out where the progarm is lacking ... DELAY is 65 MS ... timer 1 ;*************************************************************** 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 ;*************************************************************** Arvind Shrivastava ... |
Topic | Author | Date |
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 |