嵌入式 > 技术百科 > 详情

花样流水灯的设计3(单片机-汇编)

发布时间:2020-10-15 发布时间:
|
;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
;----------------------
;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
        clr        a
        movc       a,@a+dptr
        mov        dpl,a 
        ;----------------------
        clr        a
        movc       a,@a+dptr           ;Get the count of data in table
        mov        r0,a
        inc        dptr
        ;----------------------
Loop:     
        mov        a,button         ;buttion is unable
        cpl        a        
        jz        ExitCycle
        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
        
;-----------------------
Tables:     dw        Table1,Table2,Table3,Table4,0
;-----------------------
Table1:     db        Table2-$-1
        db        11111110b
        db        11111101b
        db        11111011b
        db        11110111b
        db        11101111b
        db        11011111b
        db        10111111b
        db        01111111b
        
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        TableEnd-$-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                      
        
TableEnd:
;-----------------------
main: 
        mov        Ledprt,#11111111B         
        mov        r2,#0
        mov        r3,#01111111b
        mov        SegDisplay,#00H      ;Initiate the SegDisplay
ToNext:
        cjne       r2,#5,ToNext1
        ajmp       Main
ToNext1:
        inc        r2            ;Button Number
        mov        a,r3
        rl        a       
        mov        r3,a
        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,#1           ;Location in the Tables
        mov        r1,a
        mov        a,r3
        cjne       a,button,main
        acall       Cycle    
        ajmp       Main
;-----------------------
        end
;------------------------------------------------------------
 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
用于MAX7456随屏显示器SPI