??? 05/24/04 21:26 Read: times |
#71078 - Eight LEDS & Eight Switches Simplified |
Now as far as i understand the state machine of Mr. Michael Karas is too lengthly and the same can be done in a simplified way in the following way and just liek to take opinion from you people if the following is the right way also or is there any problem in the following code for the same circuit as mentioned by
Mr. Michael Karas on http://www.8052.com/forum/read.phtml?id=47505 looking forward for your comments ORG 00H JMP POWER_UP ORG 0BH JMP TOISR ORG 030H POWER_UP: MOV A,#00H MOV R0,#7FH RAM_CLR: MOV @RO,A DJNZ R0,RAM_CLR ; Clearing the ram MAIN: CALL INIT CALL SWCHK ;SWITCH CHECK CALL LED CALL COUNTER CALL DEC JMP MAIN ;******************************************* INIT: MOV IE,#10000010B ; timer 0 intrepput enabled MOV TMOD,#01H MOV TH0,#4EH MOV TL0,#20H SETB TR0 ; ram location for counter of 5 seconds MOV R0,#47H COUNT: MOV @R0,#FBH DEC R0 CJNE R0,#3FH,COUNT ;Ram location for LEDS which are on port0 MOV R0,#37H MOV A,#01111111B PORT0: MOV @R0,A RR A DEC R0 CJNE R0,#2FH,PORT0 ;Ram location for buttons which are on P1 MOV R0,#2FH MOV A,#10000000B PORT1: MOV @R0,A RR A DEC R0 CJNE R0,#27H,PORT1 MOV R0,#27H MOV R7,P1 RET ;****************************************** SWCHK: MOV A,R7 RLC A MOV R7,A CJNE @R0,#02H,NEXT RET NEXT: JC END MOV A,#01H MOV @R0,A RET END: MOV A,#00H MOV @R0,A RET :*************************************** LED: CJNE @R0,#01H,END1 MOV A,R0 ADD A,#10H MOV R1,A MOV A,@R1 ANL P2,A RET END1: MOV A,R0 ADD A,#08H MOV R1,A MOV A,@R1 ORL P2,A RET ;*************************************************** COUNTER: CJNE @R0,#01,END2 MOV A,R0 ADD A,#20H MOV R1,A MOV A,@R1 DEC A MOV @R1,A RET END2: MOV A,R0 ADD A,#20H MOV R1,A MOV @R1,0FBH RET ;******************************************** DEC: CJNE R0,#20H,DEC1 MOV R0,#27H MOV R7,P1 RET DEC1: DEC R0 RET ;********************************************* TOISR: PUSH A PUSH PSW MOV TH0,#43H MOV TL0,#20H MOV R1,#47H CHK_A: CJNE @R0,#FBH,CHK_B DEC R1 CJNE R1,#3FH,CHK_A POP PSW POP A RETI CHK_B: MOV A,@R1 DJNZ A,CHK_C MOV @R1,#FBH MOV A,R1 CLR C SUBB A,#20H MOV R1,A MOV @R1,#02H MOV A,R1 ADD A,#20H MOV R1,A DEC R1 JMP CHK_A CHK_C: MOV @R1,A DEC R1 JMP CHK_A END ************************************ |
Topic | Author | Date |
Eight LEDS & Eight Switches Simplified | 01/01/70 00:00 | |
RE: Eight LEDS & Eight Switches Simplifi | 01/01/70 00:00 | |
is my code not a state machine | 01/01/70 00:00 | |
something more | 01/01/70 00:00 | |
RE: Eight LEDS & Eight Switches Simplified | 01/01/70 00:00 | |
RE: Eight LEDS & Eight Switches Simplified | 01/01/70 00:00 | |
RE: Eight LEDS & Eight Switches Simplified | 01/01/70 00:00 | |
RE: Eight LEDS & Eight Switches Simplifi | 01/01/70 00:00 | |
thanks | 01/01/70 00:00 | |
RE: thanks![]() | 01/01/70 00:00 |