GAME.asm
;---; Program LCD & Keypad
; dibuat menjadi aplikasi
; GAME PAC-MAN ; TOMMY AGUSTIANTO ; M. AZHAR BACHTIAR ; TEKNIK ELEKTRO 5A ; ; ORG 0000h main mov R7,#FFh a1 djnz R7,a1 mov sp,#2Fh ;port1 = untuk kondisi LCD clr p1.0 clr p1.1 clr p1.2 lcall init_lcd mov a,#0Fh lcall wrinst ;---;Program Utama tampil_lcd: lcall clr lcall curon clr P3.7 lcall dly_1s setb p3.7 lcall dly_1s mov dptr,#menu1 mov R2,#18 lcall wrdata1 lcall line2 mov dptr,#menu2 mov R2,#18 lcall wrdata2 lcall dly_1s lcall dly_1s mov r7,#5 tamp_count lcall curoff lcall line1 mov dptr,#menu3 mov R2,#19 lcall wrdata2 lcall curoff lcall line2
GAME.asm mov dptr,#menu4 mov R2,#19 lcall wrdata2 lcall curoff lcall line3 mov dptr,#menu5 mov R2,#19 lcall wrdata2 lcall curoff lcall line4 mov dptr,#menu6 mov R2,#19 lcall wrdata2 lcall dly_1s lcall dly_1s lcall line1 lcall clr lcall line2 lcall clr lcall line3 lcall clr lcall line4 lcall clr lcall dly_1s lcall dly_1s djnz r7,tamp_count
res: lcall line1
lcall clr lcall line2 lcall clr lcall line3 lcall clr lcall line4 lcall clr lcall dly_1s lcall dly_1s lcall curoff lcall line1 mov dptr,#splash mov r2,#20 lcall wrdata2 lcall dly_1s lcall dly_1s lcall curoff lcall line3 mov dptr,#splash2 mov r2,#20 lcall wrdata2 lcall dly_1s lcall dly_1s
res2: lcall line1
lcall clr lcall line2
GAME.asm lcall clr lcall line3 lcall clr lcall line4 lcall clr lcall dly_1s lcall curoff lcall line1 mov dptr,#menu7 mov r2,#20 lcall wrdata2 lcall curoff lcall line2 mov dptr,#menu8 mov r2,#20 lcall wrdata2 lcall curoff lcall line3 mov dptr,#menu9 mov r2,#20 lcall wrdata2 lcall curoff lcall line4 mov dptr,#menux mov r2,#20 lcall wrdata2 balixx: lcall dly_1s
lcall dly_1s lcall dly_1s
balix: lcall line1
lcall clr lcall line2 lcall clr lcall line3 lcall clr lcall line4 lcall clr lcall dly_1s
menuu: lcall curoff
lcall line1 mov dptr,#anim1 mov r2,#20 lcall wrdata2 lcall line2 mov dptr,#anim2 mov r2,#20 lcall wrdata2 lcall line3 mov dptr,#anim3 mov r2,#20 lcall wrdata2 lcall line4
GAME.asm mov dptr,#anim4
mov r2,#20 lcall wrdata2 masukan: lcall keypad
mov r0,7fh cjne r0,#31h,dua lcall mainn
dua: cjne r0,#32h,tiga
lcall aturanmain tiga: cjne r0,#33h,masukan
lcall about
mainn: lcall line1
lcall clr lcall line2 lcall clr lcall line3 lcall clr lcall line4 lcall clr lcall line1 mov dptr,#loading mov r2,#20 lcall wrdata2 lcall line3 mov dptr,#loading1 mov r2,#20 lcall wrdata3 lcall dly_1s lcall line1 lcall clr lcall line2 lcall clr lcall line3 lcall clr lcall line4 lcall clr lcall line1 mov dptr,#soal1 mov 5fh,#30h mov r2,#20 lcall wrdata2 lcall line4 mov dptr,#okeh mov r2,#20 lcall wrdata2 lcall line2 mov dptr,#jawab mov r2,#15 lcall wrdata2 lcall keypad mov r0,7fh mov a,r0 lcall wrchr lcall dly_1s cjne r0,#31h,kalah1 ljmp soalb kalah1 ljmp kalah
GAME.asm soalb lcall clr lcall line1 mov dptr,#soal2 mov 5fh,#32h mov r2,#20 lcall wrdata2 lcall line4 mov dptr,#okeh mov r2,#20 lcall wrdata2 lcall line2 mov dptr,#jawab mov r2,#15 lcall wrdata2 lcall keypad mov r0,7fh mov a,r0 lcall wrchr lcall dly_1s cjne r0,#37h,kalah2 ljmp soalc kalah2 ljmp kalah soalc lcall clr lcall line1 mov dptr,#soal3 mov 5fh,#34h mov r2,#20 lcall wrdata2 lcall line4 mov dptr,#okeh mov r2,#20 lcall wrdata2 lcall line2 mov dptr,#jawab mov r2,#15 lcall wrdata2 lcall keypad mov r0,7fh mov a,r0 lcall wrchr lcall dly_1s cjne r0,#37h,kalah3 ljmp soald kalah3 ljmp kalah soald lcall clr lcall line1 mov dptr,#soal4 mov 5fh,#36h mov r2,#20 lcall wrdata2 lcall line4 mov dptr,#okeh mov r2,#20 lcall wrdata2 lcall line2 mov dptr,#jawab mov r2,#15 lcall wrdata2 lcall keypad
GAME.asm mov r0,7fh mov a,r0 lcall wrchr lcall dly_1s cjne r0,#32h,kalah4 ljmp soale kalah4 ljmp kalah soale lcall clr lcall line1 mov dptr,#soal5 mov 5fh,#38h mov r2,#20 lcall wrdata2 lcall line4 mov dptr,#okeh mov r2,#20 lcall wrdata2 lcall line2 mov dptr,#jawab mov r2,#15 lcall wrdata2 lcall keypad mov r0,7fh mov a,r0 lcall wrchr lcall dly_1s cjne r0,#32h,kalah ljmp menang
kalah: lcall line1
lcall clr lcall line2 lcall clr lcall line3 lcall clr lcall line4 lcall clr lcall line1 mov dptr,#kalahx mov r2,#20 lcall wrdata2 lcall line4 mov dptr,#backk mov r2,#20 lcall wrdata2 lcall line3 mov dptr,#skor mov r2,#15 lcall wrdata2 mov r4,5Fh lcall ascii kalahh: lcall keypad
mov r0,7fh
cjne r0,#2ah,kalahh ljmp res
GAME.asm
menang: lcall line1 lcall clr lcall line2 lcall clr lcall line3 lcall clr lcall line4 lcall clr mov dptr,#menangx mov r2,#20 lcall wrdata2 lcall line4 mov dptr,#backk mov r2,#20 lcall wrdata2 lcall line3 mov dptr,#skor mov r2,#15 lcall wrdata2 mov r4,5Fh lcall ascii menangg: lcall keypad
mov r0,7fh
cjne r0,#2ah,menangg ljmp res2
lcall balixx
about: lcall dly_1s
lcall line1 lcall clr lcall line2 lcall clr lcall line3 lcall clr lcall line4 lcall clr
but: lcall line1
mov dptr,#but1 mov r2,#20 lcall wrdata2 lcall line2 mov dptr,#but2 mov r2,#20 lcall wrdata2 lcall line3 mov dptr,#but3 mov r2,#20 lcall wrdata2 lcall line4 mov dptr,#but4 mov r2,#20 lcall wrdata2 lcall keypad
GAME.asm mov r0,7fh
cjne r0,#2ah,but ljmp menuu
aturanmain: lcall dly_1s lcall line1 lcall clr lcall line2 lcall clr lcall line3 lcall clr lcall line4 lcall clr lcall line1
me: mov dptr,#atur1
mov r2,#20 lcall wrdata2 lcall line2 mov dptr,#atur2 mov r2,#20 lcall wrdata2 lcall line3 mov dptr,#atur3 mov r2,#20 lcall wrdata2 lcall line4 mov dptr,#atur4 mov r2,#20 lcall wrdata2 lcall keypad mov r0,7fh cjne r0,#2ah,me ljmp balix ;=================================================================================
; Program Baca Keypad
; Hasil di alamat 7fh = ascii
; 7eh = bcd ; interrupt service 0 ; INPUT ; C0 = p2.6 ; C1 = p2.5 ; C3 = p2.4 ; OUTPUT ; R0 = p2.3 ; R1 = p2.2 ; R2 = p2.1 ; R3 = p2.0 ;==================================================================================
keypad: push e0h
push d0h key setb p2.0 setb p2.1 setb p2.2 setb p2.3 setb p2.4 setb p2.5 setb p2.6
GAME.asm clr p2.3 jb p2.4,Key02 ;pad3 mov 7fh,#33h mov 7eh,#03h ljmp bounc0
Key02 jb p2.5,Key01 ;pad2
mov 7fh,#32h mov 7eh,#02h
ljmp bounc0
Key01 jb p2.6,Key06 ;pad1
mov 7fh,#31h mov 7eh,#01h
ljmp bounc0
Key06 setb p2.3 ;pad6
clr p2.2
jb p2.4,Key05 mov 7fh,#36h mov 7eh,#06h
ljmp bounc0
Key05 jb p2.5,Key04 ;pad5
mov 7fh,#35h mov 7eh,#05h
ljmp bounc0
Key04 jb p2.6,Key09 ;pad4
mov 7fh,#34h mov 7eh,#04h sjmp bounc0 Key09 setb p2.2 clr p2.1 jb p2.4,Key08 ;pad9 mov 7fh,#39h mov 7eh,#09h sjmp bounc0
Key08 jb p2.5,Key07 ;pad8
mov 7fh,#38h mov 7eh,#08h
sjmp bounc0
Key07 jb p2.6,Keypgr ;pad7
mov 7fh,#37h mov 7eh,#07h sjmp bounc0 Keypgr setb p2.1 clr p2.0 jb p2.4,Key0 ;pad# mov 7fh,#23h mov 7eh,#0bh sjmp bounc0
Key0 jb p2.5,Keybin ;pad0
mov 7fh,#30h mov 7eh,#00h sjmp bounc0 Keybin jb p2.6,sls0 ;pad* mov 7fh,#2ah mov 5eh,#0ah sjmp bounc0 sls0 ljmp key
GAME.asm ;=========================================================================== ; Anti Bounching ;=========================================================================== bounc0 push 07h boun0 mov r7,#ffh mov a,p2 orl a,#10001111b
dlyk0 cjne a,#ffh,boun0
lcall dly_100us lcall dly_100us lcall dly_100us djnz r7,dlyk0 pop 07h pop d0h pop e0h clr p2.0 clr p2.1 clr p2.2 clr p2.3 ;setb ie.0 ret ; ;---; SUB - 1
; Subprogram konversi hexa ke ASCII ; R4 = sumber
; hasil ditampilkan di lcd ; tumpukan sp = 1 push
; = 1 lcall wrchr
;---ascii: push E0h
push D0h mov a,r4 anl a,#0fh orl a,#30h lcall wrchr pop D0h pop E0h ret ;---; SUB - 2 ; Subprogram LCD ; inisialisasi LCD
; display ON, cursor on-blink ; DDRAM clear alla display
; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; - - - --; 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F ; ; C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF ;---init_lcd: mov a,#00110000b lcall dly_10ms lcall dly_10ms
GAME.asm lcall wrinst lcall dly_10ms lcall wrinst lcall dly_1ms lcall wrinst mov a,#00111000b lcall wrinst mov a,#00001000b lcall wrinst mov a,#00000001b lcall wrinst mov a,#00000110b lcall wrinst ret ;---; Pengaturan cursor dan tampilan
;---clr: push E0h mov a,#01h lcall wrinst pop E0h ret
modset1: push E0h mov a,#20h lcall wrinst pop E0h ret
modset2: push E0h mov a,#30h lcall wrinst pop E0h ret
dspmov_l: push E0h mov a,#18h lcall wrinst pop E0h ret
dspmov_r: push E0h mov a,#1Ch lcall wrinst pop E0h ret
curoff: push E0h mov a,#0Ch lcall wrinst pop E0h ret
GAME.asm curon: push E0h
mov a,#0Dh lcall wrinst pop E0h ret
curhome: push E0h mov a,#03h lcall wrinst pop E0h ret
modecur_1: push E0h mov a,#07h lcall wrinst pop E0h ret
modecur_2: push E0h mov a,#04h lcall wrinst pop E0h ret
;---; Pengaturan line display
; line1 = 80h ; line2 = C0h
;---line1: push E0h
mov a,#80h lcall wrinst pop E0h ret
line2: push E0h mov a,#C0h lcall wrinst pop E0h ret
line3: push E0h mov a,#94h lcall wrinst pop E0h ret
line4: push E0h mov a,#D4h lcall wrinst pop E0h ret
; linex: mov a,#xxh ; lcall wrinst ; ret
;---; Write Instruction ke LCD
GAME.asm ; RS = 0
; r/w = 0
; reg.a = data kode format
;---wrinst: lcall busy
mov p0,E0h setb p1.2 clr p1.2 ret
;---; Penulisan tampilan data paket
; write data ke DDRAM ; RS = 1
; r/w = 0
; dptr = alamat data paket ; R2 = counter karakter
;---wrdata1: push E0h
push D0h wr1 lcall busy clr a movc a,@a+dptr mov p0,E0h setb p1.0 setb p1.2 clr p1.2 clr p1.0 inc dptr lcall dly_1s djnz R2,wr1 pop D0h pop E0h ret ;---; Tanpa delay ;---wrdata2: push E0h
push D0h wr2 lcall busy clr a movc a,@a+dptr mov p0,E0h setb p1.0 setb p1.2 clr p1.2 clr p1.0 inc dptr djnz R2,wr2 pop D0h pop E0h ret ;---; Tanpa delay ;---wrdata3: push E0h
push D0h wr3 lcall busy
GAME.asm clr a movc a,@a+dptr mov p0,E0h setb p1.0 setb p1.2 clr p1.2 clr p1.0 inc dptr lcall dly_100ms djnz R2,wr3 pop D0h pop E0h ret ;---; Untuk message 16 karakter
;---wrdatam: push E0h
push D0h mov R2,#16 wrm lcall busy clr a movc a,@a+dptr mov p0,E0h setb p1.0 setb p1.2 clr p1.2 clr p1.0 inc dptr djnz R2,wrm pop D0h pop E0h ret ;---; Penulisan tampilan data 1 karakter
; write data ke DDRAM ; RS = 1 ; r/w = 0 ; a = data karakter ;---wrchr: lcall busy mov p0,E0h setb p1.0 setb p1.2 clr p1.2 clr p1.0 ret ;---; BUSY LCD
; Cek bit 7 port 1 atau p1.7 ; p1.7 = 1 busy
; p1.7 = 0 ready
;---busy: push E0h
mov p0,#FFh bsy1 clr p1.0 setb p1.1
GAME.asm setb p1.2 jb p0.7,bsy1 clr p1.2 clr p1.1 pop E0h ret ;---; Delay ; 10 us, 100 us, 1 ms, 10 ms, 100 ms, 1 s ; Reg. R7 ;---dly_10us: nop nop nop nop nop nop ret dly_100us: push D0h push 07h mov R7,#43 dl1 djnz R7,dl1 pop 07h pop D0h ret dly_1ms: push D0h push 07h mov R7,#70 dl2 lcall dly_10us djnz R7,dl2 pop 07h pop D0h push 07h pop 07h nop nop ret dly_10ms: push D0h push 07h mov R7,#96 dl3 lcall dly_100us djnz R7,dl3 pop 07h pop D0h nop nop ret dly_100ms: push D0h push 07h mov R7,#99 dl4 lcall dly_1ms djnz R7,dl4 mov R7,#42 dl4a lcall dly_10us
GAME.asm djnz R7,dl4a pop 07h pop D0h ret dly_1s: push D0h push 07h mov R7,#249 dl5 lcall dly_1ms djnz R7,dl5 mov R7,#249 dl5a lcall dly_1ms djnz R7,dl5a mov R7,#249 dl5b lcall dly_1ms djnz R7,dl5b mov R7,#249 dl5c lcall dly_1ms djnz R7,dl5c push 07h pop 07h pop 07h pop D0h ret ;---; Tabel operasi pseudo
;---menu1 db ' TOMMY & M.AZHAR '
menu2 db ' TE 5A ' menu3 db ' ÛÛÛÛ Û Û ÛÛÛ ' menu4 db ' Û Û ÛÛ Û Û ' menu5 db ' ÛÛÛÛ Û Û Û Û Û ' menu6 db ' Û Û ÛÛ ÛÛÛÛ ' menu7 db 'ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ' menu8 db 'Û GAME Û' menu9 db 'Û Ayo-Ngitung Û' menux db 'ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ' splash db ' PNJ Robotics Team ' splash2 db ' Proudly Present ' anim1 db ' 1ÛMulai Game ' anim2 db ' 2ÛAturan Main ' anim3 db ' 3ÛTentang ku ' anim4 db 'silahkan pilih menu ' atur1 db '=ayo belajar hitung=' atur2 db ' gunakan keypad 3x4 ' atur3 db ' untuk jawab soal ' atur4 db '=tekan * untuk back=' but1 db ':Project MiCon 2009:' but2 db 'TOMMY && AZHAR EC5A ' but3 db 'ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ' but4 db '=tekan * untuk back=' loading db '====Game Loading====' loading1 db 'ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ'
soal1 db 'a.1+1-1x1/1 adalah ='
soal2 db 'b.2+1-2+1+5 adalah ='
soal3 db 'c.3/2x4+2-1 adalah ='
GAME.asm
soal5 db 'e.1-5+6-1+1 adalah ='
waktu db ' waktu kamu: '
kalahx db '=====KAMU KALAH====='
skor db ' skor kamu: '
menangx db '====KAMU MENANG====='
backk db '=tekan * untuk back='
jawab db 'jawaban kamu = '
okeh db ' Ayo Kamu Bisa!! '