Can't do serial on a 16F1825

Discussion in 'Embedded Systems and Microcontrollers' started by Roto, Sep 12, 2011.

  1. Roto

    Thread Starter New Member

    Jul 13, 2011
    23
    0
    Hi Folks,

    I tried several times to post the following code on Microchip Forum.
    But it just kept taking out the line breaks and spaces even after I used their online editor?
    Anyway after I program this chip with the following (some parts removed to simplify the example) I can not find a serial output on any pin? It should be RC4 as far as I know?
    This editor has not been as bad but I have tried to indent with spaces for the lines within a subroutine but it took them out when I posted???


    list p=PIC16F1825
    #include <p16f1825.inc>


    __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF

    __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_25 & _LVP_OFF

    ORG 0x0000
    PAGESEL START
    GOTO START
    ORG 0x0004

    ;--INTERRUPT ROUTINE NOT INCLUDED BUT WORKING


    START
    call Set_Ports
    call INT_initialize ;(WORKING - NOT INCLUDED)
    call USART_initialize
    call USART_Baud_rate_adjust

    Main
    call Delay ;--- NOT INCLUDED (ABOUT 1/2 SEC.)
    call FlashPortC1 ;-- NOT INCLUDED (BUT WORKING)
    movlw 0x55
    movwf TXREG ; !!! NO OUTPUT ANYWHERE !!!
    goto Main


    Set_Ports
    banksel ANSELA
    clrf ANSELA
    banksel ANSELC
    clrf ANSELC
    banksel CM1CON0
    clrf CM1CON0
    banksel CM1CON1
    clrf CM1CON1
    banksel CM2CON0
    clrf CM2CON0
    banksel CM2CON1
    clrf CM2CON1
    banksel PORTA
    clrf PORTA
    banksel LATA
    clrf LATA
    banksel TRISA
    movlw b'00000000'
    movwf TRISA
    banksel PORTC
    clrf PORTC
    banksel LATC
    clrf LATC
    banksel TRISC
    movlw b'00100000'
    movwf TRISC
    banksel START
    return


    USART_initialize
    banksel TXSTA
    movlw b'00100000'
    movwf TXSTA
    banksel RCSTA
    movlw b'10010000'
    movwf RCSTA
    banksel START
    return


    USART_Baud_rate_adjust
    banksel SPBRGH
    movlw 0x00
    movwf SPBRGH
    banksel SPBRGL
    movlw 0x33
    movwf SPBRGL
    banksel START
    return

    END


    Yours,
    Colin Wilson
     
    Last edited: Sep 13, 2011
  2. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    Read the Sticky thread titled "Use of CODE tags".
     
  3. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    yeah, click on the Advanced button below the quick reply box and use the code tag (#) on the above menu.....

    Code ( (Unknown Language)):
    1. list                     p=PIC16F1825
    2.      #include             <p16f1825.inc>
    3.  
    4.  
    5.     __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF  & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF &  _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    6.  
    7.     __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_25 & _LVP_OFF
    8.  
    9.     ORG        0x0000
    10.     PAGESEL  START
    11.     GOTO      START
    12.     ORG        0x0004
    13.  
    14. ;--INTERRUPT ROUTINE NOT INCLUDED BUT WORKING
    15.  
    16.  
    17. [B]START[/B]
    18.    call    Set_Ports
    19.            call    INT_initialize          ;(WORKING - NOT INCLUDED)
    20.            call    USART_initialize
    21.    call    USART_Baud_rate_adjust
    22.  
    23. [B]Main[/B]
    24.            call    Delay          ;--- NOT INCLUDED (ABOUT 1/2 SEC.)
    25.    call    FlashPortC1  ;-- NOT INCLUDED (BUT WORKING)
    26.            movlw   0x55
    27.    movwf   TXREG     ; [B]!!! NO OUTPUT ANYWHERE !!![/B]
    28.            goto    Main
    29.  
    30.  
    31. [B]Set_Ports[/B]
    32.            banksel ANSELA
    33.            clrf       ANSELA
    34.            banksel ANSELC
    35.            clrf       ANSELC
    36. banksel CM1CON0
    37.            clrf       CM1CON0
    38.    banksel CM1CON1
    39.            clrf       CM1CON1
    40.            banksel CM2CON0
    41.            clrf       CM2CON0
    42.            banksel CM2CON1
    43.            clrf       CM2CON1
    44. banksel PORTA
    45.            clrf       PORTA
    46.            banksel LATA
    47.            clrf       LATA
    48.            banksel TRISA
    49.            movlw   b'00000000'
    50.            movwf  TRISA
    51.            banksel PORTC
    52.            clrf       PORTC
    53.            banksel LATC
    54.            clrf       LATC
    55.            banksel TRISC
    56.    movlw   b'00100000'
    57.    movwf  TRISC
    58.            banksel START
    59.            return
    60.  
    61.  
    62. [B]USART_initialize [/B]
    63.            banksel  TXSTA
    64.            movlw   b'00100000'
    65.            movwf   TXSTA
    66.            banksel  RCSTA
    67.            movlw   b'10010000'
    68.            movwf   RCSTA
    69.            banksel  START
    70.            return
    71.  
    72.  
    73. [B]USART_Baud_rate_adjust[/B]
    74.    banksel  SPBRGH
    75.            movlw   0x00
    76.            movwf   SPBRGH
    77.            banksel  SPBRGL
    78.            movlw   0x33
    79.            movwf   SPBRGL
    80.            banksel  START
    81.            return
    82.  
    83.    END
     
  4. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    According to the datasheet, USART RX pin is RB5, and USART TX pin is RB7., for the 20 Pin uC, which uC are you using?? 20 pin or 14 pin???....
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Hmm you need to make more comments on your code. Also what numbers have you used the setting up the baudrate generator. Are you sure you have used the correct CPU clock speed. In your calculations.
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Are you sure about this. As I can read from the data sheet it is RC5(RX) and RC4(TX). The PIC16F1825 do not have a PORTB
     
  7. Roto

    Thread Starter New Member

    Jul 13, 2011
    23
    0
    Yes this is the 14 pin and TX should be on RC4. But there's no output on any pin. I am not concern about the baud rate at the moment just want to see some output from the TX pin.
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Just one thing. You do know that you can nor connect your PIC directly to a real RS232 unit. You will need a TTL to RS232 level converter. Many use the a chip like MAX232 (or one of its derivates) for this task. Just Google max232
     
    Last edited: Sep 13, 2011
  9. Roto

    Thread Starter New Member

    Jul 13, 2011
    23
    0
    Thanks everyone.

    As it turns out the TXREG on the 16f1825 is not in bank0.
    So simply doing a banksel TXREG takes you to bank3 where this little register resides!
    This was thanks to user: 1and0 on the Microchip forum.
     
Loading...