之前發問過有關PORTB的Interrupt on change應用的問題,小弟將程式附上如下,麻煩各位先進提供解決的方法
|
||||
---|---|---|---|---|
新會員
|
之前發問過有關PORTB的Interrupt on change應用的問題,小弟將程式附上如下,麻煩各位先進提供解決的方法(應該是Read-Modify-Write造成wake up之後輸出不正常的情況)
list p = 18F452 #include <p18F452.inc> TEMP EQU 0x02 ORG 0x00 GOTO START ORG 0x08 GOTO ServiceInterrupt org 0x20 START call InitPortB ;initalize port B bsf RCON,IPEN bsf INTCON,GIEH loop sleep ;sleep till key is hit nop goto loop ServiceInterrupt btfsc INTCON,RBIF ;change on rb int? goto ServiceWakup ;yes then service bcf INTCON,TMR0IE ;clear TMR0 int mask bcf INTCON,TMR0IF ;clear flag return ServiceWakup bcf INTCON,RBIE ;clear mask MOVF LATB,W ;read PORTB bcf INTCON,RBIF ;clear flag call delay16 ;do de-bounce for 16mSecs MOVF LATB,W ;read port B again andlw B'11110000' ;mask outputs movwf TEMP ;save in temp swapf TEMP,F ;switch low and high movfF TEMP,LATB ;send as outputs. call KeyRelease ;check for key release RETFIE KeyRelease call delay16 ;do debounce MOVF LATB,W ;read PORTB bcf INTCON,RBIF ;clear flag bsf INTCON,RBIE ;enable mask andlw B'11110000' ;clear outputs btfsc STATUS,Z ;key still pressed? return ;no then return sleep ;else save power bcf INTCON,RBIE ;on wake up clear mask MOVF LATB,W bcf INTCON,RBIF ;clear flag goto KeyRelease ;try again InitPortB CLRF PORTB CLRF LATB MOVLW 0x0F ; 使PORTB為 MOVWF ADCON1 ; Digital I/O MOVLW 0xF0 ; RB0-RB3 outputs MOVWF TRISB ; RB4-RB7 inputs bcf INTCON2,RBPU ;enable pull up bcf INTCON,RBIE ;disable mask movf LATB,W ;read port bcf INTCON,RBIF ;clear flag bsf INTCON,RBIE ;enable mask RETFIE delay16 movlw B'11000111' ;fosc/256 --> TMR0 movwf T0CON ; / clrf TMR0L bcf INTCON,TMR0IF ;clear flag bsf INTCON,TMR0IE ;enable mask CheckAgain btfss INTCON,TMR0IF ;timer overflowed? goto CheckAgain ;no check again bcf INTCON,TMR0IE ;else clear mask bcf INTCON,TMR0IF ;clear flag return end
發表於: 2006/7/25 8:39
|
|||
|