PIC 18F4431 USART Problema

1

Hace tiempo que uso felizmente un PIC 16F628A UART. Recientemente he cambiado a un chip PIC 18F4431 pero tengo algunos problemas con el USART. Inicialmente, no pude hacer que funcionara la función de transmisión, estaba transmitiendo pero a solo 0.8 V para condiciones altas. Extrañamente luego puse en estas líneas:

 movlw   0FFh
 movwf   PORTB 

y de repente comenzó a transmitirse correctamente y puedo recibir datos de forma correcta a través del UART en Pickit2. Lamentablemente ahora no puedo recibir nada a través del UART. He probado varios chips y todos muestran el mismo comportamiento.

He adjuntado mi código a continuación, ¿alguna idea?

include <P18f4431.INC>


CONFIG     OSC = IRC
CONFIG     FCMEN = OFF
CONFIG     IESO = OFF
CONFIG     PWRTEN = OFF
CONFIG     BOREN = OFF
CONFIG     BORV = 20
CONFIG     WDTEN = OFF
CONFIG     WDPS = 1
CONFIG     WINEN = OFF
CONFIG     PWMPIN = OFF
CONFIG     LPOL = LOW
CONFIG     T1OSCMX = OFF
CONFIG     FLTAMX = RC1
CONFIG     SSPMX = RD1
CONFIG     PWM4MX = RB5
CONFIG     EXCLKMX = RC3
CONFIG     MCLRE = ON
CONFIG     CP0 = OFF
CONFIG     CP1 = OFF
CONFIG     CP2 = OFF
CONFIG     CP3 = OFF
CONFIG     CPD = OFF
CONFIG     WRT1 = OFF
CONFIG     WRT2 = OFF
CONFIG     WRT3 = OFF
CONFIG     WRTC = OFF
CONFIG     WRTB = OFF
CONFIG     WRTD = OFF
CONFIG     EBTR0 = OFF
CONFIG     EBTR1 = OFF
CONFIG     EBTR2 = OFF
CONFIG     EBTR3 = OFF
CONFIG     EBTRB = OFF
CONFIG     HPOL = LOW
CONFIG     STVREN = OFF
CONFIG     DEBUG = OFF
CONFIG     CPB = OFF
CONFIG     WRT0 = OFF
CONFIG     LVP = OFF


    ;***********VARIABLE DEFINITIONS******************

Timer   res 1
Timer2  res 1
DataTemp1  res 1
DataTemp2  res 1
dataL   res 1

 ;*******************************************************************************
 ; Reset Vector
 ;*******************************************************************************

 STARTUP  CODE    0x00           ; processor reset vector
 GOTO    START                   ; go to beginning of program

org    0x0008
 GOTO    HIGH_ISR

 ;*******************************************************************************
 ; MAIN PROGRAM
 ;******************************************************************************

 PROG1 code

 START

 clrf PORTD
 clrf TRISD
 clrf LATB   ; clear portB output latches
 clrf TRISB  ; set all portB as outputs
 clrf TRISC   ;set all port C as outputs

 ;***********SET UP USART ***********************
 bsf TRISC, 7    ; Make RC7 an input
 bsf TRISC, 6
 bsf TRISC, 1
 movlw   d'12'     ;9600 baud at 8MHz
 movwf   SPBRG
 bsf TXSTA, TXEN     ; enable transmit
 bcf TXSTA, BRGH     ;de Select high baud rate
 bsf RCSTA, SPEN     ; enable serial port
 bsf RCSTA, CREN     ; Enable continuous reception
 bcf PIR1, RCIF      ; clear RCIF Interrupt Flag
 bsf PIE1, RCIE      ; Set RCIE Interrupt Enable
 bsf INTCON, PEIE    ; Enable peripheral interrupts
 bsf INTCON, GIE     ; Enable global interrupts

 movlw   0FFh
 movwf   PORTB  ; I don't know why I need to do this but this seems to be
               ; needed to kick start the USART !!!!!


 ;***********SET UP OSCILLATOR**************

 bsf   OSCCON, IRCF0
 bsf   OSCCON, IRCF1
 bsf   OSCCON, IRCF2

 ;***********MAIN ROUTINE **********************************

 ;********SETTLING TIME *************
 clrf    dataL
 settle: decfsz dataL, F
 goto settle
 ;*******flush the receive buffer**************
 movf RCREG, w
 movf RCREG, w
 movf RCREG, w

 ;turn on lamp to show power
  bsf PORTD, 1


 Loop:
  call Delay
  GOTO Loop                         ; loop forever


Delay:

 movlw   d'255'
 movwf   Timer
 movwf   Timer2

Loop2:
 nop
Loop1:
 nop
 decfsz Timer, f
 goto Loop1
 decfsz Timer2, f
 goto Loop2
 return


 HIGH_ISR

btfss   PIR1, RCIF  ;check if USART caused interrupt
goto OtherInt
btg     PORTD, 0
movlw   06h     ; mask unwanted bits
andwf   RCSTA,w    ;check for errors
btfss   STATUS,Z   ;was error status bit set?
goto    RCVError    ; Found error goto handler
movf    RCREG, w    ; get input data and stick it on w
movwf   LATB        ; Display on LEDs
movwf   TXREG       ; Echo character back
goto    ISREnd      ; go to end of ISR, restore context, return


RCVError
bcf RCSTA, CREN     ; clear receiver status
bsf RCSTA, CREN
movlw   0FFh    ; light all the LEDs
movwf   PORTB
goto ISREnd ; goto end of ISR

OtherInt
ISREnd

RETFIE

END
    
pregunta tommo2000

0 respuestas

Lea otras preguntas en las etiquetas