Can't do serial on a 16F1825

Thread Starter

Roto

Joined Jul 13, 2011
23
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:

BMorse

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

Rich (BB code):
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
 

BMorse

Joined Sep 26, 2009
2,675
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???....
 

t06afre

Joined May 11, 2009
5,936
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.
 

t06afre

Joined May 11, 2009
5,936
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???....
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
 

Thread Starter

Roto

Joined Jul 13, 2011
23
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.
 

t06afre

Joined May 11, 2009
5,936
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:

Thread Starter

Roto

Joined Jul 13, 2011
23
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.
 
Top