please dont rip this site

PIC Specific RS232 routine

Bente Petersen's 9600baud 16F628 UART test circuit and program


UART test program for 16F628

Function
This program sends an alive message and then echoes characters received from a terminal via RS232.

Hardware
The testboard K4 is set up with reset circuit and a ST232 (or MAX232) for RS232 communication.


Testboard K4 configured for 628uart.asm

Software in assembler
;*******************************************************************
; Function:  Sends alive message, then echoes characters at 9600 bps
; Processor: PIC16F628 at 4 MHz using internal RC oscillator
; Hardware:  Testboard K4
; Filename:  628uart.asm
; Author:    Lars Petersen, oz1bxm@qsl.net
; Website:   www.qsl.net/oz1bxm/PIC/pic.htm
; Credit:    Tony Nixon's test program at
;            www.piclist.com/techref/microchip/16f877/setup.htm
;*******************************************************************

        LIST P=16F628, R=DEC    ; Use the PIC16F628 and decimal system

        #include "P16F628.INC"  ; Include header file

        __config  _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON

        CBLOCK 0x20             ; Declare variable addresses starting at 0x20
          dataL
        ENDC

        ORG    0x000            ; Program starts at 0x000
;
; --------------------------------
; SET ANALOG/DIGITAL INPUTS PORT A
; --------------------------------
;
        movlw 7
        movwf CMCON             ; CMCON=7 set comperators off
;
; ----------------
; INITIALIZE PORTS
; ----------------
;
        movlw b'00000000'       ; set up portA
        movwf PORTA

        movlw b'00000100'       ; RB2(TX)=1 others are 0
        movwf PORTB

        bsf STATUS,RP0          ; RAM PAGE 1

        movlw 0xFF
        movwf TRISA             ; portA all pins input

        movlw b'11110010'       ; RB7-RB4 and RB1(RX)=input, others output
        movwf TRISB

; ------------------------------------
; SET BAUD RATE TO COMMUNICATE WITH PC
; ------------------------------------
; Boot Baud Rate = 9600, No Parity, 1 Stop Bit
;
        movlw 0x19              ; 0x19=9600 bps (0x0C=19200 bps)
        movwf SPBRG
        movlw b'00100100'       ; brgh = high (2)
        movwf TXSTA             ; enable Async Transmission, set brgh

        bcf STATUS,RP0          ; RAM PAGE 0

        movlw b'10010000'       ; enable Async Reception
        movwf RCSTA
;
; ------------------------------------
; PROVIDE A SETTLING TIME FOR START UP
; ------------------------------------
;
        clrf dataL
settle  decfsz dataL,F
        goto settle

        movf RCREG,W
        movf RCREG,W
        movf RCREG,W            ; flush receive buffer
;
; ---------
; MAIN LOOP
; ---------
;
        call message            ; send "16F628 alive"
loop    call receive            ; wait for a char
        call send               ; send the char
        goto loop
;
; -------------------------------------------
; RECEIVE CHARACTER FROM RS232 AND STORE IN W
; -------------------------------------------
; This routine does not return until a character is received.
;
receive btfss PIR1,RCIF         ; (5) check for received data
        goto receive

        movf RCREG,W            ; save received data in W
        return
;
; -------------------------------------------------------------
; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING
; -------------------------------------------------------------
;
send    movwf TXREG             ; send data in W

TransWt bsf STATUS,RP0          ; RAM PAGE 1
WtHere  btfss TXSTA,TRMT        ; (1) transmission is complete if hi
        goto WtHere

        bcf STATUS,RP0          ; RAM PAGE 0
        return
;
; -------
; MESSAGE
; -------
;
message movlw  '1'
        call send
        movlw  '6'
        call send
        movlw  'F'
        call send
        movlw  '6'
        call send
        movlw  '2'
        call send
        movlw  '8'
        call send
        movlw  ' '
        call send
        movlw  'a'
        call send
        movlw  'l'
        call send
        movlw  'i'
        call send
        movlw  'v'
        call send
        movlw  'e'
        call send
        movlw  0x0D ; CR
        call send
        movlw  0x0A ; LF
        call send
        return

        END
Remarks
The ST232 is used for RS232 communication. An MAX232 can also be used. A simpler circuit can be set up using DS275, see the homepage of Wichit Sirichote from Thailand.
A terminal program (HyperTerminal) is set up for 9600 baud with 8 data bits, no parity, no flowcontrol and 1 stop bit.


Port settings in HyperTerminal


The alive message displayed in HyperTerminal

The same program written in C is here.

Download
Download 628art.zip containing the source code in assembler and the hexfile.

Credit
Tony Nixon's UART test program at http://www.piclist.com/techref/microchip/16f877/setup.htm was my source for the above program. Thanks!



This page created October 14th, 2002 by Lars Petersen, KILLspamoz1bxmspam at spamqsl.net

Back to PIC experiments
 

Questions:

Comments:


file: /Techref/microchip/16F/628/UARTtest.htm, 19KB, , updated: 2009/9/27 14:28, local time: 2024/12/26 22:50,
TOP NEW HELP FIND: 
3.15.223.129:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://ecomorder.com/Techref/microchip/16F/628/UARTtest.htm"> Bente Petersen's 9600baud 16F628 UART test circuit and program</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .