PIC單片機在ICD1上做LED燈的循環(huán)閃爍程序
;* FLASH.ASM *
;*************************************************
;*************************************************
;* 本程序是一個LED燈的循環(huán)閃爍程序,用INT鍵來切換*
;* 閃爍模式 *
;*************************************************
include p16f877.inc>
;*----
MODESEL equ 20h
MODESELB equ 21h
Count equ 22h
Count1 equ 23h
Count2 equ 24h
PORTDB equ 25h
;*-----
org 0
goto start
org 4
goto ISR
org 10
start
clrf PORTD ;清D口
movlw 00h
movwf MODESEL ;初始化模式選擇寄存器
movwf MODESELB
movlw b'10010000'
movwf INTCON ;初始化中斷控制
bsf STATUS,RP0
clrf TRISD ;設(shè)D口全為輸出
movlw b'10111111'
OPTION ;選擇INT下降沿有效
bcf STATUS,RP0
call FMsel
movwf PORTDB
movwf PORTD
main btfsc PORTB,0 ;
goto $+6 ;
call Delay ; 按鍵去抖動
btfsc PORTB,0
goto $+3 ; /
call FMsel ;/
movwf PORTDB
movf MODESELB,W ;
movwf MODESEL ;
call LongDelay
bcf STATUS,C
rlf PORTDB,1
btfsc STATUS,C
bsf PORTDB,0
movf PORTDB,W
movwf PORTD
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
movlw 0x01
movwf Count2
LDloop
decfsz Count,f
goto LDloop
decfsz Count1,f
goto LDloop
decfsz Count2,f
goto LDloop
return
;*---------------
FMsel
movf MODESEL,w
movwf MODESELB
movf MODESEL,w
addwf PCL
retlw b'11111000'
retlw b'11110000'
retlw b'11100000'
retlw b'11000000'
retlw b'10000000'
movlw 00h
movwf MODESELB
bsf INTCON,GIE
retlw b'11111000'
return
;*-------------
ISR
btfss INTCON,INTF
goto $+3
bcf INTCON,INTF
incf MODESEL
retfie
end
led燈相關(guān)文章:led燈原理
評論