I am trying to communicate two 16f877 .
It works like this:
PIC1: It reads PORTB and sends that data to PIC2, then it reads RCREG to see if other PIC2 has sent some data, and sends that data to PORTA.
PIC2: It reads RCREG to see if other PIC2 has sent some data and then reads PORTA and sends that data to PIC1.
But is not working. What is wrong with this code. Can't get it.
The code is :
;---------------------------------------------------------------------------
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
banksel TRISB
movlw 0ffh
movwf TRISB
movlw 00h
movwf TRISA
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
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
It works like this:
PIC1: It reads PORTB and sends that data to PIC2, then it reads RCREG to see if other PIC2 has sent some data, and sends that data to PORTA.
PIC2: It reads RCREG to see if other PIC2 has sent some data and then reads PORTA and sends that data to PIC1.
But is not working. What is wrong with this code. Can't get it.
The code is :
;---------------------------------------------------------------------------
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
errorlevel -302, -207
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
banksel TRISB
movlw 0ffh
movwf TRISB
movlw 00h
movwf TRISA
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
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