PIC单片机在ICD1上做LED灯的循环闪烁程序
 
;*************************************************
;* FLASH.ASM *
;*************************************************
;*-----------------------------------------------*
;*PIC单片机 www.pic16.com*
;*-----------------------------------------------*
;*************************************************
;* 本程序是一个LED灯的循环闪烁程序,用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 ;设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
   返回

-------------PIC单片机 www.pic16.com-----------