PIC 16F873A uart receive problem

Discussion in 'Embedded Systems and Microcontrollers' started by Haros, Dec 9, 2009.

  1. Haros

    Thread Starter New Member

    Dec 9, 2009
    1
    0
    Hello people, nice to find you.

    I have a problem receiving some characters typed in windows hyperterminal.

    my code (I excluded CBLOCK and CONFIG) is:

    Code ( (Unknown Language)):
    1.  
    2.     BSF STATUS,5
    3.     MOVLW 0X07
    4.     MOVWF CMCON     ;DISABLE ANALOG COMPARATORS
    5.     MOVLW 0X06
    6.     MOVWF ADCON1     ;PORTA DIGITAL PINS
    7.  
    8.     MOVLW 0X00
    9.     MOVWF TRISA
    10.     MOVLW 0X00
    11.     MOVWF TRISB
    12.     MOVLW B'10000000'
    13.     MOVWF TRISC
    14.  
    15.     MOVLW 0X19
    16.     MOVWF SPBRG   ;BAUD RATE 9600
    17.     MOVLW B'00100100'
    18.     MOVWF TXSTA
    19.     BCF STATUS,5
    20.     MOVLW B'10010000'
    21.     MOVWF RCSTA
    22.  
    23.     CLRF PORTA
    24.     CLRF PORTB
    25.     CLRF PORTC
    26.     CLRW
    27.     MOVF RCREG,W
    28.     MOVF RCREG,W    ;CLEAR RECEIVE BUFFER
    29.     MOVF RCREG,W
    30.  
    31.     MOVLW 'U'
    32.     CALL SEND
    33.     MOVLW 'P'
    34.     CALL SEND
    35.     MOVLW 0X0D
    36.     CALL SEND
    37.     MOVLW 0X0A
    38.     CALL SEND
    39.    
    40.     CALL RECEIVE
    41.     MOVLW 'P'   ;DEBUG ONLY
    42.     CALL SEND   ;DEBUG ONLY
    43.     MOVLW 0X0D  ;DEBUG ONLY
    44.     CALL SEND   ;DEBUG ONLY
    45.     MOVLW 0X0A  ;DEBUG ONLY
    46.     CALL SEND   ;DEBUG ONLY
    47.     SUBLW 'O'
    48.     BTFSS STATUS,Z
    49.     GOTO $-9
    50.     CALL RECEIVE
    51.     SUBLW 'K'
    52.     BTFSS STATUS,Z
    53.     GOTO $-3
    54.  
    55.     BSF PORTB,7
    56.  
    57. .
    58. .
    59. .
    60. .
    61.  
    62. RECEIVE
    63.     BTFSC PIR1,RCIF
    64.     GOTO $+15
    65.     MOVLW D'100'    ;DELAY CODE
    66.     MOVWF d1
    67.     MOVLW D'200'
    68.     MOVWF d2
    69.     NOP
    70.     NOP
    71.     DECFSZ d2,1
    72.     GOTO $-3
    73.     DECFSZ d1,1
    74.     GOTO $-7
    75.     MOVLW 0X00
    76.     MOVWF PORTA
    77.     BCF PORTB,6
    78.     GOTO RECEIVE
    79.     BCF PORTB,5 ;DEBUG ONLY YLW
    80.     MOVF RCREG,W    ;FETCH CODE
    81.     RETURN
    82.  
    83. SEND
    84.     MOVWF TXREG
    85.     BSF STATUS,5
    86.     BTFSS TXSTA, TRMT
    87.     GOTO $-1
    88.     BCF STATUS,5
    89.     RETURN
    90.  
    As you can see I am sending the word 'UP', that works fine.

    The problem is with receiving the word 'OK'... I type 'OK' in hyperterminal but nothing happens. When I type another character it seems like I am having an overflow or something (i guess the 3 character program breaking has to do something with the RCREG size).

    I tried to spot where the program breaks by placing the debug code you can see above. So now when I write a third character in hyperterminal I get an endless 'P' output in my terminal.

    I use an RC oscillator at 4mhz but I don't think that is the problem.

    Thank you in advance for your help.
     
Loading...