|
Posted by on June 27, 2006, 5:56 am
I thank you, all. I tried the solutions you suggeested me and I
found the mistake. Because of the fast incoming messages my usart
crashed. After every read operation, I reset the usart if there is an
error. And it works correct. Here is the full program, I also made some
changes with the configuration of USART. THANKS AGAIN
here is the code: It is working :)
#include <p16f877.inc>
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC &
_WRT_ENABLE_OFF & _LVP_OFF & _DEBUG_OFF & _CPD_OFF
cblock 0x70
temp
endc
org 0x0000
reset clrf PCLATH
goto main
NOP
NOP
irq nop
main: clrf STATUS ;main program
BSF STATUS,RP0 ;durum kontrolü için kullanilacak portb'nin
kosullanmasi
clrf TRISA ;HATA durumlarinin kontrol edilecegi kütük
clrf TRISD
BCF STATUS,RP0
call setUSART
CALL GPSAL ;gps'den gelen veriler 1dk süre ile alinir
RETURN
GPSAL: CALL set4800
MOVLW 0X00 ;for mutliplexer
movwf PORTD
A0: CALL RXget
MOVWF temp
CALL TXsend
MOVF temp,W
XORLW 'G'
BNZ A0
MOVLW '.'
CALL TXsend
MOVF temp,W
CALL TXsend
MOVLW 0XFF
MOVWF PORTA
goto GPSAL
RETURN
setUSART: bsf RCSTA,SPEN ; asyncron active
bsf RCSTA,CREN ; rx active
bsf STATUS,RP0 ;BANK1
bcf TXSTA,SYNC ;asyncron active
BSF TXSTA,TXEN ;tx active
BSF TXSTA,BRGH ;High Baud rate
movlw 0xc0 ;set tris bits for TX and RX
iorwf TRISC,F
BCF STATUS,RP0 ;AGAIN BANK0
RETURN
set4800: bsf STATUS,RP0
MOVLW D'51'
MOVWF SPBRG
BCF STATUS,RP0
RETURN
set19200: bsf STATUS,RP0
MOVLW D'12'
MOVWF SPBRG
BCF STATUS,RP0
RETURN
RXget:
getc1 btfSS PIR1,RCIF ; Skip if RC int flag set
goto getc1 ; Try again
btfsc RCSTA,OERR ;if overrun error occurred
goto ErrSerialOverr ; then go handle error
btfsc RCSTA,FERR ;if framing error occurred
goto ErrSerialFrame ; then go handle error
btfss RCSTA,RX9D ;if first stop bit error occurred
goto ErrSerialFrame ; then go handle error
movf RCREG,W ; Read the character
return
TXsend btfsS PIR1, TXIF
goto TXsend
movwf TXREG
bcf PIR1,TXIF ; Clear the interrupt flag
return
ErrSerialOverr:
bcf RCSTA,CREN ;reset the receiver logic
bsf RCSTA,CREN ;enable reception again
return
;error because FERR framing error bit is set or first stop bit is zero
;can do special error handling here - this code simply clears and
continues
ErrSerialFrame:
movf RCREG,W ;discard received data that has error
return
END
|