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
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
Last edited by Amoque; - 10th September 2015 at 13:27. Reason: Sorry, missed Richard's post above.
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
Code:' 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
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
yes have a done this - saved some space there - thanksEvent1_OT_Hour=Event1_OT_Hour min 23
http://www.picbasic.co.uk/forum/showthread.php?t=19949can i store the data as a word and then get it back as a byte or if needed a word if so how
re reading the post make it clearDT - 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.
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
thanks richard
i am using darrels hi and low interupts services
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.
Code: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 your program uses the watchdog timer, there will be some buried in all of that.Code:'if Event_Penalty_Sec <1 if Event_Penalty_Sec =0
You should get away with only one for that entire slab,Code:DEFINE NO_CLRWDT
and sprinkle any others only where needed
definitely if there are any nops in code they can be replaced with them.Code:@ clrwdt
Last edited by Art; - 11th September 2015 at 20:42.
this:
this should work instead (directly replaced) :Code: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
and if that still works, you might as well:Code: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
then if it still works, you should be able to:Code: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
Now this is still assuming I haven’t broken it yet, you can:Code:memorysavelookup: lookup val-thingyousubtract,[1,2,4,8,16,32],val goto Show_current_sel_2
Code: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
Last edited by Art; - 11th September 2015 at 20:56.
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)
Code: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
Last edited by Art; - 11th September 2015 at 21:29.
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
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
Code: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
I’m glad if it saved some memory... I made a bigger post but it looks to have disappeared.
yes i am the point that every bit really counts even a large change to get a small result has its merits
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
13 words
Code: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
Code: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
thanks richard that little change got back 600 byte over all
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
Code: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,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_ $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$3F,$FC,$00,$3F,$FC,$00,$3F,$FC,_ $00,$3F,$FC,$00,$3F,$FC,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_ $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
Code:'=================== 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
16 bytes to a line is goodCode:LG_Font_Base: @ db 0x00,0x00,...................................
good
note 64k address limitCode:@ GetAddress _LG_Font_Base, _Font_Base_Address
Code:@ 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
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.
Code:if Event2_OT_Min <1 then Event2_OT_Min = 0
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
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
or i guess readcode can reads in a word value and i swap it in the routine some how
unfortunalty the for /next loop of x_scan can be 2 or 3 so not easy to break into even words -mm darn
Bookmarks