英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流

 找回密码
 立即注册
搜索
电子烟方案单片机单片机开发深圳单片机开发
单片机方案国产单片机8位单片机电子烟方案开发
查看: 2982|回复: 0
打印 上一主题 下一主题

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

[复制链接]
跳转到指定楼层
1#
发表于 2009-5-5 17:42:34 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
;**********************************************************************
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
;***************************************************************
movwf W_Temp ; save off current W register contents
movf STATUS,W ; move status register into W register
bcf STATUS,RP0 ; ensure file register bank set to 0
movwf STATUS_Temp ; save off contents of STATUS register
movf FSR,W
movwf FSR_Temp

BANKSEL PORTB
movf 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
movf FSR_Temp,W
movwf FSR
bcf STATUS,RP0 ; ensure file register bank set to 0
movf STATUS_Temp,w ; retrieve copy of STATUS register
movwf 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
movlw .10
movwf INT_Var1
Bounce_Loop1
movlw .248
movwf INT_Var2
Bounce_Loop2
nop
decfsz INT_Var2,F
goto Bounce_Loop2
decfsz INT_Var1,F
goto Bounce_Loop1
return
******************************************
Main
BANKSEL TRISB
movlw B'11110000'
movwf TRISB ; RB4..RB7
clrf TRISC
movlw B'00000000' ; Enable PORTB  Pull UP
movwf OPTION_REG
BANKSEL PORTB
movlw B'11111111'
movwf 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
movf PORTB,W
bcf INTCON,RBIF
bsf INTCON,RBIE
SLEEP
nop
nop
goto Prog_Loop

;****************************************************************************
;**** Delay 50ms 
;****************************************************************************
Delay_50ms
movlw .50
movwf Var2
Delay_200ms_Loop
call Delay_1ms
decfsz Var2,F
goto Delay_200ms_Loop
return
;****************************************************************************
;**** Delay 1ms 
;****************************************************************************
Delay_1ms
nop
nop
nop
movlw VAL_1MS
movwf Var1
Delay_1ms_Loop nop
decfsz Var1,F
goto Delay_1ms_Loop
return

END
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|公司首页|Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 ( 粤ICP备09008620号 )

GMT+8, 2024-4-20 11:44 , Processed in 0.047994 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表