| ??? 04/19/00 19:18 Read: times |
#2266 - RE: programming a memory game |
Here's how I'd do it. I assume you show 4 randomly selected LEDs in a sequence and then see if they key-in the same sequence via the 4 buttons. When they press I key, I then light the correct LED and then compare their answer for correct or not. Correct answers proceed, a wrong answer aborts and starts a new 4 number sequence.
You can add the delay routines and the two jazzy LED loop subroutines at the botton. If I've done this right (over my lunch) then you should require any explicit button debouncing (the delays and program flow should take care of it.) .;=============== .ledini equ 08003h .ledadr equ 08000h . . org 07000h .init: . mov sp,#40h . mov tmod,#00010001b . mov tcon,#00010000b . mov a,080h . mov dptr,#ledini . movx @dptr,a . acall inidelay . mov a,#0FFh . mov p1,a . mov dptr,#ledadr . movx @dptr,a .play: . jb p1.7,play .nextseq: . call offpause . call seqdelay . mov r7,tl0 ;get 4 random . mov r6,#4 ;sho 4 random .nextrandom: . call offpause . mov a,r7 . rr a . rr a . mov r7,a . anl a,#00000011b . acall show . djnz r6,nextrandom . . mov a,#0FFh . movx @dptr,a . mov r6,#4 .nexttest: . mov a,r7 ;get 4 random . rr a . rr a . mov r7,a . anl a,#00000011b . acall testbutton . jc mistake . djnz r6,nexttest . lcall LEDPASS ;success . ajmp nextseq .mistake: . lcall LEDFAIL ;failure . ajmp nextseq ;play again .;-------; .show: . acall getBIT . movx @dptr,a . acall ondelay ;show bit . ret .;-------; .getBIT: . inc a ;adj past RET . movc a,@pc+a . ret . db 0FEh ;bit 1 . db 0FDh ;bit 2 . db 0FBh ;bit 3 . db 0F7h ;bit 4 .;-------; .testbutton: . acall getBIT . mov r4,a ;save image .wait4key: . mov a,p0 . anl a,#0Fh ;mask p1.4-7 . cjne a,#0Fh,hitkey . ajmp wait4key .hitkey: . xch a,r4 . movx @dptr,a ;show correct . xrl a,r4 ;compare . jnz testfail ;jif wrong . acall relkey ;hold til rel . clr c ;flag success . ret .testfail: . acall relkey ;hold til rel . setb c ;flag mistake . ret .;-------; .relkey: . acall ondelay .heldkey: . mov a,p0 . anl a,#0Fh ;mask p1.4-7 . cjne a,#0Fh,heldkey . mov a,0FFh . movx @dptr,a ;LEDs off . ret .;-------; .offpause: . mov a,#0FFh . movx @dptr,a . acall offdelay . ret .;-------; .ondelay: . ; insert loop code here .using available r0-r3 . ret .offdelay: . ; insert loop code here .using available r0-r3 . ret .delay: . ; insert loop code here .using available r0-r3 . ret .inidelay: . ; insert loop code here .using available r0-r3 . ret .seqdelay: . ; insert loop code here .using available r0-r3 . ret .LEDPASS: . ; insert loop code here .using available r0-r3 . ret .LEDFAIL: . ; insert loop code here .using available r0-r3 . ret .;-------; |
| Topic | Author | Date |
| programming a memory game | 01/01/70 00:00 | |
| RE: programming a memory game | 01/01/70 00:00 | |
| RE: programming a memory game | 01/01/70 00:00 | |
RE: programming a memory game | 01/01/70 00:00 |



