PIC 单片机 LED流水灯程序
;*************************************************************
include
;**************************************************
__CONFIG 3F39H;设置配置位中振荡方式为XT,其它全部禁止或关闭
;*----
MODESEL equ 20h
MODESELB equ 21h
Count equ 22h
Count1 equ 23h
Count2 equ 24h
PORTDB equ 25h
;*-----
org 0
nop
goto start
org 4
goto ISR
org 10
start
clrf PORTC ;清c口
MOV lw 00h
MOV wf MODESEL ;初始化模式选择寄存器
MOV wf MODESELB
MOV lw b'10010000'
MOV wf INTCON ;初始化中断控制
bsf STATUS,RP0
clrf TRISC ;设C口全为输出
MOV lw b'10111111'
MOV WF OPTION_REG ;选择INT下降沿有效
bcf STATUS,RP0
call FMsel
MOV wf PORTDB
MOV wf PORTC
main
btfsc PORTB,0 ;\
goto $+6 ; \
call Delay ; 按键去抖动
btfsc PORTB,0
goto $+3 ; /
call FMsel ;/
MOV wf PORTDB
MOV f MODESELB,W ;
MOV wf MODESEL ;
call LongDelay
bcf STATUS,C
rlf PORTDB,1
btfsc STATUS,C
bsf PORTDB,0
MOV f PORTDB,W
MOV wf PORTC
goto main
;*----------
Delay ; call指令占用2个指令周期
clrf Count ; 清 Count占用1个指令周期
Dloop
decfsz Count,f ; 这两行指令将延时
goto Dloop ; (256 * 3) -1 个指令周期
return ; return占用2个指令周期
;*----------------
LongDelay
clrf Count
clrf Count1
MOV lw 0x01
MOV wf Count2
LDloop
decfsz Count,f
goto LDloop
decfsz Count1,f
goto LDloop
decfsz Count2,f
goto LDloop
return
;*---------------
FMsel
MOV f MODESEL,w
MOV wf MODESELB
MOV f MODESEL,w
addwf PCL
retlw b'11111000'
retlw b'11110000'
retlw b'11100000'
retlw b'11000000'
retlw b'10000000'
MOV lw 00h
MOV wf MODESELB
bsf INTCON,GIE
retlw b'11111000'
return
;*-------------
ISR
btfss INTCON,INTF
goto $+3
bcf INTCON,INTF
incf MODESEL
retfie
end
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』