so as a bit of summery to date , what i have seen and do to reduce code size and ram allocation are as follows.
But this is no where near complete , but add / correct where needed !!!
1. Use the correct variable size – eg bit byte word
2. Where multi flags are required of setup myflags as a byte, with variable = myflags.0, for each flag
Code:Myflags var byte Timeout_flag_0 var Myflags.0 Timeout_flag_1 var Myflags.1 Fade_flags_0 var Myflags.2 Fade_flags_1 var Myflags.3
3. Keep variables that are used in subroutine to min and reuse in each subroutine ( don’t forget to set to 0 in each routine at start)
4. Keep Global variables to small number and to a byte
5. When doing a read such as pulsin , and using a word variable , if accuracy is not as a big issue for other processing then dont assign words to an array with the results / divide the result so a byte value in array is used
6 where practical for code reading and structure , replace case select code with if , then statementsCode:FOR X = 0 TO 31 ' grab 32 incoming pulses PULSIN IR,1,leader ' now measuring high-going pulse widths ( pulsin_max set to 21600 = 108ms ) BtnVal(x) = leader/2 ' leader divide by 2 so array Btnval(x) is byte (<255) not word value NEXT X
7 replace if x= 1 And y=1 then statements , with multi if statements , uses less words in compileCode:if DByte[4] = $6F then ' Red - remote 1 read remotetype + Red ,STDByte[4] ' read eeprom remote 2 location + button offset STDByte[3] = (~ STDByte[4]) ' bitwise Not the value of byte4 to be byte3 endif if DByte[4] = $4F then ' Btn01 - remote 1 read remotetype + Btn01 ,STDByte[4] ' read eeprom remote 2 location + button offset STDByte[3] = (~ STDByte[4]) ' bitwise Not the value of byte4 to be byte3 endif if DByte[4] = $57 then ' Btn02 - remote 1 read remotetype + Btn02 ,STDByte[4] ' read eeprom remote 2 location + button offset STDByte[3] = (~ STDByte[4]) ' bitwise Not the value of byte4 to be byte3 endif if DByte[4] = $67 then ' Btn03 - remote 1 read remotetype + Btn03 ,STDByte[4] ' read eeprom remote 2 location + button offset STDByte[3] = (~ STDByte[4]) ' bitwise Not the value of byte4 to be byte3 endif
8. when doing a read from a table in eeprom , its better to multi reads than keep in variables
9. assigning constants with a variable name and use as the offset in lookup table and then doing a read at that location is better than using a variable for each name in the table
10 love DT_int14.bas , routines but has high hit on ram on small pics , so better to use for all interrupts for timers , IOC etc , than setting up other code to monitor interrupt flags outside of DT routines
11 math calculations , not sure , not had to do much of those where its been an issue ??


so as a bit of summery to date , what i have seen and do to reduce code size and ram allocation are as follows.


Bookmarks