Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

assembly code for transmitting data in PIC memory

Status
Not open for further replies.

ceibawx

Junior Member level 2
Joined
Oct 13, 2008
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
chongqing,China
Activity points
1,606
pic txif

Who can help me check it?
I stored data in PIC, but output is not correct.


TransData:
MOVLW 0xBF
MOVWF FSR ; TO RAM
MOVLW 0x08
MOVWF ChannelCounter ; ChannelCounter=4*2

GoOnTransData:
bsf STATUS,5
MOVF INDF,W
bcf STATUS,5
MOVWF TXREG ; Move the data to the transmit register
bsf STATUS,5
INCF FSR,1 ; INDF address number moves next
DECFSZ ChannelCounter,1 ; ChannelCounter-1
goto GoOnTransData ; cc!=0.
goto ReProcess ; cc=0.tx finish, start a new rx.
 

res asm pic memory

I think your problem is that you are overwriting the TXREG. You need to test the TXIF flag to see when the TXREG is empty ant then load the new byte.
See below for a possible fix. I assume the UART setup was done correctly, that is the TXEN bit was set. That will set TXIF. Make sure you use bsf to set TXEN, rather than writing to the register. You can add that instruction just before the GoOnTransData, if it was not done before.

By the way, since you are using the FSR, you do not need to set and clear the RP0 bit; the FSR is able to access the correct data within banks 0 and 1 with IRP=0, regardless of the state of RP0,1.

Code:
TransData: 
MOVLW 0xBF 
MOVWF FSR ; TO RAM 
MOVLW 0x08 
MOVWF ChannelCounter ; ChannelCounter=4*2 

bsf STATUS,RP0   ;bank 1
bsf TXSTA,TXEN   ;enable xmit
bcf STATUS,Rp0   ;bank 0 again

GoOnTransData: 
btfss PIR1,TXIF    ;check if we can send new byte
goto GoOnTransData

MOVF INDF,W      ; get byte
MOVWF TXREG    ; Move the data to the transmit register 
INCF FSR,1          ; INDF address number moves next 
DECFSZ ChannelCounter,1 ; ChannelCounter-1 
goto GoOnTransData ; cc!=0. 
goto ReProcess    ; cc=0.tx finish, start a new rx.
 

Thanks for your reply.
My question is that what does it mean?

when TXIF=1, buffer is empty, it will ---------------------
MOVF INDF,W ; get byte
MOVWF TXREG ; Move the data to the transmit register
when TXIF=0, buffer is full, it will ------------------------
GoOnTransData:
btfss PIR1,TXIF ;check if we can send new byte
goto GoOnTransData.

Can you explain more detail about transmit buffer? if it is still full, we have to wait for it until it is empty?
 

Yes, it means the transmit buffer is empty and you can write a new byte to it. If you do it before it's empty, then your write will be ignored and you will lose characters.

Setting TXEN will set TXIF, alowing the code to run for the first character you send. Afterwards, you have to wait for the previous character transmission to complete. As soon as you write to TXREG, TXIF will be cleared, so if you check this bit you will not be able to write a new byte to TXREG until it's empty.

For more info, read the attachment
 

Thanks a lot.
And I have tested , and your code is useful, and I received the expected data.

You are powerful.
Good day.


Xing
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top