os códigos:
**transmissor************
INICIO
BANK0
CLRF PORTA
CLRF PORTB
CLRF PORTC
CLRF PORTD
CLRF RCSTA
BSF RCSTA,7
BANK1
MOVLW B'111111'
MOVWF TRISA
MOVLW B'00000000'
MOVWF TRISB
MOVLW B'00000000'
MOVWF TRISC
MOVLW B'11111111'
MOVWF TRISD
MOVLW B'111'
MOVLW B'10000100'
MOVWF OPTION_REG
MOVLW B'00000000'
MOVWF INTCON
MOVLW .25
MOVWF SPBRG ;BAUD RATE
MOVLW B'00100100'
MOVWF TXSTA
MOVLW B'01000000'
MOVWF ADCON1
BANK0
MOVLW B'00000111'
MOVWF CMCON
MOVLW B'11000001'
MOVWF ADCON0
;ROTINA PRINCIPAL
START
TRANSMISSAO
BANK1
BCF TXSTA, TRMT
BANK0
MOVLW B'10101010'
MOVWF TXREG
GOTO START
***receptor***************
CLRF PORTA
MOVLW D'7'
MOVWF CMCON ;
BSF STATUS,RP0
CLRF TRISA
BSF TRISB,4
BCF OPTION_REG,7
;—Configure peripheral interrupts
MOVLW B'00100000' ;Disable all peripheral interrupts except receiver
MOVWF PIE1 ;Peripheral interrupt enable/disable
;—Configure general interrupts
MOVLW B'01000000' ;Disable all interrupts except peripheral
MOVWF INTCON ;Interrupt control register
;—Configure SPBRG for desired baud rate
MOVLW D'25' ;We will use 9600
MOVWF SPBRG ;baud at 4MHz
;—Configure TXSTA
MOVLW B'00100100' ;Configure TXSTA as :
MOVWF TXSTA ;
;8 bit transmission – 6.bit
;Transmit enabled – 5.bit
;Asynchronous mode – 4.bit
;Enable high speed baud rate – 2.bit
BCF STATUS,RP0 ;Switch to BANK0
MOVLW B'10000000' ;Enable serial port
MOVWF RCSTA ;Receive status reg
CLRF TMP_TX
BSF INTCON,7 ;Enable all unmasked interrupts
BSF RCSTA,4 ;Enable USART receive
MAIN_LOOP: ;Continous loop
BTFSC PORTB,4 ;Check if the button is pressed
GOTO MAIN_LOOP ;If not goto continous loop
MOVF TMP_TX,W ;Load TMP_TX
MOVWF TXREG ;to TXREG
;We load TMP_TX on the interrupt routine,
;when an information received from RX.
GOTO MAIN_LOOP ;Continous loop
interrupt:
BCF INTCON,7 ;Disable all interrupts
BTFSS PIR1,5 ;Check if the RCIF flag is set
GOTO quit_int ;If not return back to the main loop
MOVF RCREG,W ;Move the received byte to W
MOVWF PORTA ;Move W to PORTA
MOVWF TMP_TX
BCF PIR1,5
quit_int:
RETFIE