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
callFMsel
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