please dont rip this site

PIC Specific RS232 IO Routine

for 16F877

by Claudio Rachiele

    Title  "USART TESTER"
     ;
     ; Author  Claudio RACHIELE IW0DZG
     ;
     ; Working  20000318
     ;
     list p=16f877,c=140    ; processor type
     errorlevel          1, -(305)
     #include "p16f877.inc"
     __CONFIG  _PWRTE_ON&_HS_OSC&_LVP_OFF&_WDT_OFF

temp  equ   7Fh               ;
;
; -----------
; DESCRIPTION
; -----------
;
; Baud Rate = 9600, No Parity, 8 bits & 1 Stop Bit
;
; -------------
; PROGRAM START
; -------------
;
     org  0         ; startup = 0000H
     clrf STATUS         ; bank 0
     goto BootStart
     org  4
ISR  goto 5         ;
     org  5
;
; --------------------------------------------------
; SET UP THE PORTS TO SUIT YOUR CIRCUIT REQUIREMENTS
; --------------------------------------------------
;

BootStart
     banksel PORTA       ; bank0
     movlw     b'00000000'
     movwf     PORTA
     movlw     b'00000000'
     movwf     PORTB
     movlw     b'01000000'
     movwf     PORTC
     movlw     b'00000000'
     movwf     PORTD
     movlw     b'00000000'
     movwf     PORTE

     banksel TRISA       ; bank1
     movlw     b'00000001'
     movwf     TRISA
     movlw     b'00000000'
     movwf     TRISB
     movlw     b'11000000'    ; set RC6 & RC7 as input
     movwf     TRISC
     movlw     b'00000000'
     movwf     TRISD
     movlw     b'11101000'
     movwf     TRISE
     movlw     b'00000111'
     movwf     ADCON1         ; porta inputs = digital not analog
;
; BAUD RATE SETTINGS
;
                    ;  Baud Values with BRGH = 0
                    ;  ((20000000/9600)/64)-1 = 32
;    movlw     d'207'    ;  1200 baud @ 16 Mhz Fosc +0.16 err
;    movlw     d'103'          ;  2400 baud @ 16 Mhz Fosc +0.16 err
;    movlw     d'25'           ;  9600 baud @ 16 Mhz Fosc +0.16 err
;    movlw     d'12'           ; 19200 baud @ 16 Mhz Fosc +0.16 err
;    movlw     d'255'          ;  1200 baud @ 20 Mhz Fosc +1.73 err
;    movlw     d'129'          ;  2400 baud @ 20 Mhz Fosc +0.16 err
;    movlw     d'32'          ;  9600 baud @ 20 Mhz Fosc -1.36 err
;    movlw     d'15'          ; 19200 baud @ 20 Mhz Fosc +1.73 err

                    ;  Baud Values with BRGH = 1
                    ;  ((20000000/9600)/16)-1 = 32
     movlw     d'129'         ;  9600 baud @ 20 Mhz Fosc +0.16 err
     movwf     SPBRG
     movlw     b'00100100'    ; brgh = 1
     movwf     TXSTA           ; enable Async Transmission, set brgh
     banksel RCSTA       ; bank0
     movlw     b'10010000'
     movwf     RCSTA          ; enable Async Reception
     movf RCREG,w
     movf RCREG,w
     movf RCREG,w        ; flush receive buffer
;
;
; ------------------------------------
; PROVIDE A SETTLING TIME FOR START UP
; ------------------------------------
;
     clrf temp
Settle
     decfsz  temp
     goto Settle

LWaitCom
     call      RecLoop         ; wait and read from RS232
     movwf     PORTB          ; show value for diagnostic purpose
TxLoop
     nop
     btfss     PIR1,TXIF ;xmit buffer empty?
     goto TxLoop         ;no, wait

     movwf     TXREG

     goto LWaitCom  ; no
;
; ----------------------------
; RECEIVE CHARACTER FROM RS232
; ----------------------------
; This routine does not return until a character is received.

RecLoop
     nop
     btfss     PIR1,RCIF ; check for received data
     goto RecLoop
     movf RCREG,w
     return
     end

Questions:

Comments:


file: /Techref/microchip/16F877/rs232-cr.htm, 4KB, , updated: 2009/4/30 12:18, local time: 2024/12/22 07:12,
TOP NEW HELP FIND: 
3.23.102.79: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://massmind.ecomorder.com/Techref/microchip/16F877/rs232-cr.htm"> PIC Specific RS232 IO</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 massmind.ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .