| 
 | 
 
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册  
 
×
 
哪位同学用过PIC单片机,能否帮我看看这个程序是否能够实现流水灯, 
仿真或者直接用开发板实验,这里使用PIC16F84。 
 
 
 
;***************************************************************************** 
;  lights run (0,1,2,...,7,off,7,6,5,...,1,0,off,0,1,2...) 
;***************************************************************************** 
    LIST P=16F84, R=HEX 
    #include p16f84.inc 
 
    flag  equ  H'25' 
 
    org    000h 
;***************************************************************************** 
;  main code 
start 
    nop 
    bsf    STATUS,5    ;set register file to bank 1 
    movlw  0x00    ;set trisb to 0x00(output) 
    movwf  TRISB 
    bcf    STATUS,5    ;clear bank select bits(default select bank 0) 
    movlw  0x01    ;set portb[0] 
    movwf  PORTB 
    bsf    flag,0    ;set flag[0] 
    bcf    STATUS,0    ;clear Carry/Borrow BIT 
loop 
    btfss  STATUS,0    ;skip if Carry/Borrow BIT set 
    goto   loop1 
    comf   flag,1    ;complement flag,and place back, 
                     ;ie,move the reverse direction 
loop1 
    btfss  flag,0    ;skip if flag[0] set 
    goto   loop2 
    rlf    PORTB,0    ;rotate left portb through Carry/Borrow BIT, 
    movwf  PORTB      ;and move result to portb 
    goto   loop3 
loop2 
    rrf    PORTB,0    ;rotate right portb through Carry/Borrow BIT, 
    movwf  PORTB      ;and move result to portb 
loop3 
    call   delay 
    call   delay 
    goto   loop 
 
;***************************************************************************** 
;  subroutine delay 
delay 
    movlw  0x0f    ;set H'20' to 0xff 
    movwf  H'20' 
lp0 
    movlw  0x0f    ;set H'21' to 0xff 
    movwf  H'21' 
lp1 
    decfsz H'21',1    ;decrement H'21',skip if 0,result place back 
    goto lp1 
    decfsz H'20',1    ;decrement H'20',skip if 0,result place back 
    goto lp0 
    return 
 
;***************************************************************************** 
;  end 
    end |   
 
 
 
 |