Anh ơi cho em hỏi thêm cái nữa là:
1.Tại sao lại có lệnh CLRF PORTD (nằm trong hàm main) ... trong đây ta đâu đụng gì đến cổng D của 16F877A ?!
2.
MOVF RCREG,W
MOVWF PORTD
Trong ngắt có 2 lệnh này, thật ra là dư thừa vì trong mạch test ta ko có kết nối LED vào PortD !
3. Em sửa lại như vầy có được ko ạ:
list p=16f877A
#include <p16f877A.inc>
__CONFIG 0x393A
errorlevel -302
w_temp EQU 0x71
status_temp EQU 0x72
pclath_temp EQU 0x73
;************************************************* *********************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move STATUS register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,W ; move PCLATH register into W register
movwf pclath_temp ; save off contents of PCLATH register
;================================================= ============================
BANKSEL RCREG
MOVF RCREG,W
MOVWF PORTB ; Chuyen du lieu nhan duoc ra PortB
BANKSEL TXREG ;
MOVWF TXREG ; Chuyen du lieu nguoc lai PC
;================================================= =============================
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie
main
BANKSEL ADCON1
MOVLW 0x06
MOVWF ADCON1
CALL Init_serialport
BANKSEL TRISB
CLRF TRISB ; Cho dang PORTB la dang out
BSF INTCON,GIE
BSF INTCON,PEIE
GOTO $
Init_serialport ; Module khoi tao cho Serial
BANKSEL TXSTA
BSF TRISC,7 ; Chon chan rb2 la dang in
BCF TRISC,6
MOVLW B'00100100' ; Chon che do 8 bit, Hightbaudrate
MOVWF TXSTA
MOVLW D'25' ; Chon che do 9.600
MOVWF SPBRG
BSF PIE1,RCIE ; Cho phep ngat ( receive )
BANKSEL RCSTA
MOVLW B'10010000' ;
MOVWF RCSTA
RETURN
END ; directive 'end of program'
|