PIC Specific RS232 routine

Thomas C. Sefranek tcs at cmcorp.com says:

I have several working PICs now successfully driving Character strings.

ASSEMBLY SOURCE CODE

; A 20MHz Source is divided by 8 (Externally)
; producing a processor clock of 2.5 Mhz,
; the machine cycle clock is 625 Khz.
;
; USART clock = 2.5Mhz/64(1+1) = 19,531,25 Baud.
; (1.7% Error to 19,200 Baud)  BRGH=0

Init_PORTC      CLRF    PORTC           ; Clear all outputs.
                BSF     STATUS,RP0      ; Select Bank 1 Registers.
                MOVLW   B'11000000'     ; Form a byte to signify:
                                        ; Bits 7-6 as Inputs.
                                        ; Bit 5-0 as unused Outputs.
                MOVWF   TRISC           ; Set Port C as:
                                        ; RC<7> Serial Data In.
                                        ; RC<6> Serial Data Out.
                                        ; RC<5:0> not used.
                BCF     STATUS, RP0     ; Select Bank 0 Registers.

Init_USART      BSF     STATUS,RP0      ; Select Bank 1 Registers.
                MOVLW   1               ; Form a byte to signify 19.2 Baud rate.
                MOVWF   SPBRG           ; Set the Baud Rate Generator to 19.2 Baud Rate.
                BCF     STATUS,RP0      ; Select Bank 0 Registers.
                MOVLW   B'10010000'     ; Form a byte to signify:
                                        ; Bit 7 Serial Port enabled.
                                        ; Bit 6 Select 8 bit reception.
                                        ; Bit 5 Don't care.
                                        ; Bit 4 Enable continuous receive mode.
                                        ; Bit 3 Don't care.
                                        ; Bit 2 Framing Error.
                                        ; Bit 1 Overrun Error.
                                        ; Bit 0 9th bit.
                MOVWF   RCSTA           ; Initialize Receive Status and control register.
                BSF     STATUS,RP0      ; Select Bank 1 Registers.
                MOVLW   B'00100010'     ; Form a byte to signify:
                                        ; Bit 7 Don't care in Asynchronous mode.
                                        ; Bit 6 Select 8 bit transmission.
                                        ; Bit 5 Enable the transmitter.
                                        ; Bit 4 Select Asynchronous mode.
                                        ; Bit 3 Don't care.
                                        ; Bit 2 Select Low Speed BRG.
                                        ; Bit 1 Xmit Shift Reg. Empty.
                                        ; Bit 0 9th bit.
                MOVWF   TXSTA           ; Initialize Transmit Status/control register.
                BCF     STATUS,RP0      ; Select Bank 0 Registers.

;
;****************************** Print Character Routine
***********************
; Character is passed in "W".  If the transmitter is busy, characters
are saved
; in a FIFO.
;******************************************************************************
Print_Chr       BTFSC   FIFO_STATE,0    ; Is the FIFO in use?
                GOTO    Push_Chr        ; Yes, Push the character in the FIFO.
PR_Loop         BTFSC   PIR1,TXIF       ; No, Is the Transmitter busy?
                GOTO    Stuff_Chr       ; No, Send this character.
                BSF     STATUS,RP0      ; Yes, Select Bank 1 Registers.
                BTFSC   TXSTA,TRMT      ; Is the Shift register empty?
                GOTO    ReTest_TSR      ; Yes, Re-test for Initialization.
                BCF     STATUS, RP0     ; No, Select Bank 0 Registers.
                GOTO    Save_Chr        ; Push the character in the FIFO.
;
ReTest_TSR      BCF     STATUS, RP0     ; Select Bank 0 Registers.
                GOTO    PR_Loop         ; Yes, Look for it to clear.
;
Stuff_Chr       MOVWF   TXREG           ; No, Send this character.
                RETURN                  ; Done.
;
--
  *
  |  __O    Thomas C. Sefranek  tcs at cmcorp.com
  |_-\<,_   Amateur Radio Operator: WA1RHP
  (*)/ (*)  Bicycle mobile on 145.41, 448.625 Mhz

ARRL Instructor, Technical Specialist, VE Contact.
http://hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org

Onboard UARTS