;This program will show you cycle glitter between 8 led lamps
; maker:Chen Weiwu
; date:2012-11-08
; version:1.0.0
;-------------------------------------------------------------
;Define
Ledprt equ p0
SegDisplay equ p2
Button equ p1
ButtonState equ 30h
;----------------------
;Set the initiation address which the program runing
;----------------------
org 0
ajmp main
;-----------------------
Cycle:
mov a,#low(Tables)
add a,r1
mov dpl,a
clr a
addc a,#high(Tables)
mov dph,a
;---------------------- Get Table's Address
clr a
movc a,@a+dptr
mov r1,a
mov a,#1
movc a,@a+dptr
mov dpl,a
mov dph,r1
;----------------------
clr a
movc a,@a+dptr ;Get the count of data in table
mov r0,a
inc dptr
;----------------------
mov ButtonState,button ;Save button
Loop:
mov a,button
cjne a,ButtonState,ExitCycle ;Buttion is change
clr a
movc a,@a+dptr
mov Ledprt,a
acall delay
inc dptr
djnz r0,Loop
ExitCycle:
ret
;-----------------------
;-----------------------
;delay sub
delay: mov r5,#50
delay1: mov r6,#100
DELAY2: mov r7,#10
djnz r7,$
djnz r6,delay2
djnz r5,delay1
ret
;-----------------------
ButtonTable:
;--------ONE BUTTON--------
db 11111110B
DB 11111101B
db 11111011B
DB 11110111B
;--------TWO BUTTON--------
DB 11111100B
db 11111010B
DB 11110110B
DB 11111001B
db 11110101B
DB 11110011B
;-------THREE BUTTON-------
DB 11111000B
DB 11110100B
DB 11110010B
DB 11110001B
;-------FOUR BUTTON-------
DB 11110000B
DB 0
;-----------------------
Tables: dw Table1,Table2,Table3,Table4
dw Table5,Table6,Table7,Table8,Table9,Table10
dw Table11,Table12,Table13,Table14
dw Table15
dw 0
;-----------------------
Table1: db Table2-$-1
db 11101111b
db 11011111b
db 10111111b
db 01111111b
db 11111110b
db 11111101b
db 11111011b
db 11110111b
db 11111011b
db 11111101b
db 11111110b
db 01111111b
db 10111111b
db 11011111b
Table2: db Table3-$-1
db 01111110b
db 10111101b
db 11011011b
db 11100111b
db 11011011b
db 10111101b
Table3: db Table4-$-1
db 01010101b
db 00000000b
db 10101010b
db 00000000b
Table4: db Table5-$-1
db 11111110b
db 11111100b
db 11111000b
db 11110000b
db 11100000b
db 11000000b
db 10000000b
db 00000000b
db 00000001b
db 00000011b
db 00001111b
db 00011111b
db 00111111b
db 01111111b
db 11111111b
Table5: db Table6-$-1
db 00000000b
db 11111111b
Table6: db Table7-$-1
db 00001111b
db 00011110b
db 00111100b
db 01111000b
db 11110000b
db 01111111b
db 00111111b
db 00011111b
Table7: db Table8-$-1
db 00110110b
db 01010110b
db 01100110b
db 01101010b
db 01101100b
db 01101010b
db 01100110b
db 01010110b
Table8: db Table9-$-1
db 01110111b
db 10110111b
db 11010111b
db 11100111b
db 11101011b
db 11101101b
db 11101110b
db 11101101b
db 11101011b
db 11100111b
db 11010111b
db 10110111b
Table9: db Table10-$-1
db 11100111b
db 11000011b
db 10100101b
db 01100110b
Table10: db Table11-$-1
db 01111111b
db 10111111b
db 11011111b
db 11101111b
db 11110111b
db 11111011b
db 11111101b
db 11111110b
db 01111110b
db 10111110b
db 11011110b
db 11101110b
db 11110110b
db 11111010b
db 11111100b
db 01111100b
db 10111100b
db 11011100b
db 11101100b
db 11110100b
db 11111000b
db 01111000b
db 10111000b
db 11011000b
db 11101000b
db 11110000b
db 01110000b
db 10110000b
db 11010000b
db 11100000b
db 01100000b
db 10100000b
db 11000000b
db 01000000b
db 10000000b
db 10000000b
db 10000000b
db 01000000b
db 11000000b
db 10100000b
db 01100000b
db 11100000b
db 11010000b
db 10110000b
db 01110000b
db 11110000b
db 11101000b
db 11011000b
db 10111000b
db 01111000b
db 11111000b
db 11110100b
db 11101100b
db 11011100b
db 10111100b
db 01111100b
db 11111100b
db 11111010b
db 11110110b
db 11101110b
db 11011110b
db 10111110b
db 01111110b
db 11111110b
db 11111101b
db 11111011b
db 11110111b
db 11101111b
db 11011111b
db 10111111b
db 01111111b
db 11111111b
db 11111111b
db 11111111b
db 11111111b
db 11111111b
db 11111111b
db 11111111b
db 11111111b
db 11111111b
db 11111111b
db 11111111b
db 11111111b
Table11: db Table12-$-1
db 11111110b
db 01111111b
db 11111101b
db 10111111b
db 11111011b
db 11011111b
db 11110111b
db 11101111b
db 11110111b
db 11101111b
db 11111011b
db 11011111b
db 11111101b
db 10111111b
Table12: db Table13-$-1
db 00111100b
db 11111111b
db 11100111b
db 11111111b
db 11011011b
db 11011011b
db 11011011b
db 11011011b
Table13: db Table14-$-1
db 01111110b
db 11111111b
db 10111101b
db 11111111b
db 10111101b
db 11111111b
db 11011011b
db 11111111b
db 11011011b
db 11111111b
db 11011011b
db 11111111b
db 11100111b
db 11111111b
db 11100111b
db 11111111b
db 11100111b
db 11111111b
db 11100111b
db 11111111b
db 00000000b
Table14: db Table15-$-1
db 11111110b
db 11111100b
db 11111010b
db 11110100b
db 11101100b
db 11011010b
db 10111010b
db 01110101b
db 01110101b
db 01101101b
db 01101101b
db 01011011b
db 01011011b
db 00111011b
db 00111011b
db 00110111b
db 00110111b
db 00110111b
db 00110111b
db 00101111b
db 00101111b
db 00101111b
db 00101111b
db 00011111b
db 00011111b
db 00011111b
db 00011111b
db 00011111b
db 00011111b
Table15: db TableEnd-$-1
db 01111110b
db 10111110b
db 11011101b
db 11101101b
db 11110011b
db 11101101b
db 11011101b
db 10111110b
TableEnd:
;-----------------------
main:
mov Ledprt,#11111111B
mov r2,#0
mov SegDisplay,#00H ;Initiate the SegDisplay
MOV DPTR,#ButtonTable
ToNext:
inc r2 ;Button Number
CLR A
MOVC A,@A+DPTR
JZ MAIN
INC DPTR
cjne a,button,ToNext ;Check whether the button is enable or not
mov SegDisplay,r2 ;button is enable,Show on the SegDisplay
mov a,r2
rl a
clr c
subb a,#2 ;Location in the Tables
mov r1,a
acall Cycle
ajmp Main
;-----------------------
end
;-------------------------------------------------------------