chipchipvn
03-11-2006, 07:39 PM
Em viết một cái code rất đơn giản để làm quen với Interupt nhưng sao không biết cái Proteus lại chẳng thực hiện được! T_T, ấn nút mỏi tay mà đèn hông sáng! Các anh xem hộ em với
Em không post phàn khai báo, chỉ có phần chạy thui ^^
Còn đây là ảnh của phần giả lập Proteus
http://s23.quicksharing.com/v/500147/TESTLED.GIF.html (namqn: Link không hoạt động)
ORG 00
Goto Main
ORG 04
Goto LED
Main
bsf INTCON,GIE
bsf INTCON,INTE
banksel TRISB
bsf TRISB,0
bcf TRISB,1
bcf TRISB,2
banksel PORTB
bcf PORTB,0
Goto $
;================================================= =========
LED
bcf PORTB,2
bsf PORTB,2
movwf _work ; Save W in Bank0 or Bank1
btfsc STATUS,RP0 ; Check which bank PIC is in
goto IN_BANK0 ; IF == 0 THEN already in Bank0
; Continue here if PIC is in Bank1 on entry
bcf STATUS,RP0 ; Change into Bank0
swapf STATUS,w ; Save STATUS in Bank0
movwf _status ; in the usual way
bsf _status,RP0 ; Set back saved RP0 in memory
goto INVERT ; and begin the core code
IN_BANK0
swapf STATUS,w ; If already in Bank0
movwf _status ; save STATUS in the usual way
;================================================= ===========
INVERT
bcf INTCON,INTF
movf PORTB,w
xorlw b'00000010'
movwf PORTB
;================================================= ============
; Restore context. Processor in Bank0
swapf _status,w ; Untwist & get old Status from memory
movwf STATUS ; which also restores original bank
swapf _work,f ; Now get original W register from
swapf _work,w ; interrupted bank
retfie ; and return to interrupted background
end
Em không post phàn khai báo, chỉ có phần chạy thui ^^
Còn đây là ảnh của phần giả lập Proteus
http://s23.quicksharing.com/v/500147/TESTLED.GIF.html (namqn: Link không hoạt động)
ORG 00
Goto Main
ORG 04
Goto LED
Main
bsf INTCON,GIE
bsf INTCON,INTE
banksel TRISB
bsf TRISB,0
bcf TRISB,1
bcf TRISB,2
banksel PORTB
bcf PORTB,0
Goto $
;================================================= =========
LED
bcf PORTB,2
bsf PORTB,2
movwf _work ; Save W in Bank0 or Bank1
btfsc STATUS,RP0 ; Check which bank PIC is in
goto IN_BANK0 ; IF == 0 THEN already in Bank0
; Continue here if PIC is in Bank1 on entry
bcf STATUS,RP0 ; Change into Bank0
swapf STATUS,w ; Save STATUS in Bank0
movwf _status ; in the usual way
bsf _status,RP0 ; Set back saved RP0 in memory
goto INVERT ; and begin the core code
IN_BANK0
swapf STATUS,w ; If already in Bank0
movwf _status ; save STATUS in the usual way
;================================================= ===========
INVERT
bcf INTCON,INTF
movf PORTB,w
xorlw b'00000010'
movwf PORTB
;================================================= ============
; Restore context. Processor in Bank0
swapf _status,w ; Untwist & get old Status from memory
movwf STATUS ; which also restores original bank
swapf _work,f ; Now get original W register from
swapf _work,w ; interrupted bank
retfie ; and return to interrupted background
end