Richard,
Thanks for your time but .. if you have some more ... could you please take my sample above and correct it so it works ?
It's two days I'm turning crazy.
Anyway thank you
Marco
Richard,
Thanks for your time but .. if you have some more ... could you please take my sample above and correct it so it works ?
It's two days I'm turning crazy.
Anyway thank you
Marco
I do it this way , and use the bounds checking features of arraywriteCode:'pic18f45k20 '**************************************************************** '* Name : UNTITLED.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 4/14/2015 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** '* Name : UNTITLED.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 4/14/2015 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** #CONFIG CONFIG FOSC = INTIO67 CONFIG FCMEN = OFF CONFIG IESO = OFF CONFIG PWRT = OFF CONFIG BOREN = SBORDIS CONFIG BORV = 18 CONFIG WDTEN = ON CONFIG WDTPS = 512 CONFIG CCP2MX = PORTC CONFIG PBADEN = OFF CONFIG LPT1OSC = OFF CONFIG HFOFST = ON CONFIG MCLRE = ON CONFIG STVREN = ON CONFIG LVP = OFF CONFIG XINST = OFF CONFIG DEBUG = OFF CONFIG CP0 = OFF CONFIG CP1 = OFF CONFIG CP2 = OFF CONFIG CP3 = OFF CONFIG CPB = OFF CONFIG CPD = OFF CONFIG WRT0 = OFF CONFIG WRT1 = OFF CONFIG WRT2 = OFF CONFIG WRT3 = OFF CONFIG WRTC = OFF CONFIG WRTB = OFF CONFIG WRTD = OFF CONFIG EBTR0 = OFF CONFIG EBTR1 = OFF CONFIG EBTR2 = OFF CONFIG EBTR3 = OFF CONFIG EBTRB = OFF #ENDCONFIG define OSC 64 osccon=$70 '64 mhz OSCTUNE.6=1 pause 2000 Serout2 PORTb.7,84,["ready",13,10] Addr var word Char var byte cnt var byte inbuff var byte[30] buff var byte[30] Clear goto StartLoop ' Required String1: @ da "This is a string",0 AnotherString: @ da "Here is another string",0 '------------GetAddress Macro - Location insensitive ------------------------- ASM GetAddress macro Label, Wout ; Returns the Address of a Label as a Word CHK?RP Wout movlw low Label movwf Wout movlw High Label movwf Wout + 1 endm ENDASM StartLoop: ' This loop repeats continuously just as a test. @ GetAddress _String1, _Addr ' Get address of String cnt=0 gosub StringOut ' Send the String Serout2 PORTb.7,84, [13,10] ' New Line Serout2 PORTb.7,84, ["inbuff ",str inbuff\cnt ,13,10] ' New Line @ GetAddress _AnotherString, _Addr ' Get address of String cnt=0 gosub StringOut ' Send the String Serout2 PORTb.7,84,[13,10] ' New Line Serout2 PORTb.7,84, ["inbuff ",str inbuff\cnt ,13,10] ' New Line pause 500 goto StartLoop ' Repeat StringOut: ' Send the string out via Hserout Readcode Addr, Char ' Get a character if Char = 0 then StringDone ' Look for Null char, Stop if found buff[cnt]=char cnt=cnt+1 Serout2 PORTb.7,84, [Char] ' Send char Addr = Addr + 1 ' Point to next character goto StringOut ' Continue with rest of the string StringDone: ARRAYWRITE inbuff,cnt,,[str buff] return end
Well, any help is appreciated, so thank you anyway, but this is not what I'm asking.
My intent is not to use Arraywrite because consumes a lot of space.
With this sample code that now works I transfer a ROM string to an array, but I want also the destination array to be a parameter passed to the macro.
So with a single macro I could transfer to inbuff or testbuff or any buffer Is declared.
Code:Define USE_LFSR 1 DEFINE OSC 8 DEFINE DEBUG_REG PORTB DEFINE DEBUG_BIT 4 DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 0 OSCCON =%01110000 inbuff VAR BYTE[100] x VAR BYTE y VAR BYTE LS0 VAR WORD LS1 VAR WORD goto Lp1 ASM LoadInbuff macro Text CHK?RP _LS0 movlw low Text ; here I load in LS0 the ROM address of the source string movwf _LS0 movlw High Text movwf _LS0 + 1 L?CALL _Lstr endm ENDASM Lstr: y=0 do peekcode LS0, x inbuff(y)=x if x=0 then exit y=y+1 LS0=LS0+2 loop return Lp1: @ LoadInbuff _ROM_CfgString debug str inbuff\100,13,10 goto lp1 ROM_CfgString: PokeCode "This a test string",0
I understand but pbp does not allow pointers like in C . the only way I can see for this to be done is to have either a user cmd or asm code that actually mimics arraywrite's array loading method anyway .I'm sure something like that could be made accept a pointer to the array to be loaded .
I'm just having trouble seeing any point to this. my prog with arraywite 1041 bytes , with arraywrite commented out 951 bytes ,surely 90 bytes is pretty good I'm sure my asm attempts would be much worse than that
I have to ask why do this at all . I can't see a good reason to read a string from flash into ram ,surely its best shuffled off to its destination directly . if it needs to be altered before its used was it really a good move putting it in flash memory in the first place.
have a look at this thread post#50 where I update portions of an array with EXT modifiers and arraywrite . the fixed unchanging parts could be in flash
http://www.picbasic.co.uk/forum/showthread.php?t=19420
perhaps if you provide a little more detail .....
Hi Richard,
yes, strings need to be altered before use.
Well, I had about 3K free on 64k (PIC18F4680) and needed to add more code, so I was looking for some tricks to save space and make a diet to the actual code.
I have noted that if I substitute an arraywrite entry (for a string of about 100 char) with the method above, I save around 600 bytes of code. I have about 10 difefrent strings, so the total saved space is several KB.
To be honest I can't understand why there is so much difference between the two methods ....
Also I have noted this: in a blank project like the sample above, the difference between the two methods is about 150 bytes. Inside my 63KB project, the difference is more than 600 bytes.
So it probably depends where the instruction and the buffer are located (bank switching, etc). For thei sreason I wonder also if the method above with the macro is correct or can bring to unexpected behavours in some situations .....
For example: why did you say before "interrupts need to be disabled" ? Context is fully saved and restored in the interrupt routines. Also I use "PBP Instant Interrupt" of that great Darrel that should be bullet-proof.
Marco
I was thinking that if were to read the flash using TABLPU reg and index through the ram array using fsr0 then I'm not convinced that method is interrupt proofwhy did you say before "interrupts need to be disabled
but your not doing that anyway
I expect you realise that pokecode uses twice the memory to store a string compared to da
Last edited by richard; - 17th April 2015 at 08:52. Reason: got interrupted by customer / and lost plot
well, I was not understanding why I had to increment the pointer by two when reading data ...
I have subsituted now pokecode with da and peekcode with readcode and saved another kb .. thanks !
Marco
Bookmarks