EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Re: microchip's USART code..

Started by Ken Wilson January 18, 2003

Mitch,

 

            What is the name on the top of the dryer? How much electricity goes through it? If you can send me any of these things I’d appreciate it. Have you got the money yet? Hope so,

 

Ken



From:  "Charles Douvier" <>
Date:  Fri May 16, 2003  5:53 pm
Subject:  [piclist] microchip's USART code..
To:  "Piclist" <>

Microchip has a couple 18Fxxx usart code samples .. the one I chose for my
project was p18_tprp.asm. I chose polling because I'll pretty much know when
to expect to send or when I am going to be receiving information..

I can't tell if the information will be sent correctly if I dump what I want
to send in POSTINC1 and increment the TxByteCount. I don't know how POSTINC1
works.. since its not "really" a SFR per say its just mapped into the SFR ..
I assume I could just drop byte by byte into TXREG, but I like their code
and how they did it and I might want to use the TxBuffer so I could dump
some bytes into it quickly. Can I "cheat" and just movwf my byte into
POSTINC1 for now? I'll probably use their whole TxBuffer later on in project
development, but for now I just have one byte to send..

The code for transmitting data is:

TransmitSerial:      movf      TxByteCount,F      ;check if data to be transmitted
            btfsc      STATUS,Z
            return                  ;return if no data to be transmitted
            btfss      PIR1,TXIF      ;check if transmitter busy
            return                  ;return if transmitter busy

            movff      POSTINC1,TXREG      ;get the data and transmit
            decf      TxByteCount,F      ;decrement number of bytes left
            return they use this code.. to copy the RxBuffer to the TxBuffer I am not using
this code but this is why they are using POSTINC0, and POSTINC1 in the first
place I guess.
;---
-
;Copy data from receive buffer to transmit buffer to echo the line back.

;CopyRxToTx:      tstfsz      TxByteCount      ;check if TX buffer still has data
;            bra      ErrTxBufOver      ;error if previous TX is still busy
;            movff      RxByteCount,TxByteCount ;copy number of bytes
;            lfsr      1,TxBuffer      ;load start address of TX buffer
;            lfsr      0,RxBuffer      ;load start address of RX buffer
;CopyRxTx1:
;            movff      POSTINC0,POSTINC1 ;copy from RX buffer to TX buffer
;            decfsz      RxByteCount,F      ;decrement counter and see if all done
;            bra      CopyRxTx1      ;repeat if not done
;
;            lfsr      1,TxBuffer      ;load start address of TX buffer
;            lfsr      0,RxBuffer      ;load start address of RX buffer
;            bcf      Flags,ReceivedCR ;clear indicator for <CR> received
;            return



to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

">Yahoo! Terms of Service.

Please disregard last message

 

Ken

 



From:  "Charles Douvier" <>
Date:  Fri May 16, 2003  5:53 pm
Subject:  [piclist] microchip's USART code..
To:  "Piclist" <>

Microchip has a couple 18Fxxx usart code samples .. the one I chose for my
project was p18_tprp.asm. I chose polling because I'll pretty much know when
to expect to send or when I am going to be receiving information..

I can't tell if the information will be sent correctly if I dump what I want
to send in POSTINC1 and increment the TxByteCount. I don't know how POSTINC1
works.. since its not "really" a SFR per say its just mapped into the SFR ..
I assume I could just drop byte by byte into TXREG, but I like their code
and how they did it and I might want to use the TxBuffer so I could dump
some bytes into it quickly. Can I "cheat" and just movwf my byte into
POSTINC1 for now? I'll probably use their whole TxBuffer later on in project
development, but for now I just have one byte to send..

The code for transmitting data is:

TransmitSerial:      movf      TxByteCount,F      ;check if data to be transmitted
            btfsc      STATUS,Z
            return                  ;return if no data to be transmitted
            btfss      PIR1,TXIF      ;check if transmitter busy
            return                  ;return if transmitter busy

            movff      POSTINC1,TXREG      ;get the data and transmit
            decf      TxByteCount,F      ;decrement number of bytes left
            return they use this code.. to copy the RxBuffer to the TxBuffer I am not using
this code but this is why they are using POSTINC0, and POSTINC1 in the first
place I guess.
;---
-
;Copy data from receive buffer to transmit buffer to echo the line back.

;CopyRxToTx:      tstfsz      TxByteCount      ;check if TX buffer still has data
;            bra      ErrTxBufOver      ;error if previous TX is still busy
;            movff      RxByteCount,TxByteCount ;copy number of bytes
;            lfsr      1,TxBuffer      ;load start address of TX buffer
;            lfsr      0,RxBuffer      ;load start address of RX buffer
;CopyRxTx1:
;            movff      POSTINC0,POSTINC1 ;copy from RX buffer to TX buffer
;            decfsz      RxByteCount,F      ;decrement counter and see if all done
;            bra      CopyRxTx1      ;repeat if not done
;
;            lfsr      1,TxBuffer      ;load start address of TX buffer
;            lfsr      0,RxBuffer      ;load start address of RX buffer
;            bcf      Flags,ReceivedCR ;clear indicator for <CR> received
;            return



to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

">Yahoo! Terms of Service.

Microchip has a couple 18Fxxx usart code samples .. the one I chose for my
project was p18_tprp.asm. I chose polling because I'll pretty much know when
to expect to send or when I am going to be receiving information..

I can't tell if the information will be sent correctly if I dump what I want
to send in POSTINC1 and increment the TxByteCount. I don't know how POSTINC1
works.. since its not "really" a SFR per say its just mapped into the SFR ..
I assume I could just drop byte by byte into TXREG, but I like their code
and how they did it and I might want to use the TxBuffer so I could dump
some bytes into it quickly. Can I "cheat" and just movwf my byte into
POSTINC1 for now? I'll probably use their whole TxBuffer later on in project
development, but for now I just have one byte to send..

The code for transmitting data is:

TransmitSerial: movf TxByteCount,F ;check if data to be transmitted
btfsc STATUS,Z
return ;return if no data to be transmitted
btfss PIR1,TXIF ;check if transmitter busy
return ;return if transmitter busy

movff POSTINC1,TXREG ;get the data and transmit
decf TxByteCount,F ;decrement number of bytes left
return they use this code.. to copy the RxBuffer to the TxBuffer I am not using
this code but this is why they are using POSTINC0, and POSTINC1 in the first
place I guess.
;---
-
;Copy data from receive buffer to transmit buffer to echo the line back.

;CopyRxToTx: tstfsz TxByteCount ;check if TX buffer still has data
; bra ErrTxBufOver ;error if previous TX is still busy
; movff RxByteCount,TxByteCount ;copy number of bytes
; lfsr 1,TxBuffer ;load start address of TX buffer
; lfsr 0,RxBuffer ;load start address of RX buffer
;CopyRxTx1:
; movff POSTINC0,POSTINC1 ;copy from RX buffer to TX buffer
; decfsz RxByteCount,F ;decrement counter and see if all done
; bra CopyRxTx1 ;repeat if not done
;
; lfsr 1,TxBuffer ;load start address of TX buffer
; lfsr 0,RxBuffer ;load start address of RX buffer
; bcf Flags,ReceivedCR ;clear indicator for <CR> received
; return



POSTINCx and POSTDECx use the related FSRx register to access memory
indirectly and then increment or decrement the FSR register.

So, in older devices the programmer would load the address in FSR and
access the data in INDF and then increment FSR. With POSTINCx you
load FSR with the start of the data and access the data with POSTINCx
which grabs the data and increments FSR in one operation.

Refer to section 4.12.1 (pg 50) of the datasheet.

If you had a string of characters in RAM and you wanted to send them
to the serial port you could set FSRx to the beginning of the string
and grab the characters via POSTINCx before putting them in TXREG.
If the string in NULL terminated you could tell when to stop sending
them to TXREG. --- In , "Charles Douvier" <charles@k...>
wrote:
> Microchip has a couple 18Fxxx usart code samples .. the one I chose
for my
> project was p18_tprp.asm. I chose polling because I'll pretty much
know when
> to expect to send or when I am going to be receiving information..
>
> I can't tell if the information will be sent correctly if I dump
what I want
> to send in POSTINC1 and increment the TxByteCount. I don't know how
POSTINC1
> works.. since its not "really" a SFR per say its just mapped into
the SFR ..
> I assume I could just drop byte by byte into TXREG, but I like
their code
> and how they did it and I might want to use the TxBuffer so I could
dump
> some bytes into it quickly. Can I "cheat" and just movwf my byte
into
> POSTINC1 for now? I'll probably use their whole TxBuffer later on
in project
> development, but for now I just have one byte to send..
>
> The code for transmitting data is:
>
> TransmitSerial: movf TxByteCount,F ;check if data to be
transmitted
> btfsc STATUS,Z
> return ;return if no data to be
transmitted
> btfss PIR1,TXIF ;check if transmitter busy
> return ;return if transmitter busy
>
> movff POSTINC1,TXREG ;get the data and transmit
> decf TxByteCount,F ;decrement number of bytes
left
> return > they use this code.. to copy the RxBuffer to the TxBuffer I am not
using
> this code but this is why they are using POSTINC0, and POSTINC1 in
the first
> place I guess.
> ;-------------------------------
--------
> -
> ;Copy data from receive buffer to transmit buffer to echo the line
back.
>
> ;CopyRxToTx: tstfsz TxByteCount ;check if TX buffer still has
data
> ; bra ErrTxBufOver ;error if previous TX is
still busy
> ; movff RxByteCount,TxByteCount ;copy number of bytes
> ; lfsr 1,TxBuffer ;load start address of TX
buffer
> ; lfsr 0,RxBuffer ;load start address of RX
buffer
> ;CopyRxTx1:
> ; movff POSTINC0,POSTINC1 ;copy from RX buffer to TX
buffer
> ; decfsz RxByteCount,F ;decrement counter and see if
all done
> ; bra CopyRxTx1 ;repeat if not done
> ;
> ; lfsr 1,TxBuffer ;load start address of TX
buffer
> ; lfsr 0,RxBuffer ;load start address of RX
buffer
> ; bcf Flags,ReceivedCR ;clear indicator for <CR>
received
> ; return





The 2024 Embedded Online Conference