您当前的位置:五五电子网电子知识单片机-工控设备PIC单片机16F870单片机的中断应用程序 正文
16F870单片机的中断应用程序

16F870单片机的中断应用程序

点击数:7586 次   录入时间:03-04 11:50:53   整理:http://www.55dianzi.com   PIC单片机
; Filename: WK_PCHG.asm *
; Date:Mar/13/2001 ;**********************************************************************
list p=16f870
#include <p16f870.inc>

; __CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _RC_OSC & _WRT_ENABLE_ON & _LVP_OFF & _CPD_OFF 
FLAG EQU 0x20
Var1 EQU 0x21
Var2 EQU 0x22
INT_Var1 EQU 0x30
INT_Var2 EQU 0x31
W_Temp EQU 0x72
STATUS_Temp EQU 0x73
FSR_Temp EQU 0x74
#define VAL_1MS .248
#define FLAG_INC 0
#define FLAG_DEC 1

org 0x00 ; RESET ???? 0x000
nop
clrf PCLATH
goto Main
org 0x004
INT_ISRs
;***************************************************************
MOV wf W_Temp ; save off current W register contents
MOV f STATUS,W ; move status register into W register
bcf STATUS,RP0 ; ensure file register bank set to 0
MOV wf STATUS_Temp ; save off contents of STATUS register
MOV f FSR,W
MOV wf FSR_Temp

BANKSEL PORTB
MOV f PORTB,W
bcf INTCON,RBIF
bcf INTCON,RBIE ; RBIE DISAble

call Bounce_Delay
?
btfsc PORTB,4
goto Check_DEC_KEY
bsf FLAG,FLAG_INC ; FLAG_INC ? 1
goto Exit_ISRs
Check_DEC_KEY
btfss PORTB,5
bsf FLAG,FLAG_DEC

Exit_ISRs
MOV f FSR_Temp,W
MOV wf FSR
bcf STATUS,RP0 ; ensure file register bank set to 0
MOV f STATUS_Temp,w ; retrieve copy of STATUS register
MOV wf STATUS ; restore pre-isr STATUS register contents
swapf W_Temp,F
swapf W_Temp,W ; restore pre-isr W register contents
retfie ; return from interrupt
;******************************************************************************
;**** Delay 10 ms ?
;******************************************************************************
Bounce_Delay
MOV lw .10
MOV wf INT_Var1
Bounce_Loop1
MOV lw .248
MOV wf INT_Var2
Bounce_Loop2
nop
decfsz INT_Var2,F
goto Bounce_Loop2
decfsz INT_Var1,F
goto Bounce_Loop1
return
******************************************
Main
BANKSEL TRISB
MOV lw B’11110000’
MOV wf TRISB ; RB4..RB7
clrf TRISC
MOV lw B’00000000’ ; Enable PORTB ? Pull UP
MOV wf OPTION_REG
BANKSEL PORTB
MOV lw B’11111111’
MOV wf PORTB
clrf PORTC

bsf INTCON,GIE
clrf FLAG
bsf FLAG,FLAG_INC
Prog_Loop
btfss FLAG,FLAG_INC
goto Dec_Process

Inc_Process
call Delay_50ms
incfsz PORTC,F
goto Inc_Process
goto SLEEP_Process
Dec_Process
call Delay_50ms
decfsz PORTC,F
goto Dec_Process
SLEEP_Process
clrf PORTC
clrf FLAG
MOV f PORTB,W
bcf INTCON,RBIF
bsf INTCON,RBIE
SLEEP
nop
nop
goto Prog_Loop

;****************************************************************************
;**** Delay 50ms ?
;****************************************************************************
Delay_50ms
MOV lw .50
MOV wf Var2
Delay_200ms_Loop
call Delay_1ms
decfsz Var2,F
goto Delay_200ms_Loop
return
;****************************************************************************
;**** Delay 1ms ?
;****************************************************************************
Delay_1ms
nop
nop
nop
MOV lw VAL_1MS
MOV wf Var1
Delay_1ms_Loop nop
decfsz Var1,F
goto Delay_1ms_Loop
return

END 


本文关键字:单片机  应用程序  PIC单片机单片机-工控设备 - PIC单片机