View Full Version : some help with math
longpole001
- 28th August 2015, 05:28
Hi guys i need to make this table of value in code
count byte code end value
1 -1 0 0
2 1 42
3 2 84
4 3 126
5 4 168
6 5 210
7 -7 0 0
8 1 42
9 2 84
10 3 126
11 4 168
12 5 210
13 -13 0 0
14 1 42
15 2 84
16 3 126
17 4 168
18 5 210
19 -19 0 0
20 1 42
21 2 84
22 3 126
23 4 168
24 5 210
25 -25 0 0
26 1 42
27 2 84
28 3 126
29 4 168
30 5 210
code attempt
Data_Length = 42 ' 38chrs + 4 byte setting - required varable for spi flash routine
SDC_Page = 129 + (Menu_Subtxt-1)/6 ' page start point + 1 page per each 6 subtxt placed
IF Menu_subtxt-1 //6 = 0 THEN
SDC_Byte = 0
ELSE
SDC_Byte = (Menu_Subtxt-1)+6 *6 + (Menu_Subtxt-1)-6 *6 /6 * Data_Length ' byte start point per data length
ENDIF
longpole001
- 28th August 2015, 06:21
count in the table is Menu_subtxt varable
end code in the table is the value of SDC_Byte
byte code in table the intrum caculation prior to mulitply data length
HenrikOlsson
- 28th August 2015, 07:26
Try
EndValue = ((Count - 1) // 6) * 42
Is that what you want?
/Henrik.
longpole001
- 28th August 2015, 07:37
OMG - gee i been playing with hours and i have variations of this same code but it did not work , THANKYOU hendrick , sometime you cant see the wood for the trees
longpole001
- 28th August 2015, 07:46
end code
- it is used to put 42 bytes into flash per page of 256 bytes of data
Data_Length = 42 ' 38chrs + 4 byte setting - required varable for spi flash routine
SDC_Page = 129 + (Menu_Subtxt-1)/6 ' page start point + 1 page per each 6 subtxt placed
IF Menu_subtxt-1 //6 = 0 THEN
SDC_Byte = 0 ' set byte to 0 when Menu_subtxt = 7, 13, 19etc
ELSE
SDC_Byte = ((Menu_Subtxt-1)//6) * Data_Length ' byte start point per data length
ENDIF
HSEROUT ["write SDC_Page = ",dec SDC_Page ,", SDC_Byte = ",dec SDC_Byte,13,10 ]
gosub Flash_Font_Common_write ' use flash font common write to save subtxt data
return
HenrikOlsson
- 28th August 2015, 08:01
Hi,
I don't think you need the IF/ELSE/ENDIF block in there. SDC_Byte = ((Menu_Subtxt-1)//6) * Data_Length should work fine even when Menu_Subtxt - 1 equals 0.
/Henrik.
longpole001
- 28th August 2015, 08:14
yes your correct hendrick have removed the if/else statements
longpole001
- 28th August 2015, 20:38
i think what threw me in my thinking hendrick was that the math command of "//" remainder (modulus) in that i have only ever used it to test for the remainder value of 0 or 1 being true /false in a if statement , not to use the remainder value directly
longpole001
- 2nd September 2015, 23:26
and the maths eqivalant of this
lookup gl_i,[24,32,40,24,32,40,24,32,40,24,32,40],gl_y ' menu row lines 8,24,32,40 for gl_y
gl_y = 24+ (gl_i//3 *8) ????
HenrikOlsson
- 3rd September 2015, 08:01
Hi,
Have you tried it, doesn't it work?
Looks alright to me at first glance.
/Henrik.
longpole001
- 3rd September 2015, 08:35
no not tried it just looked wrong
longpole001
- 3rd September 2015, 10:16
it appears to work , i have about 10 of these lookups , looking to save space
Art
- 8th September 2015, 19:53
Better?
gl_y = 24+((gl_i//3)*8)
Don’t know if you get screwed over for gl_i less than 3 though.
I’d expect PBP gives you zero modulus for a value less than 1.
longpole001
- 9th September 2015, 00:20
gives 0 when less then 3
Art
- 9th September 2015, 05:01
If you have to check for <3 as well you might be approaching the code size of the lookup table.
Are all the lookup tables repeating like this? It’s the sort of problem I like,
certianly a mind F* though.
longpole001
- 10th September 2015, 05:14
well i been going though my code and i had about 35 lookup tables in various values and size , most have been changed now to math calculation , most were of simular in how they need to place font, chrs , on a glcd within menus
the goal is to reduce code size as lookups really do chew up space
this along with change any IF /then to a math caclulation where possible
removing any multi if /then when used to compare to for/next loop compare
moving bit varables into the same byte to use bit matching on them
remove any "and " in if/then and just doing 2 if/then statements - this often saved about 50 bytes each
moving any lookup "txt into spi flash so it not on the main cpu flash
all these saved so far a total of 33k from a code that started at 127k
still trying more space as i really would like to get to 90k code before i add the next section
found pokecode has a limit of 256 bytes before for adata string ,
and this i cant find a better way to do to reduce its compile size
if val < 6 AND Menu_Select = 211 then
lookup val,[1,2,4,8,16,32],val ' reasign val to
gosub Show_current_sel_2 ' place "* *" on the selected channel in menu using bit pattern sleection
endif
if val =>6 and val <= 11 and Menu_Select = 2112 then
lookup val-6,[1,2,4,8,16,32],val
gosub Show_current_sel_2
endif
if val =>12 and Menu_Select = 2113 then
lookup val-12,[1,2,4,8,16,32],val
gosub Show_current_sel_2
endif
i am also ll stuck with a lot of if then statements when input range checks are done when a key is pressed such as
and i cant see away to reduce them
Input_Timevalue_Check:
' input checks for time inputs from menu1111
if Event1_OT_Day >7 then
Event1_OT_Day = 0
Event1_OT_hour = 0
Event1_OT_Min = 0
Event1_OT_sec = 0
Event1_OT_100th = 0
ENDIF
if Countdwn_Day > 7 then
Countdwn_Day = 0 ' day settings
Countdwn_Hour = 0
Countdwn_Min = 0
Countdwn_Sec = 0
Countdwn_100th = 0
ENDIF
if Event_Penalty_Day >7 then
Event_Penalty_Day = 0
Event_Penalty_Hour = 0
Event_Penalty_Min = 0
Event_Penalty_Sec = 0
Event_Penalty_100th = 0
ENDIF
if Event2_OT_Day >7 then
Event2_OT_Day = 0
Event2_OT_hour = 0
Event2_OT_Min = 0
Event2_OT_sec = 0
Event2_OT_100th = 0
ENDIF
if Preset_EL0_Day >7 then
Preset_EL0_Day = 0
Preset_EL0_Hour = 0
Preset_EL0_Min = 0
Preset_EL0_Sec = 0
Preset_EL0_100th = 0
ENDIF
if Event1_OT_Hour >23 then Event1_OT_Hour = 23
if Countdwn_Hour >23 then Countdwn_Hour = 23
if Event_Penalty_Hour > 23 then Event_Penalty_Hour = 23
if Event2_OT_Hour > 23 then Event2_OT_Hour = 23
if Preset_EL0_Hour > 23 then Preset_EL0_Hour = 23
if Event1_OT_Hour <1 then Event1_OT_Hour = 0
if Countdwn_Hour <1 then Countdwn_Hour = 0
if Event_Penalty_Hour <1 then Event_Penalty_Hour = 0
if Event2_OT_Hour <1 then Event2_OT_Hour = 0
if Preset_EL0_Hour <1 then Preset_EL0_Hour = 0
if Event1_OT_Min >59 then Event1_OT_Min = 59
if Countdwn_Min > 59 then Countdwn_Min = 59
if Event_Penalty_Min > 59 then Event_Penalty_Min = 59
if Event2_OT_Min >59 then Event2_OT_Min = 59
if Preset_EL0_Min >59 then Preset_EL0_Min = 59
if Event1_OT_Min <1 then Event1_OT_Min = 0
if Countdwn_Min <1 then Countdwn_Min = 0
if Event_Penalty_Min <1 then Event_Penalty_Min = 0
if Event2_OT_Min <1 then Event2_OT_Min = 0
if Preset_EL0_Min <1 then Preset_EL0_Min = 0
if Event1_OT_Sec >59 then Event1_OT_Sec = 59
if Countdwn_Sec >59 then Countdwn_Sec = 59
if Event_Penalty_Sec >59 then Event_Penalty_Sec = 59
if Event2_OT_Sec > 59 then Event2_OT_Sec = 59
if Preset_EL0_Sec > 59 then Preset_EL0_Sec = 59
if Event1_OT_Sec <1 then Event1_OT_Sec = 0
if Countdwn_Sec <1 then Countdwn_Sec = 0
if Event_Penalty_Sec <1 then Event_Penalty_Sec = 0
if Event2_OT_Sec <1 then Event2_OT_Sec = 0
if Preset_EL0_Sec <1 then Preset_EL0_Sec = 0
if Event1_OT_100th > 99 then Event1_OT_100th = 99
if Countdwn_100th > 99 then Countdwn_100th = 99
if Event_Penalty_100th >99 then Event_Penalty_100th = 99
if Event2_OT_100th > 99 then Event2_OT_100th = 99
if Preset_EL0_100th > 99 then Preset_EL0_100th = 99
if Event1_OT_100th <1 then Event1_OT_100th = 0
if Countdwn_100th <1 then Countdwn_100th = 0
if Event_Penalty_100th <1 then Event_Penalty_100th = 0
if Event2_OT_100th <1 then Event2_OT_100th = 0
if Preset_EL0_100th <1 then Preset_EL0_100th = 0
return
richard
- 10th September 2015, 06:58
I expect you realise that pokecode uses twice the memory to store a byte compared to @ db , @ data ...........
richard
- 10th September 2015, 07:06
if Event1_OT_Hour >23 then Event1_OT_Hour = 23
if Event1_OT_Hour <1 then Event1_OT_Hour = 0
can be replaced by if Event1_OT_Hour is a byte
Event1_OT_Hour=Event1_OT_Hour min 23
saves heaps of typing if nothing else
longpole001
- 10th September 2015, 10:53
I expect you realise that pokecode uses twice the memory to store a byte compared to @ db , @ data ...........
umm no i did not i am very new to using pokecode and peekcode , i am just trying it out now , and using darrel getaddress built into the INTs18.inc to get the the address in mem or where its put the label
longpole001
- 10th September 2015, 11:53
looking at a hex dump noticed that pokecode stores a byte as a word value in the flash , this is real waist of space , can i store the data as a word and then get it back as a byte or if needed a word if so how , this must have been done a lot before
Dave
- 10th September 2015, 12:10
Hey Longpole001, you asked this:
and this i cant find a better way to do to reduce its compile size
if val < 6 AND Menu_Select = 211 then
lookup val,[1,2,4,8,16,32],val ' reasign val to
gosub Show_current_sel_2 ' place "* *" on the selected channel in menu using bit pattern sleection
endif
Why not use the PBP command "DCD for the lookup table problem like this:
Value = DCD Value
When you come into the statement value will be a number between 0 and something less than 31, DCD will give it a value based on the bit position which is what you are doing with the lookup command. a value of 0 = 1, a value of 1 = 2, a value of 2 = 4 and so on. At lease that's how I would do it...
Amoque
- 10th September 2015, 13:26
You might also explore the use of MAX and MIN for setting bounds in situations like:
if Event1_OT_Hour >23 then Event1_OT_Hour = 23
or
if Event1_OT_Hour <1 then Event1_OT_Hour = 0
longpole001
- 10th September 2015, 22:26
Event1_OT_Hour=Event1_OT_Hour min 23
yes have a done this - saved some space there - thanks
richard
- 11th September 2015, 00:19
can i store the data as a word and then get it back as a byte or if needed a word if so how
http://www.picbasic.co.uk/forum/showthread.php?t=19949
longpole001
- 11th September 2015, 02:53
thanks richard
i am using darrels hi and low interupts services
Art
- 11th September 2015, 20:30
If it’s bigger now, it won’t be if you put all of them in the same big array and skip to each group
with an outer loop around that.
Event_OT var byte[8] ‘ or however many there are
Event_OT_Day var Event_OT[0] ‘create alias to keep those names used elsewhere
Event_OT_AllThoseOtherThings var Event_OT[1] ‘create alias
…
…
index var byte ‘ this is re-useable for all of them
if Event1_OT[0] >7 then
for index = 0 to 4
Event_OT[index] = 0
next index
ENDIF
You could check it isn’t cheaper to check for 0.
It might not be now, but an earlier PBP, it would be cheaper.
'if Event_Penalty_Sec <1
if Event_Penalty_Sec =0
if your program uses the watchdog timer, there will be some buried in all of that.
DEFINE NO_CLRWDT
You should get away with only one for that entire slab,
and sprinkle any others only where needed
@ clrwdt
definitely if there are any nops in code they can be replaced with them.
Art
- 11th September 2015, 20:48
this:
if val < 6 AND Menu_Select = 211 then
lookup val,[1,2,4,8,16,32],val ' reasign val to
gosub Show_current_sel_2 ' place "* *" on the selected channel in menu using bit pattern sleection
endif
if val =>6 and val <= 11 and Menu_Select = 2112 then
lookup val-6,[1,2,4,8,16,32],val
gosub Show_current_sel_2
endif
if val =>12 and Menu_Select = 2113 then
lookup val-12,[1,2,4,8,16,32],val
gosub Show_current_sel_2
endif
this should work instead (directly replaced) :
thingyousubtract var byte ‘ new variable
if val < 6 AND Menu_Select = 211 then
thingyousubtract = 0 : gosub memorysavelookup ' reasign val to
gosub Show_current_sel_2 ' place "* *" on the selected channel
endif
if val =>6 and val <= 11 and Menu_Select = 2112 then
thingyousubtract = 6 : gosub memorysavelookup
gosub Show_current_sel_2
endif
if val =>12 and Menu_Select = 2113 then
thingyousubtract = 12 : gosub memorysavelookup
gosub Show_current_sel_2
endif
memorysavelookup:
lookup val-thingyousubtract,[1,2,4,8,16,32],val
return
and if that still works, you might as well:
thingyousubtract var byte ‘ new variable
if val < 6 AND Menu_Select = 211 then
thingyousubtract = 0 : gosub memorysavelookup ' reasign val to
endif
if val =>6 and val <= 11 and Menu_Select = 2112 then
thingyousubtract = 6 : gosub memorysavelookup
endif
if val =>12 and Menu_Select = 2113 then
thingyousubtract = 12 : gosub memorysavelookup
endif
memorysavelookup:
lookup val-thingyousubtract,[1,2,4,8,16,32],val
gosub Show_current_sel_2
return
then if it still works, you should be able to:
memorysavelookup:
lookup val-thingyousubtract,[1,2,4,8,16,32],val
goto Show_current_sel_2
Now this is still assuming I haven’t broken it yet, you can:
thingyousubtract var byte ‘ new variable
thingyousubtract = 0
if val < 6 AND Menu_Select = 211 then
gosub memorysavelookup
endif
if val =>6 and val <= 11 and Menu_Select = 2112 then
gosub memorysavelookup
endif
if val =>12 and Menu_Select = 2113 then
gosub memorysavelookup
endif
memorysavelookup:
lookup val-thingyousubtract,[1,2,4,8,16,32],val
thingyousubtract = thingyousubtract + 6
goto Show_current_sel_2
Art
- 11th September 2015, 21:20
But wait there’s more!
If you call within the next 20 minutes I’ll also throw in this rotating bit
(but also found I broke it and got to steal some memory back)
thingyousubtract var byte ‘ new variable
thingyousubtract = 0
if val < 6 AND Menu_Select = 211 then
thingyousubtract = 0 : gosub memorysaverotate
endif
if val =>6 and val <= 11 and Menu_Select = 2112 then
thingyousubtract = 6 : gosub memorysaverotate
endif
if val =>12 and Menu_Select = 2113 then
thingyousubtract = 12 : gosub memorysaverotate
endif
memorysaverotate:
val = 1<<(val-thingyousubtract)
goto Show_current_sel_2
longpole001
- 12th September 2015, 11:15
thanks art that works well
i used an exiting variable for the temp one
i also did multi if /then statements , which reduced the compile further - those "and " do add up in compile
i have not seen the command ":" to allow you to put on the same line before btw
here what works
cheers
Sheldon
Show_RF_CH_Select:
gl_y = 8 ' show current channel in use on menu heading line - gl_y = 8 , gl_x= 162,168
gl_x= 160
read $09,val ' get channel ref
g_num = val
if g_num dig 1 = 0 then ' leading 0 supression
gosub put_1dig
gl_x = gl_x +6
g_char = " " ' clear 2nd digit space, case it was used
gosub put_char
else
gosub put_2dig
endif
g_num = 0 ' use as temp verable
if val < 6 then ' if current RF ch = 0-5
if Menu_Select = 211 then ' and menu 211
g_num = 0 ' value offset for ch
gosub Show_RF_CH_Select_common ' show * * on the selected ch
endif
endif
if val =>6 then ' if current RF ch = 6-11
if val <= 11 then
if Menu_Select = 2112 then ' and on menu 2112
g_num = 6 ' value offset for ch
gosub Show_RF_CH_Select_common
endif
endif
endif
if val =>12 then ' if current RF ch = 6-11
if Menu_Select = 2113 then
g_num = 12 ' value offset for ch
gosub Show_RF_CH_Select_common ' show * * on the selected ch
endif
endif
return
'------------------------------
Show_RF_CH_Select_common:
val = 1<<(val-g_num) ' val = shift right 1 of VAL- Offset RF menu to get 1,2,4,8,16,32 in bit pattern
gosub Show_current_sel_2 ' show "* * on selected menu / ch using the bit pattern of VAL
return
Art
- 12th September 2015, 12:20
I’m glad if it saved some memory... I made a bigger post but it looks to have disappeared.
longpole001
- 12th September 2015, 13:57
yes i am the point that every bit really counts even a large change to get a small result has its merits
longpole001
- 12th September 2015, 14:08
if i do write data to the flash mem using the the write table asm , how do reserve the space so the compiler does not use it , write all over the top of it
richard
- 13th September 2015, 02:37
13 words
g_num var byte
g_num = 10
if g_num <10 then ' leading 0 supression
gosub d1
else
gosub d2
endif
d1:
return
d2:
return
84 words
g_num var byte
g_num = 10
if g_num dig 1 =0 then ' leading 0 supression
gosub d1
else
gosub d2
endif
d1:
return
d2:
return
if i do write data to the flash mem using the the write table asm , how do reserve the space so the compiler does not use it , write all over the top of it
do u mean with TBLWT OR DT
longpole001
- 14th September 2015, 03:32
thanks richard that little change got back 600 byte over all
longpole001
- 14th September 2015, 05:16
in relation to using the peek/poke code routine i have is to put font tables into cpu flash , but that uses 2 times the space in flash than what is need for the data alone as it takes it sotres a command + data byte
i would like to use the same arrangment from @getaddress which is incorporated in to darrel's int-18 routines
but not store the instruction as the pokecode does
LG_Font_Base:
' Note gl_x char space need be 12 , not normal 24 when using chr else too big a gap space _
' Code for "-" Asci 45 : note -gl_i(0) is ASCI CHR CODE , 90 real values _
pokecode $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0 0,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, _
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0 0,$00,$00,$00,$00,$3F,$FC,$00,$3F,$FC,$00,$3F,$FC, _
$00,$3F,$FC,$00,$3F,$FC,$00,$00,$00,$00,$00,$00,$0 0,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, _
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0 0,$00,$00
'=================== FONT COMMON ROUTINE - pokecode use ==========================
' Assumes gl_x, gl_y,X_scan,Y_scan,Font_lookup
' ALL FONTS MUST BE gl_x = 8 , 16 , 24 etc
' Inv_font = 0 = normal 1= inverse
Font_Common:
x_save = gl_x ' save the gl_x start point value
y_save = gl_y ' save the gl_y start point value
gl_yb = y_save + Y_scan ' number of y scans for the char from y starting point(0)
gl_xb = 0
Address = 0
if Font_lookup = 1 then
@ GetAddress _LG_Font_Base, _Font_Base_Address ; gets base start address of LG_font into Font_Base_Address varable
Font_Index = (LG_font - 45)* (90*2) ' remove the ascii chr value 45 offset 0 * font chr length x 2 cos of RETLW INSTRUCTION for each byte read in index
endif
if Font_lookup = 2 then ' remove the offset of the first symbol $2D / 45 so start at 0
@ GetAddress _Med_Font_Base, _Font_Base_Address
Font_Index = (Med_font - 45)* (40*2) ' remove the ascii chr value 45 offset * font chr length in index
endif
Address = Font_Base_Address + Font_Index 'gets you to the start of the glyph
for gl_y = y_save to gl_yb ' y scan lines, start to finish values
gl_x = x_save ' clear x position to start point (keep it an 8bit multiple)
gosub gl_gaddr ' Set address
for gl_xb = 1 to X_scan ' gl_x byte x X scan bytes on each line
peekcode Address,gl_byte ' read the indexed byte in
glcd_msb = gl_byte
glcd_cmd = DATA_WR_INC ' write and increment
gosub send_1 ' send to glcd
Address = Address+2 ' inc address here +2 cos each byte includes , as data start at 0 not 1 as per lookup tables previously
next gl_xb ' next byte of font
next gl_y ' next scan line of font
gl_y = y_save ' Restore the Y location
gl_x = x_save ' Restore the X location
return
richard
- 14th September 2015, 06:24
LG_Font_Base:
@ db 0x00,0x00,...................................
16 bytes to a line is good
good
@ GetAddress _LG_Font_Base, _Font_Base_Address note 64k address limit
@ GetAddress _Med_Font_Base, _Font_Base_Address ;note 64k address limit
Font_Index = (Med_font - 45)* (40*2) ' remove the ascii chr value 45 offset * font chr length in index
endif
Address = Font_Base_Address + Font_Index 'gets you to the start of the glyph
for gl_y = y_save to gl_yb ' y scan lines, start to finish values
gl_x = x_save ' clear x position to start point (keep it an 8bit multiple)
gosub gl_gaddr ' Set address
for gl_xb = 1 to X_scan ' gl_x byte x X scan bytes on each line
readcode Address,gl_byte ' read the indexed byte in ;note 64k address limit for readcode
glcd_msb = gl_byte
glcd_cmd = DATA_WR_INC ' write and increment
gosub send_1 ' send to glcd
Address = Address+1 ' inc address here +2 cos each byte includes , as data start at 0 not 1 as per lookup tables previously
next gl_xb ' next byte of font
next gl_y ' next scan line of font
look at my tft font and tft-spi.pbpmod (gcga: subroutine)
there are other ways to get around the 64k limitation in that code too
Art
- 14th September 2015, 13:02
What am I missing here?
PBP integer math, if something is less than 1 is another way to check if it’s zero.
and should be able to be deleted without any consequence.
ie.. if something = 0 then something = 0.
if Event2_OT_Min <1 then Event2_OT_Min = 0
longpole001
- 14th September 2015, 16:07
yes that was stuff up - it was to stop it going passed a 0 value when a key was pushed and it never worked cos it was checked after the key had removed the value, so then value was the max value and so it never worked
so it was changed in the key routines to
if key = x then
if value <> 0 then value = value - 1
endif
longpole001
- 14th September 2015, 16:13
the problem i am having with the @ db 0x?? , 0x?? is it takes the 1st byte as the low byte , the next as the high byte , so the data is out of sequance when stored into the flash
is there away to reverce the seqaunce ( eg high byte 1st , lowbyte 2nd m etc , without changing the font data
longpole001
- 14th September 2015, 16:32
or i guess readcode can reads in a word value and i swap it in the routine some how
longpole001
- 14th September 2015, 17:00
unfortunalty the for /next loop of x_scan can be 2 or 3 so not easy to break into even words -mm darn
longpole001
- 16th September 2015, 05:58
interesting results
i now format the data as word value which now stores the data in the correct byte by byte sequance form ,
however readcode reads the address data back incorectly for a given address when reading as byte value
i assume its cos readcode is word based command ???
is there a way to read the data back for each address byte only ?
as can be seen on address 5172, 5173 byte values are incorrect for the given address
LG_Font_Base:
' Note gl_x char space need be 12 , not normal 24 when using chr else too big a gap space _
' Code for "-" Asci 45 90 real values _
@ dw 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0 x0000,0x0000,0x0000,0x0000,0x0000;,0x00
@ dw 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0 x0000,0x0000,0x3FFC,0x003F,0xFC00,0x3FFC
@ dw 0x003F,0xFC00,0x3FFC,0x0000,0x0000,0x0000,0x0000,0 x0000,0x0000,0x0000,0x0000,0x0000;,0x00
@ dw 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0 x0000
part of flash dump of font stored
5170- 0000 3ffc 003f fc00 3ffc 003f fc00 3ffc
5180- 0000 0000 0000 0000 0000 0000 0000 0000
5190- 0000 0000 0000 0000 0000 0000 0000 0000
51a0- 0000
terminal debug dump - for each address read by readcode
5170- 0 , 5171- 0,
5172- FC, 5173- 3F,
5174- 3F, 5175- 0,
5176- 0 , 5177- FC,
5178- FC, 5179- 3F,
517A- 3F, 517B- 0,
517C- 0 , 517D- FC,
517E- FC, 517F- 3F,
5180- 0 , 5181- 0
richard
- 16th September 2015, 06:30
I will see if I can explain it
pic18 pgm mem is stored as words , so if the bytes are not an even number the last byte is padded with 00
if we store this @ db "say",34,"hello",34,0
then its stored like this lst file extract
00014A 6173 2279 6568 db "say",34,"hello",34,0 ; note order looks reversed but its really lowbyte first
6C6C 226F 0000
when readcode reads it back
its lowbyte, highbyte
so the string is returned in order as say"hello",0
richard
- 16th September 2015, 06:50
when stored as words
@ dw 0x0000,0x0000,0x53d7,0x53d7,0x53d7,0x53d7,0x53d7,0 x53d7,0x53d7,0x53d7,0x53d7,0x0000,0x0000,0x0000,0x 0000,0x0000
lst file looks like this
003CF6 0000 0000
53D7 06827
0000,0x0000
53D7 53D7 53D7
53D7 53D7 53D7
53D7 53D7 0000
0000 0000 0000
0000
note the order is now not reversed
longpole001
- 16th September 2015, 07:40
ok what i dont follow is
if readcode can read a byte back based on a word address ,
and the data is written to flash as a word , and therefore are stored in the way i want to read them byte by byte based on address i should be able to get each byte of the word
what i am finding is that the byte returned is not correct for the address given
richard
- 16th September 2015, 08:37
work just fine for me
pause 2000
Serout2 PORTb.7,84,["ready",13,10]
addr var word
inbuff var byte[30]
buff var byte[30] $4f0
lb var byte
hb var byte
lc var byte
Clear
goto StartLoop ' Required
String1:
@ data "may \"Hello\"\0"
String2:
@ db "say",34,"hello",34,0
String3:
@ dw 0x003F,0xFC00,0x3FFC,0x0000,0x0000,0x0000,0x0000,0 x0000,0x0000,0x0000,0x0000,0x0000;,0x00
'------------Flash2Ram Macro - Location insensitive -------------------------
ASM
Flash2Ram macro buffer, msg ; Fills the buffer from flash msg
movlw UPPER msg
movwf TBLPTRU
movlw HIGH msg
movwf TBLPTRH
movlw LOW msg
movwf TBLPTRL
movlw low buffer
movwf FSR2L
movlw High buffer
movwf FSR2H
L?CALL _bfill
endm
ENDASM
ASM
GetAddress macro Label, Wout
CHK?RP Wout
movlw low Label ; get low byte
movwf Wout
movlw High Label ; get high byte
movwf Wout + 1
endm
ENDASM
StartLoop: ' This loop repeats continuously just as a test.
@ Flash2Ram _buff,_String1' Get a String from flash memory
Serout2 PORTb.7,84, ["buff ",str buff ,13,10] ' and print it
@ Flash2Ram _inbuff,_String2' Get a String from flash memory
Serout2 PORTb.7,84, ["inbuff ",str inbuff ,13,10] '
pause 500
@ GetAddress _String3 ,_addr
for lc=0 to 3
readcode addr ,lb
addr=addr+1
readcode addr ,hb
addr=addr+1
Serout2 PORTb.7,84, ["hb ",hex2 hb," lb ",hex2 lb,13,10]
next
goto StartLoop ' Repeat
end
bfill:
ASM
Next_Char
tblrd *+
movf TABLAT,w
movwf POSTINC2
btfss STATUS,Z
goto Next_Char
return
ENDASM
output
buff may "Hello"
inbuff say"hello"
hb 00 lb 3F
hb FC lb 00
hb 3F lb FC
hb 00 lb 00
buff may "Hello"
inbuff say"hello"
hb 00 lb 3F
hb FC lb 00
hb 3F lb FC
hb 00 lb 00
buff may "Hello"
inbuff say"hello"
hb 00 lb 3F
richard
- 16th September 2015, 09:13
to read as words
pause 2000
Serout2 PORTb.7,84,["ready",13,10]
addr var word
inbuff var byte[30]
buff var byte[30] $4f0
lb var byte
hb var byte
lc var byte
lp var word
Clear
goto StartLoop ' Required
String1:
@ data "may \"Hello\"\0"
String2:
@ db "say",34,"hello",34,0
String3:
@ dw 0x003F,0xFC00,0x3FFC,0x0000,0x0000,0x0000,0x0000,0 x0000,0x0000,0x0000,0x0000,0x0000;,0x00
'------------Flash2Ram Macro - Location insensitive -------------------------
ASM
Flash2Ram macro buffer, msg ; Fills the buffer from flash msg
movlw UPPER msg
movwf TBLPTRU
movlw HIGH msg
movwf TBLPTRH
movlw LOW msg
movwf TBLPTRL
movlw low buffer
movwf FSR2L
movlw High buffer
movwf FSR2H
L?CALL _bfill
endm
ENDASM
ASM
GetAddress macro Label, Wout
CHK?RP Wout
movlw low Label ; get low byte
movwf Wout
movlw High Label ; get high byte
movwf Wout + 1
endm
ENDASM
StartLoop: ' This loop repeats continuously just as a test.
@ Flash2Ram _buff,_String1' Get a String from flash memory
Serout2 PORTb.7,84, ["buff ",str buff ,13,10] ' and print it
@ Flash2Ram _inbuff,_String2' Get a String from flash memory
Serout2 PORTb.7,84, ["inbuff ",str inbuff ,13,10] '
pause 500
@ GetAddress _String3 ,_addr
for lc=0 to 3
readcode addr ,lb
addr=addr+1
readcode addr ,hb
addr=addr+1
Serout2 PORTb.7,84, ["hb ",hex2 hb," lb ",hex2 lb,13,10]
next
@ GetAddress _String3 ,_addr
for lc=0 to 3
readcode addr ,lp
addr=addr+2
Serout2 PORTb.7,84, ["lp ",hex4 lp,13,10]
next
goto StartLoop ' Repeat
end
bfill:
ASM
Next_Char
tblrd *+
movf TABLAT,w
movwf POSTINC2
btfss STATUS,Z
goto Next_Char
return
ENDASM
output
lp 3FFC
lp 0000
buff may "Hello"
inbuff say"hello"
hb 00 lb 3F
hb FC lb 00
hb 3F lb FC
hb 00 lb 00
lp 003F
lp FC00
lp 3FFC
lp 0000
buff may "Hello"
inbuff say"hello"
hb 00 lb 3F
h
longpole001
- 16th September 2015, 09:34
yes i thought about doing it that way where i get a word then use high, lowbyte , and thats ok when the for/next loop is for x = 1 to 2 , 4,6 etc so it uses the 2 bytes of the word per loop
but my for/next loop 1-3 depending on the font so not even word use of 2 bytes is possible
and if you just get 1 byte using readcode addresss , byte ,
it will appears to get low byte for an even address , high byte for odd address - regardless of the data stored at that specific address
eg my listing i put in post - address in flash at 5172,73 = 3FFC
USING READCODE at address $5172 = $FC -not $3F as stored in flash
5170- 0000 3ffc 003f fc00 3ffc 003f fc00 3ffc
5180- 0000 0000 0000 0000 0000 0000 0000 0000
5190- 0000 0000 0000 0000 0000 0000 0000 0000
51a0- 0000
terminal debug dump - for each address read by readcode
5170- 0 , 5171- 0,
5172- FC, 5173- 3F,
5174- 3F, 5175- 0,
5176- 0 , 5177- FC,
5178- FC, 5179- 3F,
517A- 3F, 517B- 0,
517C- 0 , 517D- FC,
517E- FC, 517F- 3F,
5180- 0 , 5181- 0
if you put this your example of string 3 in
so if say address return is adress 1234 say 0000
@ GetAddress _String3 ,_addr
for lc=0 to 3
readcode addr ,lb
addr=addr+1
readcode addr ,hb
addr=addr+1
Serout2 PORTb.7,84, ["hb ",hex2 hb," lb ",hex2 lb,13,10]
next
richard
- 16th September 2015, 10:47
sorry but I can't make any sense of what you saying
can I suggest you make a small program that demonstrates the problem
richard
- 16th September 2015, 11:22
what about this
pause 2000
Serout2 PORTb.7,84,["ready",13,10]
addr var word
inbuff var byte[30]
buff var byte[30] $4f0
lb var byte
hb var byte
lc var byte
lp var word
Clear
goto StartLoop ' Required
String1:
@ data "may \"Hello\"\0"
String2:
@ db "say",34,"hello",34,0
'------------Flash2Ram Macro - Location insensitive -------------------------
ASM
Flash2Ram macro buffer, msg ; Fills the buffer from flash msg
movlw UPPER msg
movwf TBLPTRU
movlw HIGH msg
movwf TBLPTRH
movlw LOW msg
movwf TBLPTRL
movlw low buffer
movwf FSR2L
movlw High buffer
movwf FSR2H
L?CALL _bfill
endm
ENDASM
ASM
GetAddress macro Label, Wout
CHK?RP Wout
movlw low Label ; get low byte
movwf Wout
movlw High Label ; get high byte
movwf Wout + 1
endm
ENDASM
StartLoop: ' This loop repeats continuously just as a test.
@ Flash2Ram _buff,_String1' Get a String from flash memory
Serout2 PORTb.7,84, [13,10,"buff ",str buff ,13,10] ' and print it
@ Flash2Ram _inbuff,_String2' Get a String from flash memory
Serout2 PORTb.7,84, ["inbuff ",str inbuff ,13,10] '
pause 500
;@ GetAddress _String3 ,_addr
'
addr =$5170
for lc=0 to 3
Serout2 PORTb.7,84, [13,10,"address ",hex4 addr ]
readcode addr ,lb
addr=addr+1
;Serout2 PORTb.7,84, [13,10,"address ",hex4 addr ]
readcode addr ,hb
Serout2 PORTb.7,84, [" hb ",hex2 hb ]
Serout2 PORTb.7,84, [" lb ",hex2 lb ]
addr=addr+1
next
;@ GetAddress _String3 ,_addr
addr =$5170
for lc=0 to 3
Serout2 PORTb.7,84, [13,10,"address ",hex4 addr ]
readcode addr ,lp
addr=addr+2
Serout2 PORTb.7,84, [" lp ",hex4 lp]
next
addr =$5177
readcode addr ,lb
Serout2 PORTb.7,84, [13,10,"odd address ",hex4 addr ]
Serout2 PORTb.7,84, [" b ",hex2 lb ]
addr =$5176
readcode addr ,lb
Serout2 PORTb.7,84, [13,10,"even address ",hex4 addr ]
Serout2 PORTb.7,84, [" b ",hex2 lb ]
goto StartLoop ' Repeat
end
bfill:
ASM
Next_Char
tblrd *+
movf TABLAT,w
movwf POSTINC2
btfss STATUS,Z
goto Next_Char
return
ENDASM
String3:
asm
org 0x5170
dw 0x003F,0xFC00,0x3FFC,0x5566,0x0000,0x0000,0x0000,0 x0000,0x0000,0x0000,0x0000,0x0000;,0x00
ENDASM
output
buff may "Hello"
inbuff say"hello"
address 5170 hb 00 lb 3F
address 5172 hb FC lb 00
address 5174 hb 3F lb FC
address 5176 hb 55 lb 66
address 5170 lp 003F
address 5172 lp FC00
address 5174 lp 3FFC
address 5176 lp 5566
odd address 5177 b 55
even address 5176 b 66
richard
- 16th September 2015, 11:43
eg my listing i put in post - address in flash at 5172,73 = 3FFC
USING READCODE at address $5172 = $FC -not $3F as stored in flash
@5172 = $FC = LOW BYTE
@5173 = $3F = HIGH BYTE
$3FFC $FC = LOW BYTE $3F = HIGH BYTE
where is the PROBLEM , IT's all consistent
org 0x5170
dw 0x003F,0xFC00,0x3FFC
longpole001
- 16th September 2015, 12:36
i must not be showing it well , the data seq of the font is the only thing that matters - not how it stored , only how it is read back in sequance i need ,
it has been split over a lot of posts so ill try re show it in one post
data was orginally poke /peek
this uses 2x the space than the data alone in flash
depeding on the font , data is read back as 3 or 2 bytes for each x scan line accross so cant be out of sequance
pokecode $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0 0,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, _
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0 0,$00,$00,$00,$00,$3F,$FC,$00,$3F,$FC,$00,$3F,$FC, _
$00,$3F,$FC,$00,$3F,$FC,$00,$00,$00,$00,$00,$00,$0 0,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, _
$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0 0,$00,$00
tryed changeing to @ db command using the font data bytes ,
@ db 0x00 , 0x3F, 0x10, 0xFF..............
this stores in flash as address - 3F00 , FF10 is NOT stored at same sequance address as font DB command as it is entered
readcode gives address = $3f , address + 1 = $00 - no good cos the data is not in the font seq required
tryied
@ dw 0x003F , 0x10FF
this stores in flash as address = 003F , 10FF - excellent follows the same data seq as the font bytes and is correct in flash so reading sequantial address should get each byte in sequance
readcode address 0 , byte = $3F - wrong - it recovers address +1 or low byte
readcode address +1 , byte = $00 - wrong - it recovers address -1 or high byte
hope i am showing this better for the issue at hand
to confirm if the problem is solved by swapping low/ high byte of the font data resolve - it does , but this is alot of work as well
richard
- 16th September 2015, 13:11
tryed changeing to @ db command using the font data bytes ,
@ db 0x00 , 0x3F, 0x10, 0xFF..............
this stores in flash as address - 3F00 , FF10 is NOT stored at same sequance address as font DB command as it is entered
wrong
it is stored exactly in that order low byte first then high byte , you are feeding in the data high byte first
readcode will retrieve it in the same order low byte then high byte
@ dw 0x003F , 0x10FF
readcode address 0 , byte = $3F - wrong - it recovers address +1 or low byte
readcode address +1 , byte = $00 - wrong - it recovers address -1 or high byte
wrong
@ dw places the data the same way low byte then high byte
readcode will retrieve it in the same order low byte then high byte
pause 2000
Serout2 PORTb.7,84,["ready",13,10]
addr var word
inbuff var byte[30]
buff var byte[30] $4f0
lb var byte
hb var byte
lc var byte
lp var word
Clear
goto StartLoop ' Required
String2:
@ db 0x3f,0,0,0xfc,0xfc,0x3f,0x66,0x55,0,0
asm
org 0x5170
dw 0x003F,0xFC00,0x3FFC,0x5566,0x0000,0x0000,0x0000,0 x0000,0x0000,0x0000,0x0000,0x0000;,0x00
org 0x0200
ENDASM
asm
GetAddress macro Label, Wout
CHK?RP Wout
movlw low Label ; get low byte
movwf Wout
movlw High Label ; get high byte
movwf Wout + 1
endm
ENDASM
StartLoop:
Serout2 PORTb.7,84, [13,10,"db data " ]
@ GetAddress _String2 ,_addr
for lc=0 to 3
Serout2 PORTb.7,84, [13,10,"address ",hex4 addr ]
readcode addr ,lb
addr=addr+1
Serout2 PORTb.7,84, [" lb ",hex2 lb," address ",hex4 addr ]
readcode addr ,hb
Serout2 PORTb.7,84, [" hb ",hex2 hb ]
addr=addr+1
next
Serout2 PORTb.7,84, [13,10,"dw data as byte " ]
addr =$5170
for lc=0 to 3
Serout2 PORTb.7,84, [13,10,"address ",hex4 addr ]
readcode addr ,lb
addr=addr+1
Serout2 PORTb.7,84, [" lb ",hex2 lb," address ",hex4 addr ]
readcode addr ,hb
Serout2 PORTb.7,84, [" hb ",hex2 hb ]
addr=addr+1
next
Serout2 PORTb.7,84, [13,10,"dw data as word " ]
;@ GetAddress _String3 ,_addr
addr =$5170
for lc=0 to 3
Serout2 PORTb.7,84, [13,10,"address ",hex4 addr ]
readcode addr ,lp
addr=addr+2
Serout2 PORTb.7,84, [" lp ",hex4 lp]
next
addr =$5177
readcode addr ,lb
Serout2 PORTb.7,84, [13,10,"odd address ",hex4 addr ]
Serout2 PORTb.7,84, [" high ",hex2 lb ]
addr =$5176
readcode addr ,lb
Serout2 PORTb.7,84, [13,10,"even address ",hex4 addr ]
Serout2 PORTb.7,84, [" low ",hex2 lb ]
goto StartLoop ' Repeat
end
output
db data
address 0184 lb 3F address 0185 hb 00
address 0186 lb 00 address 0187 hb FC
address 0188 lb FC address 0189 hb 3F
address 018A lb 66 address 018B hb 55
dw data as byte
address 5170 lb 3F address 5171 hb 00
address 5172 lb 00 address 5173 hb FC
address 5174 lb FC address 5175 hb 3F
address 5176 lb 66 address 5177 hb 55
dw data as word
address 5170 lp 003F
address 5172 lp FC00
address 5174 lp 3FFC
address 5176 lp 5566
odd address 5177 high 55
even address 5176 low 66
longpole001
- 16th September 2015, 15:05
sorry richard the result i am seeing does not support what your are saying and the results show on the GLCD and debug terminal show the seqaunce for @ db option and @ dw to be incorrect when using readcode i have at the moment , a it gets 1 byte at a time
remember the whole goel is to
a. not change the font original data sequence of values
b. store only the font data values , and not add any other values to flash to get the data back - unlike pokecode does
try it for your self
this is font chr "0" , where the font is 24 bits wide for (X) and 30 lines (Y)high
LG font values for Common_font routine then are
Y_scan = 29 ' 30 - Y scan lines - 1 - Cos "for " starts at 1
X_scan = 3 ' 3 - X scan x 8 bits ( 24 bits)
Font_lookup = 1 ' Use LG_Font_lookup
gosub Font_Common ' not using flash chip
with poke/peek it works ok with this code
terminal should show the same data format and exact seq as the pokecode data
' Code for "0" Asci 48 90 real values _
pokecode $00,$00,$00,$00,$FF,$00,$03,$FF,$C0,$0F,$FF,$F0,$1 F,$FF,$F8,$1F,$FF,$F8,$3F,$C3,$FC,$3F,$81,$FC,$3F, _
$81,$FC,$7F,$00,$FE,$7F,$00,$FE,$7F,$00,$FE,$7F,$0 0,$FE,$7F,$00,$FE,$7F,$00,$FE,$7F,$00,$FE,$7F,$00, _
$FE,$7F,$00,$FE,$7F,$00,$FE,$7F,$00,$FE,$3F,$81,$F C,$3F,$81,$FC,$3F,$C3,$FC,$1F,$FF,$F8,$1F,$FF,$F8, _
$0F,$FF,$F0,$03,$FF,$C0,$00,$FF,$00,$00,$00,$00,$0 0,$00,$00
code to place the code on glcd and terminal - terminal should show the address and data in the same sequance as the data input here
'=================== FONT COMMON ROUTINE - pokecode use ==========================
' Assumes gl_x, gl_y,X_scan,Y_scan,Font_lookup
' ALL FONTS MUST BE gl_x = 8 , 16 , 24 etc
' Inv_font = 0 = normal 1= inverse
Font_Common:
x_save = gl_x ' save the gl_x start point value
y_save = gl_y ' save the gl_y start point value
gl_yb = y_save + Y_scan ' number of y scans for the char from y starting point(0)
gl_xb = 0
Address = 0
if Font_lookup = 1 then
@ GetAddress _LG_Font_Base, _Font_Base_Address ; gets base start address of LG_font into Font_Base_Address varable
Font_Index = (LG_font - 45)* (90*2) ' remove the ascii chr value 45 offset 0 * font chr length x 2 cos of RETLW INSTRUCTION for each byte read in index
HSEROUT [13,10,"lg Font_Base_Address = ",hex Font_Base_Address," font index = ",dec Font_Index, 13,10] 'debug
endif
if Font_lookup = 2 then ' remove the offset of the first symbol $2D / 45 so start at 0
@ GetAddress _Med_Font_Base, _Font_Base_Address
Font_Index = (Med_font - 45)* (40*2) ' remove the ascii chr value 45 offset * font chr length in index
endif
Address = Font_Base_Address + Font_Index 'gets you to the start of the glyph
for gl_y = y_save to gl_yb ' y scan lines, start to finish values
gl_x = x_save ' clear x position to start point (keep it an 8bit multiple)
gosub gl_gaddr ' Set address
for gl_xb = 1 to X_scan ' gl_x byte x X scan bytes on each line
peekcode Address,gl_byte ' read the indexed byte in
HSEROUT [hex Address,"- ",hex gl_byte, ","]
glcd_msb = gl_byte
glcd_cmd = DATA_WR_INC ' write and increment
gosub send_1 ' send to glcd
Address = Address+2 ' inc address here +2 cos each byte includes intruction code , as data start at 0
next gl_xb ' next byte of font
next gl_y ' next scan line of font
gl_y = y_save ' Restore the Y location
gl_x = x_save ' Restore the X location
return
to use @ db data format the poke code data is changed to this format
' Code for "0" Asci 48 90 real values _
@ db 0x00,0x00,0x00,0x00,0xFF,0x00,0x03,0xFF,0xC0,0x0F, 0xFF,0xF0,0x1F,0xFF,0xF8,0x1F,0xFF,0xF8,0x3F,0xC3, 0xFC,0x3F,0x81,0xFC,0x3F
@ db 0x81,0xFC,0x7F,0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00, 0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFE, 0x7F,0x00,0xFE,0x7F,0x00
@ db 0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFE, 0x3F,0x81,0xFC,0x3F,0x81,0xFC,0x3F,0xC3,0xFC,0x1F, 0xFF,0xF8,0x1F,0xFF,0xF8
@ db 0x0F,0xFF,0xF0,0x03,0xFF,0xC0,0x00,0xFF,0x00,0x00, 0x00,0x00,0x00,0x00,0x00
routine to get this data out and into the corect sequance - BUT THIS DOES NOT WORK AS THE DATA IS OUT OF SEQUANCE cos of readcode of low high reading
Font_Common:
x_save = gl_x ' save the gl_x start point value
y_save = gl_y ' save the gl_y start point value
gl_yb = y_save + Y_scan ' number of y scans for the char from y starting point(0)
gl_xb = 0
Address = 0
if Font_lookup = 1 then
@ GetAddress _LG_Font_Base, _Font_Base_Address ; gets base start address of LG_font into Font_Base_Address varable
Font_Index = (LG_font - 45)* 90 ' remove the ascii chr value 45 offset 0 * font chr length
HSEROUT [13,10,"lg Font_Base_Address = ",hex Font_Base_Address," font index = ",dec Font_Index, 13,10] 'debug
endif
if Font_lookup = 2 then ' remove the offset of the first symbol $2D / 45 so start at 0
@ GetAddress _Med_Font_Base, _Font_Base_Address
Font_Index = (Med_font - 45)*40 ' remove the ascii chr value 45 offset * font chr length in index
endif
Address = Font_Base_Address + Font_Index 'gets you to the start of the glyph
for gl_y = y_save to gl_yb ' y scan lines, start to finish values
gl_x = x_save ' clear x position to start point (keep it an 8bit multiple)
gosub gl_gaddr ' Set address
for gl_xb = 1 to X_scan ' gl_xb byte x X scan bytes can be 2 or 3 on each line
readcode Address,gl_byte
HSEROUT [hex Address,"- ",hex gl_byte, ","]
glcd_msb = gl_byte ' put in 1st byte - stored as
glcd_cmd = DATA_WR_INC ' write and increment
gosub send_1 ' send to glcd
Address = Address + 1 ' inc address + 1
next gl_xb ' next byte of font
next gl_y ' next scan line of font
gl_y = y_save ' Restore the Y location
gl_x = x_save ' Restore the X location
return
same data joined to make word values ,
these are stored in flash correct seq in flash as the font data shown here
recovery routine is same as above - and has the same issue readcode gets the data not in correct seq required
' Code for "0" Asci 48 90 real values _
@ dw 0x0000,0x0000,0xFF00,0x03FF,0xC00F,0xFFF0,0x1FFF,0 xF81F,0xFFF8,0x3FC3,0xFC3F,0x81FC ;,0x3F
@ dw 0x3F81,0xFC7F,0x00FE,0x7F00,0xFE7F,0x00FE,0x7F00,0 xFE7F,0x00FE,0x7F00,0xFE7F,0x00FE,0x7F00
@ dw 0xFE7F,0x00FE,0x7F00,0xFE7F,0x00FE,0x3F81,0xFC3F,0 x81FC,0x3FC3,0xFC1F,0xFFF8,0x1FFF ;,0xF8
@ dw 0xF80F,0xFFF0,0x03FF,0xC000,0xFF00,0x0000,0x0000,0 x0000
longpole001
- 16th September 2015, 16:08
as a test i reversed high to low byte in the font structure
unfortunately it worked , and this is supported by the data dumps as shown in previous posts , so to make the font common routine work i would have to reverse all the data stucture for each font chr - which if i dont have abetter option will need to be done
' Code for "0" Asci 48 90 real values _
@ dw 0x0000,0x0000,0x00FF,0xFF03,0x0FC0,0xF0FF,0xFF1F,0 x1FF8,0xF8FF,0xC33F,0x3FFC,0xFC81;,0x3F
@ dw 0x813F,0x7FFC,0xFE00,0x007F,0x7FFE,0xFE00,0x007F,0 x7FFE,0xFE00,0x007F,0x7FFE,0xFE00,0x007F ;swaped low high bytes arround
@ dw 0x7FFE,0xFE00,0x007F,0x7FFE,0xFE00,0x813F,0x3FFC,0 xFC81,0xC33F,0x1FFC,0xF8FF,0xFF1F;,0xF8
@ dw 0x0FF8,0xF0FF,0xFF03,0x00C0,0x00FF,0x0000,0x0000,0 x0000
Art
- 18th September 2015, 16:43
If you can write to that area your program could swap the data and write it back,
then set a flag somewhere in a spare EEPROM bit to flag not to do it again.
That’s if you can’t write something to spit it out a serial terminal in the format you want it.
If the pic can read that and also has a serial terminal, you should be able to get it to format the lines as code you have above.
longpole001
- 18th September 2015, 20:11
thats what i ended up doing art and swapped the lot arround , although pain in butt readcode is the best option for the fonts that are not loaded in the spi flash , fortunately there are only 30 font chrs like this
longpole001
- 7th October 2015, 12:02
has anyone a way to use 2 word value varables to accumulate an math value with out using longs or floating point
HenrikOlsson
- 7th October 2015, 12:23
Hi,
Depends on your particular needs, here's one way to be used when the value to be added fits within a WORD:
HW VAR WORD
LW VAR WORD
Temp VAR WORD
AddValue VAR WORD
Temp = LW ' Copy low word
LW = LW + AddValue
IF LW < Temp THEN ' Low word wrapped around
HW = HW + 1
ENDIF
If the value to be added is always one then:
HW VAR WORD
LW VAR WORD
LW = LW + 1
IF LW = 0 THEN 'Low word wrapped around.
HW = HW + 1
ENDIF
/Henrik.
pedja089
- 7th October 2015, 12:58
Why you don't try N-Bit_MATH?
http://www.picbasic.co.uk/forum/showthread.php?t=12433&p=82694#post82694
I use this code to store result as string in array
'Convert 64Bit to string
@ MOVE?CP 10, _Tmp64bit ; copy a CONSTANT to a Pvar
FOR i=19 TO 0 STEP -1
@ MATH_DIV _Int64Bit, _Tmp64bit, _Res64bit ; Res = A / B; Remainder in REG_Z
ValueStr[i]=REG_Z+48
@ MOVE?PP _Res64bit, _Int64Bit ; copy a Pvar to a Pvar
NEXT i
longpole001
- 13th October 2015, 17:30
hi thanks for the input guys
to get it to do what i want i used longs ;(
which i would like to change to 2 x word variables for this one long variable "Event_Dist_Speed "
i thinking perhaps the nbit math may work but not sure how it may be done with the calculations i have now
' routine to calc speed based on sec under 18 hours
Distance_Calc_Speed0:
if Event_Dist_Timebase = 0 then Event_Dist_Speed = Event_Dist_Value ' calculate speed with base in secs
if Event_Dist_Timebase = 1 then Event_Dist_Speed = Event_Dist_Value*60 ' calculate speed with base in mins
Event_Dist_Speed = Event_Dist_Speed*100/(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60)
if Event_Dist_Timebase = 2 then gosub Distance_Speed_Calc2 ' calculate speed with base in hours - gosub becuase it is called as a seprate display
' HSEROUT [" Event_Dist_Speed = ",dec Event_Dist_Speed, 10,13] ' debug
return
' ----------------------------------------------------------------
' routine to calc speed based on sec 's
' used when time is >18 hours so that value is < word max size
Distance_Calc_Speed1:
return
' ------------------------------------------------------------------
' show KPH or MPH on every base reading formular
' calculate speed with hours base
' called as 2nd speed display details
Distance_Speed_Calc2:
Event_Dist_Speed = Event_Dist_Value*360
if Event_Dist_Measure = 0 then Event_Dist_Speed = (Event_Dist_Speed*1000/5280)/(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60) ' if feet distance base
if Event_Dist_Measure = 1 then Event_Dist_Speed = Event_Dist_Speed*100 /(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60)/100 ' if meters distance base
if Event_Dist_Measure > 1 then Event_Dist_Speed = Event_Dist_Speed*1000 /(EL1_Seconds + (EL1_Minutes + EL1_Hours*60)*60) ' if Miles or KM distance base
' HSEROUT [" hour reading Event_Dist_Speed = ",dec Event_Dist_Speed ,10,13] ' debug
return
'------------------------------------------------------------------
Show_Speed_Value:
gl_x = 0
gl_y = 48
gl_k = 0
for gl_k = 0 to 7
lookup gl_k,[" x.xx"],Sml_font ' 8 chrs
gosub Get_Sml_font ' Get Font in K9_Fonts_banners.bas
gl_x = gl_x+8
next gl_k
gl_x = 0 ' puts 5 digits of speed 00000.xx
g_num = Event_Dist_Speed /100 ' get the base value 00000.xx
gosub Sml_put_5dig
gl_x = 48 ' put first 2 digits of speed xxxxx.00
g_num = Event_Dist_Speed
gosub Sml_put_2dig
return
longpole001
- 13th October 2015, 17:42
varable ranges information
Event_Dist_Speed input = 1 - 4096
time = combined values of EL1 varables - time range = 1sec - 8 days ' note days varable not used as yet , base time calculations based on secs
expect that if hours >18 then the secs will be droped and time caclulation base of mins - not tested yet
longpole001
- 15th October 2015, 03:37
looking at the Nmath caclualtions
can a math action be done directly without copy a pbp var to a Pvar first ?
A var byte
Tmp32bit_1 var byte[PRECISION]
Tmp32bit_2 var byte[PRECISION]
Result var byte[PRECISION]
eg - direct method
@ MATH_ADD A, Tmp32bit_2, Result ; A+B =Res
or do i always need to get the standard PBP var byte into a Pvar before the math calculation
eg
@ MOVE?BP A , Tmp32bit_1 ' copy byte PBP to Pvar
@ MATH_ADD Tmp32bit_1, Tmp32bit_2, Result ; A+B =Res
cheers
sheldon
longpole001
- 15th October 2015, 04:44
DT - ALL math done with these routines are done at the PRECISION level, and all variables used with the MATH functions must be (PRECISION) bytes in length.
re reading the post make it clear
longpole001
- 16th October 2015, 02:03
well i ended up changing all the posted code that needed the long varable to work out speed to Nbit math
it took some work time ,but the rewards are there in size of the reduced compile size - in my case i saved 8.5k over using longs
although i needed only 1 long varable - the speed value - selecting longs added 10.5k to compile size as soon as you tick the box , and that is a very big overhead when flash space is very tight
Nbit math has it high overheads as well - the include is compiled about 700bytes , but the real overhead is in having to use multi 32bit PRESISON varables( 4 were needed) to do the step by step math operations that can be avoided when using longs , as a result more ram space is used , and it is noticeably slower than using longs when showing the results, even when at 64Mhz.
Also having to do multi divides , the separate remainder value needs to be reincorporated into any following math which adds extra code and where possible should be avoided until you need the result reading back into PBP
anyone having to add longs , where only1 or 2 longs may be need should look at Nbit math as a possible alternative , more so when flash space is tight and longs are an expensive overhead in compile space.
cheers
Sheldon
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.