usart in pic16f877a help!
hey everyone!
for the past few days i ve working on the usart peri on the pic16f877a....this is wht im trying to do...i ve connected two pic in synchronous mode with slave transmitter and master receiver..transmitting data from one, receiving in the other and connecting led to see if it working...transmitting data in CREN mode(continuous receive enabled). Theproblem is that data received is wrong...im been using mplab ide for the coding and proteus 6 professional to simulate this thingie...can u guys tell me if the problem is with the code...here goes my code
;;;;;slave transmitter
LIST P=16F877A
#INCLUDE P16F877A.INC
COUNT EQU 0X20
ORG 0X00
GOTO START
ORG 0X04
CALL ISR
GOTO ENDLOOP
START:
CLRF COUNT
BSF STATUS,RP0
BSF TRISC,6
BSF TRISC,7
BSF TXSTA,SYNC
BCF TXSTA,CSRC
BCF STATUS,RP0
BSF RCSTA,SPEN
BCF RCSTA,CREN
BCF RCSTA,SREN
BSF STATUS,RP0
BSF PIE1,TXIE ;enabling interrupts
BSF INTCON,PEIE ;enabling interrupts
BSF INTCON,GIE ;enabling interrupts
BSF TXSTA,TXEN
ISR:
BCF STATUS,RP0
BCF INTCON,GIE
INCF COUNT,1
MOVF COUNT,0 ; this is continuous data transmitting section
MOVWF TXREG
RETFIE
ENDLOOP:GOTO ENDLOOP
END
;;;master receiver
LIST P=16F877A
#INCLUDE P16F877A.INC
ORG 0X00
GOTO START
ORG 0X04
CALL ISR
GOTO LOOP
START:
MOVLW 0X21
MOVWF FSR
BSF STATUS,RP0
BSF TRISC,6
BSF TRISC,7
CLRF TRISD
MOVLW 0X67
MOVWF SPBRG
BSF TXSTA,CSRC
BSF TXSTA,SYNC
BCF STATUS,RP0
BCF RCSTA,SREN
BCF RCSTA,CREN
BSF RCSTA,SPEN
;INTERRUPTS
BSF STATUS,RP0
BSF PIE1,RCIE
BSF INTCON,PEIE
BSF INTCON,GIE
BSF RCSTA,CREN
ISR:
BCF STATUS,RP0
BCF INTCON,GIE
COUNT EQU 0X20
MOVLW 0X02
MOVWF COUNT
LOOP0:
MOVF RCREG,0
MOVWF PORTD ; moving the data from rcreg to portd where the leds are connected
BTFSS RCSTA,OERR ; checking for overrun error
CALL CHECK
BTFSS RCSTA,FERR
CALL CHECK1
DECFSZ COUNT,1 ;the manual says that rcreg is 2 bytes deep so doing the transfer twice
GOTO LOOP0
GOTO ENDLOOP
CHECK:
CLRF RCREG
BCF RCSTA,CREN
BSF RCSTA,CREN
RETURN
CHECK1:
BCF RCSTA,FERR
RETURN
ENDLOOP:
RETFIE
LOOP:GOTO LOOP
END