Hi !
This program is for UART connection between 16f877 and 16f877. Its working OK as long as connection is Ok. As soon as i break connection TX-RX and make it again all freezes .
How Can I improve program so theese two PICs can restore communication after connection breakes. This is very important to my circuit.
Transmiter code:
;---------------------------------------------------------------------------
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
banksel TRISB
movlw 0ffh
movwf TRISB
movwf TRISC
movlw 00h
movwf TRISA
movlw b'00000110' ; all analog pins = digital
movwf ADCON1
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
banksel SPBRG
movlw 0x0C
movwf SPBRG
movlw b'00100100'
movwf TXSTA
bcf PIE1,TXIE
bcf PIE1,RCIE
banksel RCSTA
movlw b'10010000'
movwf RCSTA
;---------------------------------------------------------------------------
Main
call Trans
call Receive
goto Main
Receive
banksel PIR1
btfss PIR1,RCIF
goto Receive
movf RCREG,W
movwf PORTA
return
Trans
banksel PORTB
movf PORTB,W
movwf TXREG
banksel TXSTA
WtHere btfss TXSTA,TRMT
goto WtHere
return
;---------------------------------------------------------------------------
end
Receiver code:
;---------------------------------------------------------------------------
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
banksel TRISB
movlw 0ffh
movwf TRISA
movwf TRISC
movlw 00h
movwf TRISB
movlw b'00000110' ; all analog pins = digital
movwf ADCON1
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
banksel SPBRG
movlw 0x0C
movwf SPBRG
movlw b'00100100'
movwf TXSTA
bcf PIE1,TXIE
bcf PIE1,RCIE
banksel RCSTA
movlw b'10010000'
movwf RCSTA
;---------------------------------------------------------------------------
Main
call Receive
call Trans
goto Main
Receive
banksel PIR1
btfss PIR1,RCIF
goto Receive
movf RCREG,W
movwf PORTB
return
Trans
banksel PORTB
movf PORTA,W
movwf TXREG
banksel TXSTA
WtHere btfss TXSTA,TRMT
goto WtHere
return
;---------------------------------------------------------------------------
end
This program is for UART connection between 16f877 and 16f877. Its working OK as long as connection is Ok. As soon as i break connection TX-RX and make it again all freezes .
How Can I improve program so theese two PICs can restore communication after connection breakes. This is very important to my circuit.
Transmiter code:
;---------------------------------------------------------------------------
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
banksel TRISB
movlw 0ffh
movwf TRISB
movwf TRISC
movlw 00h
movwf TRISA
movlw b'00000110' ; all analog pins = digital
movwf ADCON1
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
banksel SPBRG
movlw 0x0C
movwf SPBRG
movlw b'00100100'
movwf TXSTA
bcf PIE1,TXIE
bcf PIE1,RCIE
banksel RCSTA
movlw b'10010000'
movwf RCSTA
;---------------------------------------------------------------------------
Main
call Trans
call Receive
goto Main
Receive
banksel PIR1
btfss PIR1,RCIF
goto Receive
movf RCREG,W
movwf PORTA
return
Trans
banksel PORTB
movf PORTB,W
movwf TXREG
banksel TXSTA
WtHere btfss TXSTA,TRMT
goto WtHere
return
;---------------------------------------------------------------------------
end
Receiver code:
;---------------------------------------------------------------------------
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
banksel TRISB
movlw 0ffh
movwf TRISA
movwf TRISC
movlw 00h
movwf TRISB
movlw b'00000110' ; all analog pins = digital
movwf ADCON1
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
banksel SPBRG
movlw 0x0C
movwf SPBRG
movlw b'00100100'
movwf TXSTA
bcf PIE1,TXIE
bcf PIE1,RCIE
banksel RCSTA
movlw b'10010000'
movwf RCSTA
;---------------------------------------------------------------------------
Main
call Receive
call Trans
goto Main
Receive
banksel PIR1
btfss PIR1,RCIF
goto Receive
movf RCREG,W
movwf PORTB
return
Trans
banksel PORTB
movf PORTA,W
movwf TXREG
banksel TXSTA
WtHere btfss TXSTA,TRMT
goto WtHere
return
;---------------------------------------------------------------------------
end