Moving Data to GP Registers Individually

Status
Not open for further replies.

Suraj143

Active Member
I want to move some data to some free GP registers individually. The data will update when every time in the process routine. Width contains the new data.

For ex: if process is done for 15 times it must contains 15 GP registers with different data.

Can anybody tell is this method is ok.


Thanks

Code:
	movlw	40h
	movwf	FSR
Process	---			;other work doing here
	---
	---
	---
	---
	---
	---
	movwf	Width		;contains new data

Update	incf	FSR,F		;increment the GP location
	movf	Width,W		;get a copy of Data
	movwf	INDF		;move to temporary GP registers
	goto	Process
 
Hi futz thanks for your reply.

The problem is I want to save this GP registers (with data) with a different name.

ex: if there are 15 data registers it must name as pulse1,pulse2,pulse3 etc.......

So pulse1 contains some data
pulse2 contains different data
like wise it must rename 15 items.

Thats the hardest part for me.

My first post shows how to save but i don't know how to call them & place in different name registers.

thanks
 
The "names" are just labels. They are just for your convenience. Just set aside the data space in your cblock with labels for ease of access to each byte. Then let the code index into the "array" (with indf and fsr) and store the data there. If I understand your explanation above correctly, it's very simple.

For instance:
Code:
	cblock	0x20
	pulse1, pulse2, pulse3, pulse4, pulse5, pulse6
	endc
allocates six consecutive bytes of RAM. You don't need to use the labels to access (write) these bytes. Just point your FSR to the first one and increment FSR each time you write to INDF.

If you want to access the bytes in random access fashion (not in consecutive order), just add the appropriate offset to your FSR index for each access.

You can also access the bytes using the labels if you wish.

If you need more space, you can also set aside words or multiple bytes per label in cblock. Just increment your FSR index appropriately when accessing.
 
Last edited:
Hi futz thanks for the explanation I understood.So I can directly access to data registers.Because they were in cblock.

Thanks a lot
 
Suraj143 said:
Hi futz thanks for the explanation I understood.So I can directly access to data registers.Because they were in cblock.
Ya, cblock is just a nice neat way to allocate blocks of RAM. If you need to you can do multiple cblocks, each pointing to different parts of RAM. The number after cblock is the address of the start of the block. Be sure to point to the proper address for the PIC you're using! Don't wipe out your SFR's!
 
Last edited:
Those SFR's will wipe out your GP's too Undesired symbiotic relationship.
Code:
	; Good for accessing individual elements.
	cblock (end of SFR)
	pulse, pulse2, pulse3, pulse4, pulse5, pulse6
	endc

	; Good for bulk access.
	; [register]:[byte count]
	cblock (end of SFR)
	pulse:6
	endc

	movlw	pulse		; Intitialize Pulse()
	movwf	FSR		; Pulse = Pulse(0)

Process	---			;other work doing here
	---
	---
	---
	---
	---
	---
	movwf	Width		;contains new data

Update	incf	FSR,F		; Pulse = (n + 1)
	movf	Width,W		; 
	movwf	INDF		; Pulse(n) = Width
	goto	Process

BusinesssEnd:
	; Where we access the individual elements directly.
	movf	pulse, w	; Push pulse to PortB.
	movwf	PortB
	movf	pulse2, w	; Push pulse2 to UART.
	movwf	TXreg
	movf	pulse3, w	; Push pulse3 to ...
	movwf	....
	return


Before the advent, my discover of, and will to use the 24F series here is one of my get it done techniques. When I had multiple nearly simultaneous access to different tables, a single FSR and INDF was not enough.
Code:
	cblock (end of SFR)
	pulse:6
	throb:6
	pulseoffset, throboffset
	endc

	movlw	pulse		; Initialize pulseoffset to Pulse(0)
	movwf	pulseoffset
	movlw	throb		; Initialize throboffset to Throb(0)
	movwf	throboffset	

UpdatePulse:
	movf	pulseoffset, w	; Accessing Pulse()
	movwf	FSR
	movf	Width,W		; 
	movwf	INDF		; Pulse(n) = Width	
	incf	pulseoffset	; Advance Pulse to (n + 1)

	; insert code to limit pulseoffset or reset to Pulse(0)
	return

UpdateThrob:
	movf	throboffset, w	; Accessing Throb()
	movwf	FSR
	movf	Width,W		; 
	movwf	INDF		; Throb(n) = Width	
	incf	throboffset	; Advance Throb to (n + 1)

	; insert code to limit throboffset or reset to Throb(0)
	return
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…