您当前的位置:首页 > 自动化 > 单片机

Pic16f877 中断控制电路

发布时间:2010-03-02 19:32:12  来源:资料室  作者:  更新20241204 070859

Pic16f877 中断控制电路

 

程序范例:
1.外部中断LED 方向控制
2.计时中断LED 方向控制
3.计时加外部中断LED 方向控制
4.计时中断时钟 ─ 分:秒(使用七段显示器)
5.计时中断 ─ 改写8led22.asm 程序

外部中断LED 方向控制

 

范例一:int1.*
LIST P=16F877,R=DEC
#INCLUDE <P16F877.INC>
;
CBLOCK 0X20
R0,USRFLAG
ENDC
;
ORG 0
NOP
GOTO MAIN
ORG 4
BTFSS USRFLAG,0
GOTO INT1
BCF USRFLAG,0
GOTO INT2
INT1: BSF USRFLAG,0
INT2: BTFSS PORTB,0
GOTO INT2
BCF INTCON,INTF
RETFIE
;
MAIN:
BANKSEL TRISD
MOVLW 0
MOVWF TRISD
BANKSEL PORTD
BSF INTCON,GIE
BSF INTCON,INTE
MOVLW B'11111110'
MOVWF R0
BCF USRFLAG,0
MLOOP: MOVF R0,0
MOVWF PORTD
CALL DELAY250
BTFSC USRFLAG,0
GOTO RIGHT
LEFT: CLRC
BTFSC R0,7
SETC
RLF R0,1
GOTO MLOOP
RIGHT: CLRC
BTFSC R0,0
SETC
RRF R0,1
GOTO MLOOP
;
#INCLUDE <DELAY250.INC>
;
END
 
 

计时中断LED 方向控制

 

范例一:int2.*
LIST P=16F877,R=DEC
#INCLUDE <P16F877.INC>
;
CBLOCK 0X20
R0,WBAK,SBAK,USRFLAG
DCONT
ENDC
;
TBUF EQU 256-250
;
ORG 0
NOP
GOTO MAIN
ORG 4
MOVWF WBAK
SWAPF STATUS,0
MOVWF SBAK
MOVLW TBUF
ADDWF TMR0
DECF DCONT
MOVF DCONT,1
SKPZ
GOTO T2INT
MOVLW .200
MOVWF DCONT
BTFSS USRFLAG,0
GOTO T1INT
BCF USRFLAG,0
GOTO T2INT
T1INT: BSF USRFLAG,0
T2INT: BCF INTCON,T0IF
SWAPF SBAK,0
MOVWF STATUS
SWAPF WBAK,1
SWAPF WBAK,0
RETFIE
;
MAIN:
BANKSEL OPTION_REG
MOVLW B'00000111'
MOVWF OPTION_REG
MOVLW 0
MOVWF TRISD
BANKSEL TMR0
MOVLW TBUF
MOVWF TMR0
BSF INTCON,GIE
BSF INTCON,T0IE
MOVLW .200
MOVWF DCONT
MOVLW B'11111110'
MOVWF R0
BCF USRFLAG,0
MLOOP: MOVF R0,0
MOVWF PORTD
CALL DELAY250
BTFSC USRFLAG,0
GOTO RIGHT
LEFT: CLRC
BTFSC R0,7
SETC
RLF R0,1
GOTO MLOOP
RIGHT: CLRC
BTFSC R0,0
SETC
RRF R0,1
GOTO MLOOP
;
#INCLUDE <DELAY250.INC>
;
END
 
 

 

 

计时加外部中断LED方向控制
范例一:int3.*
LIST P=16F877,R=DEC
#INCLUDE <P16F877.INC>
;
CBLOCK 0X20
R0,WBAK,SBAK,USRFLAG
DCONT
ENDC
;
TBUF EQU 256-250
;
ORG 0
NOP
GOTO MAIN
ORG 4
BTFSS INTCON,T0IF
GOTO INT0
BCF INTCON,INTE
MOVWF WBAK
SWAPF STATUS,0
MOVWF SBAK
MOVLW TBUF
ADDWF TMR0
DECF DCONT
MOVF DCONT,1
SKPZ
GOTO T2INT
MOVLW .200
MOVWF DCONT
BTFSS USRFLAG,0
GOTO T1INT
BCF USRFLAG,0
GOTO T2INT
T1INT: BSF USRFLAG,0
T2INT: BCF INTCON,T0IF
BSF INTCON,INTE
SWAPF SBAK,0
MOVWF STATUS
SWAPF WBAK,1
SWAPF WBAK,0
GOTO RIGHT
LEFT: CLRC
BTFSC R0,7
SETC
RLF R0,1
GOTO MLOOP
RIGHT: CLRC
BTFSC R0,0
SETC
RRF R0,1
GOTO MLOOP
;
#INCLUDE <DELAY250.INC>
;
END
RETFIE
;
INT0: BCF INTCON,T0IE
BTFSS USRFLAG,0
GOTO INT01
BCF USRFLAG,0
GOTO INT02
INT01: BSF USRFLAG,0
INT02: BTFSS PORTB,0
GOTO INT02
BCF INTCON,INTF
MOVLW TBUF
MOVWF TMR0
MOVLW .200
MOVWF DCONT
BSF INTCON,T0IE
RETFIE
;
MAIN:
BANKSEL OPTION_REG
MOVLW B'00000111'
MOVWF OPTION_REG
MOVLW 0
MOVWF TRISD
BANKSEL TMR0
MOVLW TBUF
MOVWF TMR0
BSF INTCON,GIE
BSF INTCON,T0IE
BSF INTCON,INTE
MOVLW .200
MOVWF DCONT
MOVLW B'11111110'
MOVWF R0
BCF USRFLAG,0
MLOOP: MOVF R0,0
MOVWF PORTD
CALL DELAY250
BTFSC USRFLAG,0
 
 

 

 

计时中断时钟 ─ 分:秒(使用七段显示器)
范例一:intclock.*
LIST P=16F877,R=DEC
#INCLUDE <P16F877.INC>
;
CBLOCK 0X20
DB0,DB1,WBAK,SBAK,DCONT
C1,C2,TIMS,TIMM
ENDC
;
TBUF EQU 256-250
;
ORG 0
NOP
GOTO MAIN
ORG 4
MOVWF WBAK
SWAPF STATUS,0
MOVWF SBAK
MOVLW TBUF
ADDWF TMR0
DECF DCONT
MOVF DCONT,1
SKPZ
GOTO T2INT
MOVLW .125
MOVWF DCONT
CALL TEST1
CALL TEST2
T2INT: BCF INTCON,T0IF
SWAPF SBAK,0
MOVWF STATUS
SWAPF WBAK,1
SWAPF WBAK,0
RETFIE
;
MAIN:
BANKSEL OPTION_REG
MOVLW B'00000110'
MOVWF OPTION_REG
MOVLW 0

;
SWAPF TIMM,0
CALL TABLE
MOVWF PORTD
MOVLW H'F7'
MOVWF PORTB
CALL DELAY25
BSF PORTB,3
GOTO MLOOP
;
TABLE: ANDLW H'0F'
ADDWF PCL
T1: RETLW H'C0' ;'0'
RETLW H'F9' ;'1'
RETLW H'A4' ;'2'
RETLW H'B0' ;'3'
RETLW H'99' ;'4'
RETLW H'92' ;'5'
RETLW H'82' ;'6'
RETLW H'F8' ;'7'
RETLW H'80' ;'8'
RETLW H'90' ;'9'
RETLW H'88' ;'A'
RETLW H'83' ;'B'
RETLW H'C6' ;'C'
RETLW H'A1' ;'D'
RETLW H'86' ;'E'
RETLW H'8E' ;'F'
;
TEST1: INCF DB0
MOVF DB0,0
SUBLW .60
SKPZ
RETURN
MOVLW 0
MOVWF DB0
INCF DB1
MOVF DB1,0
SUBLW .60
SKPZ
RETURN
MOVLW

MOVWF TRISD
MOVWF TRISB
BANKSEL TMR0
MOVLW TBUF
MOVWF TMR0
BSF INTCON,GIE
BSF INTCON,T0IE
MOVLW .125
MOVWF DCONT
MOVLW H'FF'
MOVWF PORTB
MOVLW 0
MOVWF DB0
MOVWF DB1
MOVWF TIMS
MOVWF TIMM
MLOOP: MOVF TIMS,0
CALL TABLE
MOVWF PORTD
MOVLW H'FE'
MOVWF PORTB
CALL DELAY25
BSF PORTB,0
;
SWAPF TIMS,0
CALL TABLE
MOVWF PORTD
MOVLW H'FD'
MOVWF PORTB
CALL DELAY25
BSF PORTB,1
;
MOVF TIMM,0
CALL TABLE
MOVWF PORTD
MOVLW H'FB'
MOVWF PORTB
CALL DELAY25
BSF PORTB,2

MOVWF DB1
RETURN
;
TEST2: CLRF C1
CLRF C2
MOVF DB0,0
MOVWF TIMS
MOVF DB1,0
MOVWF TIMM
TA: MOVLW .10
SUBWF TIMS,0
SKPC
GOTO TB
MOVWF TIMS
INCF C1
GOTO TA
TB: SWAPF C1,0
IORWF TIMS,0
MOVWF TIMS
TC: MOVLW .10
SUBWF TIMM,0
SKPC
GOTO TD
MOVWF TIMM
INCF C2
GOTO TC
TD: SWAPF C2,0
IORWF TIMM,0
MOVWF TIMM
RETURN
;
#INCLUDE <DELAY25.INC>
;
END

 
 

 

 

计时中断 ─ 改写8led22.asm 程序
范例一:int4.*
LIST P=16F877,R=DEC
#INCLUDE <P16F877.INC>
;
CBLOCK H'20'
WBAK,SBAK,DCONT,PORT_REG
ENDC
;
ORG 0
NOP
GOTO MAIN
ORG 4
MOVWF WBAK
SWAPF STATUS,0
MOVWF SBAK
MOVLW 6
ADDWF TMR0
DECF DCONT
MOVF DCONT,1
SKPZ
GOTO T2INT
MOVLW 125
MOVWF DCONT
BTFSC PORT_REG,7
GOTO T1INT
MOVLW B'11111110'
MOVWF PORT_REG
GOTO T2INT
T1INT: SETC
RLF PORT_REG,1
T2INT: BCF INTCON,T0IF
SWAPF SBAK,0
MOVWF STATUS
SWAPF WBAK,1
SWAPF WBAK,0
RETFIE
;
MAIN:
BANKSEL OPTION_REG
MOVLW B'00000110'
MOVWF OPTION_REG
MOVLW 0
MOVWF TRISD
BANKSEL TMR0
MOVLW 6
MOVWF TMR0
BSF INTCON,GIE
BSF INTCON,T0IE
MOVLW 125
MOVWF DCONT
MOVLW B'11111110'
MOVWF PORT_REG
AGAIN: MOVF PORT_REG,0
MOVWF PORTD
GOTO AGAIN
END
※ 移位时间设为1 秒钟 ※
 
 
 


来顶一下
返回首页
返回首页
分享到:
发表评论

 共有人参与,请您也说几句看法

 
   验证码: 看不清楚,点击刷新 看不清楚,点击刷新
最新评论
  • U2XN 匿名 于2024-12-03 08:55:31发布
  • 怎么下载 匿名 于2024-12-02 10:22:30发布
  • 感谢老大,资源很有用~! 扁柏 于2024-11-30 19:17:02发布
  •  吴工 于2024-11-29 23:02:18发布
  • 看看 匿名 于2024-11-28 07:38:29发布
  • SONY索尼LBT-V4500说明书在哪里能找到?
     匿名 于2024-11-24 13:08:54发布
  • 学习学习 匿名 于2024-11-20 15:18:56发布
  • 谢谢
     匿名 于2024-11-13 18:03:02发布
  • thanks 匿名 于2024-11-13 06:08:51发布
  • 学习学习 匿名 于2024-11-11 14:21:31发布