打印

LED烟花灯简化版汇编程序

[复制链接]
1893|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
优动的LED|  楼主 | 2008-7-23 22:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/* 龙图开发网: http://www.longtoo.com  */
;*****************************************
;    78p153寄存器定义
;*****************************************
    R0     ==    0X0    ;间接寻址IAR
;****CONT REGISTE*************
;    7    6    5    4    3    2    1    0
;    -   INT   TS   TE  PAB  PSR2 PSR1 PSR2
;    PSR    TCC RATE    WDT RATE
;    000    1:2            1:1
;    001    1:4            1:2
;    010    1:8            1:4
;    011    1:16           1:8
;    100    1:32           1:16
;    101    1:64           1:32
;    110    1:128          1:64
;    111    1:256          1:128
;---------------------------------
;    PAB    0:TCC    1:WDT
;    TE    TCC信号边沿选择位。0:由高到低加1。    1:由低到高加1
;    TS    TCC信号源    0:内部时钟。   1:外部输入(P62/TCC)
;    INT    中断使能标志    0:由DISI或硬件中断屏蔽,1:由ENI/RETL使能中断。
    TCC    ==    0X1
    PC     ==    0X2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    STATUS ==    0X3
        C      ==    0
        DC     ==    1
        Z      ==    2
        P      ==    3    ;执行SLEP时置为0
        T      ==    4    ;时间溢出时置为0
        GP0    ==    5    ;
        GP1    ==    6    ;
        RST    ==    7    ;复位类型,由引脚唤醒时置1,其它复位置0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    R4     ==    0X4
    
    PORT5  ==    0X5
    IOC5   ==    0X5
    PORT6  ==    0X6
    
    
    IOC6   ==    0X6
    
    
/* 龙图开发网: http://www.longtoo.com  */    
    
    
    IOCB    ==    0X0B    ;将P50,P51,P52, P60,P61,P62下拉
    IOCC    ==    0X0C    ;将P60,P61,P62,   P64,P65,P66,P67漏极开路
    IOCD    ==    0X0D    ;将P60,P61,P62,   P64,P65,P66,P67上拉
    ;0:    为允许使能。    1:为禁止
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    
    IOCE    ==    0X0E    ;WDT控制器
        WDTE    ==    7    ;0:禁止,1:允许
        EIS    ==    6    ;0:P60,双向I/O口,1:外部中断管脚。此时IOC6的BIT0置为1(输入)
                            ;为“0”时,/通道被屏蔽。INT为“1”时,可通由P6口读取其状态
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ISR    ==    0XF    ;中断状态寄存器
    
        TCIF   ==    0    ;TCC溢出时置1,软件清0
        ICIF   ==    1    ;P6口输入变化置1,软件清0
        EXIF   ==    2    ;外部中断,由P60/INT下降沿置1,软件清0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    IOCF    ==    0XF    ;中断屏蔽寄存器
    
        TCIE    ==    1    ;0:为中断禁止。1为中断允许
        ICIE    ==    2    ;
        EXIE    ==    3    ;
        
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    count1    ==    0x12
    count2    ==    0x13
    count3    ==    0x14
    temp    ==    0x15
    chtbl    ==    0x16
    time    ==    0x17
    cord1    ==    0x18
    cord2    ==    0x19
    cord3    ==    0x1a
    chtb2    ==    0x1b
    cord4    ==    0x1c
    wmode    ==    0x1f
    next    ==    0x11
    
    
    
    org    0x0
    jmp    start
    
tbl0:
    add    pc,a            ;这是没有渐变的
    retl    0b00000000
    retl    0b01100000    
    
    retl    0b01110000
    retl    0b10110001
    retl    0b10110011
    retl    0b10110111
    retl    0b11111111
    retl    0b01001111
    retl    0b00111110
    retl    0b00101100
    retl    0b00011000        ;6
    
    retl    0b10110000
    retl    0b00110001
    retl    0b00110010
    retl    0b00100100
    retl    0b00101000        ;5
    
    retl    0b10110000
    retl    0b00110001
    retl    0b00110010
    retl    0b00100100
    retl    0b00101000        ;5
    
    retl    0b10110000
    retl    0b00110001
    retl    0b00110010
    retl    0b00100100
    retl    0b00101000        ;5
    
    retl    0b10110000
    retl    0b00110001
    retl    0b00100010
    retl    0b00010100
    retl    0b00011000        ;5
    
    retl    0b10110000
    retl    0b00110001
    retl    0b00110010
    retl    0b00100100
    retl    0b00101000    ;5
    

    
    
    retl    0b01000000
    retl    0b01100000
    retl    0b11010000
    retl    0b01000001
    retl    0b00110010
    retl    0b00100100
    retl    0b00011000
    retl    0b10110000
    retl    0b00110001
    retl    0b00110010
    retl    0b00100100
    retl    0b00101000
    retl    0b10110000
    retl    0b00110001
    retl    0b00110010
    retl    0b00100100
    retl    0b00101000    ;17,2
    
    
    retl    0b01100000
    retl    0b11010000
    retl    0b11000001
    retl    0b10110011
    retl    0b10110111
    retl    0b00101111
    retl    0b00101110
    retl    0b00011100
    retl    0b00011000    ;9,1
    
    retl    0b01000000
    retl    0b01110000
    retl    0b11010000
    retl    0b01000001
    retl    0b00110010
    retl    0b00100100
    retl    0b00011000
    retl    0b10110000
    retl    0b00110001
    retl    0b00110010
    retl    0b00100100
    retl    0b00101000    ;12,2
    
    retl    0b01100000
    retl    0b11010000
    retl    0b11000001
    retl    0b10110011
    retl    0b10110111
    retl    0b00101111
    retl    0b00101110
    retl    0b00011100
    retl    0b00011000    ;9,1
    

    
tbl11:
    add    pc,a
    retl    0b00000000        ;流星划过,全过程梦幻
    retl    0b00000000
    retl    0b00000000
    
    retl    0b00110000
    retl    0b00010000
    retl    0b00011100
    retl    0b10001111
    retl    0b10001111
    retl    0b00100000
    retl    0b00100000
    retl    0b10010000
    retl    0b10001111
    retl    0b10001111
    retl    0b00100000
    retl    0b00100000
    retl    0b00011100
    retl    0b10001111
    retl    0b10001111
    
    retl    0b00010000
    retl    0b00110000
    retl    0b00100000
    retl    0b10010000
    retl    0b10010111
    retl    0b10001111
    retl    0b10001110
    
    retl    0b00110000
    retl    0b00110000
    retl    0b00100000
    retl    0b10010000
    retl    0b10010111
    retl    0b10001111
    retl    0b10001110        ;14
    
    retl    0b01000000
    retl    0b00010000
    retl    0b00110000
    retl    0b10110000
    retl    0b10100000
    retl    0b10100001
    retl    0b00010011
    retl    0b00010110
    retl    0b00001100
    retl    0b10000000
    retl    0b10000000
    retl    0b10000000
    retl    0b10000001
    retl    0b00000011
    retl    0b00000110
    retl    0b00001100
    retl    0b10000000
    retl    0b10000000
    retl    0b10000000
    retl    0b10000001
    
    retl    0b00000011
    retl    0b00000110
    retl    0b00001100
    retl    0b10000000
    retl    0b10000000
    retl    0b10000000
    retl    0b10000001
    retl    0b00000011
    retl    0b00000110
    retl    0b00001100
    retl    0b00000000        ;4连发31
    
    retl    0b00110000
    retl    0b00010000        ;停顿一段时间
    retl    0b00110000
    retl    0b10110000
    retl    0b10100000
    retl    0b10100001
    retl    0b00010011
    retl    0b00010110
    retl    0b00001100
    retl    0b10000000
    retl    0b10000000
    retl    0b10000001
    retl    0b00000011
    retl    0b00000110
    retl    0b00001100
    retl    0b00000000    ;双响16
    
    retl    0b00110000        ;停顿一段时间
    retl    0b00010000
    retl    0b00110000
    retl    0b10110000
    retl    0b10100001
    retl    0b10100011
    retl    0b00010111
    retl    0b00011110
    retl    0b00001100
    retl    0b10000000
    retl    0b10000001
    retl    0b10000011
    retl    0b00000111
    retl    0b00001110
    retl    0b00001100
    retl    0b00000000    ;双响16

    
    retl    0b00110000
    retl    0b00010000
    retl    0b00000000
    retl    0b10010001
    retl    0b10100011
    retl    0b10100111
    retl    0b10101111
    retl    0b10101111
    retl    0b10011111
    retl    0b10001111
    retl    0b00001111
    retl    0b00001110
    retl    0b00001100
    retl    0b00000000
    retl    0b00000000
    retl    0b00000000
    retl    0b00000000    ;扫过17
    
    retl    0b00110000
    retl    0b00010000
    retl    0b10000000
    retl    0b10010001
    retl    0b10010011
    retl    0b10100111
    retl    0b10101111
    retl    0b10101111
    retl    0b10101111
    retl    0b10001111
    retl    0b00001111
    retl    0b00001110
    retl    0b00001100
    retl    0b00000000
    retl    0b00000000
    retl    0b00000000
    retl    0b00000000    ;扫过17
    
tbl2:
    add    pc,a
    retl    0b00000000
    retl    0b10100011    ;6
    retl    0b00011110
    retl    0b10011111
    retl    0b00100111
    retl    0b00100011    
    retl    0b10101100

    
    



    org    0x100


    ;org    0x1c0
start:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;init初始化
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    mov    a,@0b01111111
    iow    ioc6            ;p67口作为输出
    ;clr    port6
    mov    a,@0b00000000
    iow    ioc5
    iow    iocb            ;port5下拉
    clr    port5
    mov    a,@0b11111110
    iow    iocd            ;禁止上拉port6上拉
    mov    a,@0x01
    iow    iocc
    ;clr    port6
    clr    port5
    mov    a,@01
    iow    iocf            ;开TCC中断
    

/* 龙图开发网: http://www.longtoo.com  */
    
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;boom3在时间方面差不多了,功能是单调,不要进行太多
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

boom3:
    mov    a,@4            ;只进行3次
    mov    count2,a
boom32:
    mov    a,@83            ;共有这么多个点
    mov    chtbl,a
boom31:
    mov    a,chtbl
    call    tbl0            ;
    mov    cord1,a
    call    display1        ;display1是一个单一的输出
    djz    chtbl
    jmp    boom31
    djz    count2
    jmp    boom32
    ;mov    a,wmode
    ;xor    a,@04
    ;jbs    status,z
    jmp    boom3


/*;;;;;;;;;;;;;;;;;;
;boom4
;;;;;;;;;;;;;;;;;;
boom4:
    mov    a,@4
    mov    count2,a
boom42:
    mov    a,@6
    mov    chtbl,a
boom41:
    mov    a,chtbl
    call    tbl2    
    mov    cord1,a        ;为什么只取一个码
    call    display2    ;两状态显示    
    nop
    djz    chtbl
    jmp    boom41
    djz    count2
    jmp    boom42
    ;mov    a,wmode
    ;xor    a,@04
    ;jbs    status,z
    jmp    boom4        */
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


luxing:
    mov    a,@2
    mov    count2,a
luxing02:
    mov    a,@125
    mov    chtbl,a
luxing01:
    mov    a,chtbl
    mov    chtb2,a
    mov    a,chtb2
    call    tbl11
    mov    cord1,a    ;取出cord1
    inc    chtb2
    mov    a,chtb2
    call    tbl11
    mov    cord2,a    ;取出cord2
    inc    chtb2
    mov    a,chtb2
    call    tbl11
    mov    cord3,a    ;取出cord3

    
    call    display3        ;三态显示
    djz    chtbl
    jmp    luxing01
    djz    count2
    jmp    luxing02
    mov    a,wmode
    xor    a,@0b00000100
    jbs    status,z
    jmp    luxing    
    jmp    boom3
    
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
display2:                ;特点是转换时间不到256拍
    mov    a,cord1
    mov    temp,a
    rrc    temp
    rrc    temp
    rrc    temp
    rrc    temp
    mov    a,@0b00000111    ;
    and    temp,a
    mov    a,temp            ;在代码中取出分频比来确定速度
    contw
    

    mov    a,@0xff
    mov    time,a
disp23:
    mov    a,@3
    mov    count3,a
disp21:    
    mov    a,cord1    
    mov    port6,a
    mov    port5,a
    com    time
    call    delay
    jbc    next,0
    jmp    chmode
    
    clr    port6
    clr    port5
    com    time
    call    delay
    djz    count3
    jmp    disp21
    ;mov    a,@50
    ;sub    time,a
    djz    time
    jmp    disp23
    ret
;disp22:
;    mov    a,@50
    ;add    time,a
    ;jmp    disp23
        
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;    
display3:                ;有渐变
    mov    a,cord1
    mov    temp,a
    rrc    temp
    rrc    temp
    rrc    temp
    rrc    temp
    mov    a,@0b00000111    ;
    and    temp,a
    mov    a,temp            ;在代码中取出分频比来确定速度
    contw
    
    
    mov    a,@0xa0                ;可用COUNT1
    mov    time,a

disp32:
    mov    a,@1
    mov    count3,a            ;count3才决定快慢
disp31:    
    mov    a,cord3
    mov    port6,a
    mov    port5,a
    
    com    time
    call    delay
    jbc    next,0
    jmp    chmode
    
    mov    a,cord2
    mov    port6,a
    mov    port5,a
    
    com    time            ;由1向2过渡
    call    delay
    jbc    next,0
    jmp    chmode
    
    com    time
    call    delay
    jbc    next,0
    jmp    chmode
    
    mov    a,cord1
    mov    port6,a
    mov    port5,a
        
    com    time            ;由2向3过渡
    call    delay
    jbc    next,0
    jmp    chmode
        
    djz    count3          ;count3为1,让时间最短。
    jmp    disp31
    
    djz    time
    jmp    disp32
    ret
    ret
    
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
display4:                ;有渐变
    mov    a,cord1
    mov    temp,a
    rrc    temp
    rrc    temp
    rrc    temp
    rrc    temp
    mov    a,@0b00000111    ;
    and    temp,a
    mov    a,temp            ;在代码中取出分频比来确定速度
    contw
    
    
    mov    a,@0xff                ;可用COUNT1
    mov    time,a
disp42:
    mov    a,@1
    mov    count3,a
disp41:
    mov    a,cord4
    mov    port6,a
    mov    port5,a
    
    com    time
    call    delay
    jbc    next,0
    jmp    chmode
    
    mov    a,cord3
    ;mov    port6,a
    mov    port5,a
    
    com    time
    call    delay
    jbc    next,0
    jmp    chmode
    
    com    time
    call    delay
    jbc    next,0
    jmp    chmode
    
    mov    a,cord2
    ;mov    port6,a
    mov    port5,a
    
    com    time            ;由1向2过渡
    call    delay
    jbc    next,0
    jmp    chmode
    
    com    time
    call    delay
    jbc    next,0
    jmp    chmode
    
    mov    a,cord1
    mov    port6,a
    mov    port5,a
        
    com    time            ;由2向3过渡
    call    delay
    jbc    next,0
    jmp    chmode
    
    djz    count3
    jmp    disp41
    
    djz    time
    jmp    disp42
    ret
    ret

    

    
    
    
display1:                ;无渐变
    mov    a,cord1        ;输出
    mov    port6,a
    mov    port5,a
    
    mov    a,cord1
    mov    temp,a
    rrc    temp
    rrc    temp
    rrc    temp
    rrc    temp
    mov    a,@0b00000111    ;设定时间分频比
    and    a,temp
    contw
    
    mov    a,@15                ;这个常数决定时间
    mov    count3,a
disp11:    
    clr    time
                            ;count3是一个内循环
    call    delay
    ;jbc    next,0
    ;jmp    chmode
    
    djz    count3
    jmp    disp11
    clr    port6
    clr    port5
    ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*display2:
    mov    a,cord1
    mov    temp,a
    rrc    temp
    rrc    temp
    rrc    temp
    rrc    temp
    mov    a,@0b00000111
    and    a,temp
    contw
    
    mov    a,@0xff
    mov    time,a
disp22:
    mov    a,@3
    mov    count3,a
disp21:    
    mov    a,cord1
    mov    port6,a
    mov    port5,a
    com    time
    call    delay
    jbc    next,0
    jmp    chmode
    
    mov    a,cord2
    mov    port6,a
    mov    port5,a
    com    time
    call    delay
    jbc    next,0
    jmp    chmode
    
    djz    count3
    jmp    disp21
    djz    time
    jmp    disp22
    ret
    ret
*/
    
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;    延时与扫描按键
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
delay:
    clr    next            ;进入之前也清0
    clr    isr
    mov    a,time
    mov    tcc,a
delay10:
    jbs    isr,tcif
    jmp    delay10    ;延时时间到否
    jbc    port6,0    ;时间到,顺便查下按键p61口
    ret                ;无按下动作,则直接返回
keyscan:    
    mov    a,@0xff    ;一个短延时
    mov    temp,a
keyscan01:
    djz    temp
    jmp    keyscan01
    jbc    port6,0    ;再次查P61口
    ret                ;是干扰,返回
    clr    port5        ;不是,
    bs    next,0
    nop
    jbs    port6,0
    jmp    $-2        ;等待放开按键
    
    djz    wmode        ;设为下一模式
    jmp    keyscan02
    mov    a,@03
    mov    wmode,a
    jmp    keyscan04
    
keyscan02:
    mov    a,@06
    contw
    mov    a,@2
    mov    count3,a
keyscan03:
    clr    port5
    call    delay2
    call    delay2
    mov    a,@0x0f
    mov    port5,a
    call    delay2
    call    delay2
    djz    count3
    jmp    keyscan03
keyscan04:
    clr    port5
    call    delay2
    call    delay2
    call    delay2
    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

delay2:    
    clr    isr
    mov    a,@06
    mov    tcc,a
delay20:    
    jbs    isr,tcif
    jmp    delay20
    ret
    ret    


/* 龙图开发网: http://www.longtoo.com  */

    
chmode:
    mov    a,wmode
    mov    count3,a
    djz    count3
    jmp    chmode1
    jmp    luxing;第一种模式
chmode1:
    djz    count3
    jmp    chmode2
    jmp    boom3;第二种模式
chmode2:
    jmp    boom3
    
    
/* http://www.youdon.cn  http://www.60film.cn  */    
    
    end
        
    

    

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

11

主题

11

帖子

0

粉丝