Autor Tema: RX no activa bandera en 16F887  (Leído 1353 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado LucasBols

  • PIC16
  • ***
  • Mensajes: 129
    • Desarrollos y Servicios Digitales
RX no activa bandera en 16F887
« en: 08 de Abril de 2009, 02:10:05 »
Hola

Tengo este código para la transmisión UART con la pc y tengo un problema con la bandera RCIF de PIR1, cuando el pic recibe un dato, se almacena en RCREG, la interrupción salta pero la bandera no se pone en alto.

¿Qué estoy haciendo mal?

Código: [Seleccionar]
;**********************************************************************

list p=16f887
#include <p16f887.inc>

;******************************************************************************

__CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG    _CONFIG2, _WRT_OFF & _BOR21V

;##############################################################################
; VECTORES ****
;**************

org 0x000
nop
  goto Inicio

org 0x004
goto SDI

;##############################################################################
; INTERRUPCIONES ****
;********************

SDI movwf w_temp
movf STATUS, w
movwf status_temp
movf PCLATH, w
movwf pclath_temp

SDI_RX
banksel PIR1
btfss PIR1, RCIF ; ¿se recibió un dato?
goto SDI_TX
banksel RCSTA
btfsc RCSTA, FERR ; error en el paquete
goto SDI_Fin
btfsc RCSTA, OERR ; error de desbordamiento
goto SDI_Fin
banksel RCREG
movf RCREG,W ; lee los datos recibidos
SDI_TX

SDI_Fin movf pclath_temp, w
movwf PCLATH
movf status_temp, w
movwf STATUS
swapf w_temp, f
swapf w_temp, w
retfie

;##############################################################################
; RUTINA PRINCIPAL ****
;**********************

Inicio
;---- Inicializa el PORTC -----------
Banco_0
clrf PORTC

Banco_1
movlw 0x80 ; RC7/RX como entrada
movwf TRISC

; 1. Initialize the SPBRGH, SPBRG register pair and the BRGH and BRG16 bits
; to achieve the desired baud rate
movlw 0x00
movwf SPBRGH
movlw 0x19
movwf SPBRG ; 9600 bps
bsf TXSTA, BRGH ; baudio alta velocidad
Banco_3
bcf BAUDCTL, BRG16 ; selecciona el generador de 8 bits ################

; 2. Enable the serial port by setting the SPEN bit.
; The SYNC bit must be clear for asynchronous operation.
Banco_1
bcf TXSTA, SYNC ; modo Asincrónico ################
Banco_0
bsf RCSTA, SPEN ; configura RC6/TX y RC7/RX como puerto serial

; 3. If interrupts are desired, set the RCIE bit of the PIE1 register
; and the GIE and PEIE bits of the INTCON register.
Banco_1
bsf INTCON, GIE ; activa las interrupciones generales
bsf INTCON, PEIE ; activa las interrupciones de los perifericos
bsf PIE1, RCIE ; activa la interrupción de recepción

; 4. If 9-bit reception is desired, set the RX9 bit.
Banco_0
bcf RCSTA, RX9

; 5. Enable reception by setting the CREN bit.
bsf RCSTA, CREN ; activa la recepción
Banco_1
bsf TXSTA, TXEN ; activa la transmisión

Banco_0
clrf cnt
estab
decfsz cnt,F
goto estab

movlw 0x14
movwf cnt
Inicio_Bucle
decfsz cnt
goto Inicio_Bucle_Cont
movf RCREG,W
movf RCREG,W
movf RCREG,W            ; vacía el buffer de recepción
goto Dormir
Inicio_Bucle_Cont
call Envia_Mensaje
goto Inicio_Bucle

;------------------------------------------------------------------------------

Envia_Mensaje
movlw "H"
call Enviar
movlw "o"
call Enviar
movlw "l"
call Enviar
movlw "a"
call Enviar
movlw "!"
call Enviar
movlw "!"
call Enviar
movlw "!"
call Enviar
movlw "!"
call Enviar
movlw 0x0D ; CR
call Enviar
movlw 0x0A ; LF
call Enviar
return

;------------------------------------------------------------------------------

Enviar
movwf TXREG
Banco_1
Enviar_Verif
btfss TXSTA, TRMT
goto Enviar_Verif

Banco_0
return

;##############################################################################
; DORMIR ****
;************

Dormir nop
goto Dormir

;##############################################################################

end

;##############################################################################

Muchas gracias.

Darío.-
Un experto es alguien que te explica algo sencillo de forma confusa de tal manera que te hace pensar que la confusión sea culpa tuya.

DSD http://www.dysd.com.ar/


 

anything