• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: 之前發問過有關PORTB的Interrupt on change應用的問題,小弟將程式附上如下,麻煩各位先進提供解決的方法
#2
高級會員
高級會員


查看用戶資訊
你read port b
用 [ MOVF LATB,W ;read PORTB ]
這裡錯了
LATB 是輸出的栓鎖 讀到的是你上次對PORTB 輸出的值

InitPortB 你用 RETFIE 返回 不會有問題嗎?

發表於: 2006/7/25 11:16
微電腦自動控制設計,產品製造
才疏學淺,若有錯誤敬請指正
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


之前發問過有關PORTB的Interrupt on change應用的問題,小弟將程式附上如下,麻煩各位先進提供解決的方法
#1
新會員
新會員


查看用戶資訊
之前發問過有關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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------