PIC单片机外部中断
时间:11-29
来源:互联网
点击:
#INCLUDE"P16F877.inc"
ORG 000HGOTO A1ORG 04HGOTO ZD01A1 BSF STATUS,RP0BCF STATUS,RP1;体1MOVLW 0HMOVWF TRISA;设置A口为输出口MOVLW 06H MOVWF ADCON1;设置A口为普通I/O口模式 movlw 0FFHmovwf TRISB;设定RB为输入BCF STATUS,RP0BCF STATUS,RP1;体0MOVLW 0FFHMOVWF PORTA;A口输出高电平BCF INTCON,INTF;清中断标志BSF INTCON,INTE;开外部中断BSF INTCON,GIE;开总中断GOTO $ZD01 BTFSS INTCON,INTF;判断是否发生外部中断GOTO ZD02 BCF INTCON,INTF;清中断标志BTFSS PORTB,0;;判断触发中断键是否抬起避免产生2次中断GOTO $-1;COMF PORTA,1;取反A口ZD02 RETFIE ;中断标志END#INCLUDE"P16F877.inc"ORG 000HGOTO A1ORG 004H;定时中断入口地址 GOTO ZD01;ORG 0CHA1 MOVLW 1;位1显示数MOVWF 50H; MOVLW 2;位2显示数MOVWF 51H;MOVLW 3;位3显示数MOVWF 52H;MOVLW 4;位4显示数MOVWF 53H;MOVLW 4;显示位数MOVWF 40H;MOVLW B00000001;位码MOVWF 41H;MOVLW 50H;MOVWF FSR ;间接寻址BSF STATUS,RP0;选择体1BCF STATUS,RP1;MOVLW 00H;1:2TMRO比例MOVWF OPTION_REG;分频1/2BCF STATUS,RP0;体0BCF STATUS,RP1;MOVLW 0FFH;MOVFW TMR0;初值BCF INTCON,T0IF;清定时中断标志BSF INTCON,T0IE;开定时中断BSF INTCON,GIE;开总中断A2 BTFSC PORTD,4GOTO A3MOVLW 1MOVWF 50HA3 BTFSC PORTD,5GOTO A4MOVLW 2MOVWF 50HA4 BTFSC PORTD,6GOTO A5MOVLW 3MOVWF 50HA5 BTFSC PORTD,7GOTO A6MOVLW 4MOVWF 50HA6 GOTO A2ZD01 BCF INTCON,GIE;关总中断BTFSS INTCON,T0IF;判断是否产生定时中断GOTO ZD03;否跳出是继续执行BCF INTCON,T0IFBSF STATUS,RP0;体1BCF STATUS,RP1;MOVLW 0;MOVWF TRISC;RB口设为输出口MOVLW B11110000MOVWF TRISD;RD口设为输出口BCF STATUS,RP0;体0BCF STATUS,RP1;MOVLW 0FFH;MOVWF PORTC;RB口输出高电平MOVLW 0MOVWF PORTD;RD口输出低电平起清屏作用MOVFW INDF;间接寻址显示数据 CALL Q1;查数据表MOVWF PORTC;显示断码输出到RB口INCF FSR,1;间接寻址地址加1MOVFW 41H ;位码MOVWF PORTD;位码输出到RD口RLF 41H,0;处理CRLF 41H,1;左移位码DECFSZ 40H,1;判断是否显示完4位GOTO ZD02;否则继续显示MOVLW 4;显示位数MOVWF 40H;MOVLW B00000001;位码MOVWF 41H;MOVLW 50H;MOVWF FSR ;间接寻址ZD02 MOVLW 0FFH;MOVFW TMR0;重装初值ZD03 BSF INTCON,GIE;开总中断RETFIE ;中断返回;********************************************; 数据表;******************************************** Q1 ADDWF PCL,1 RETLW 00C0H ;0RETLW 00F9H ;1RETLW 00A4H ;2RETLW 00B0H ;3RETLW 0099H ;4RETLW 0092H ;5RETLW 0082H ;6RETLW 00F8H ;7RETLW 0080H ;8RETLW 0090H ;9RETLW 0088H ;ARETLW 0083H ;BRETLW 00C6H ;CRETLW 00A1H ;DRETLW 0086H ;ERETLW 008EH ;FEND
PIC单片机外部中 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)