Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4745

Structured Array

$
0
0
I have been working on an idea for structured arrays with named elements eg
say i have a battery charger that can charge multiple batteries
each battery has these properties voltage[byte] current[word] pwm_drive[word] current_limit[word] status[byte]
thats 8 bytes per battery
;define structure batteries for pbp
struct_items con 10 ;10 index size ie number of batteries
struct_sz_of con 8 ;total 8 bytes / index

;elements byte offset of each element
volts CON 0;byte
amps CON 1;word
drive CON 3;word
climit con 5;word
stat con 7;byte
reserve our memory
battery var byte[ struct_items*struct_sz_of ]
some user commands
USERCOMMAND "ARRAY_GET" ;{array,}index,element{,var}
USERCOMMAND "ARRAY_PUT" ;index,element,DATA

we now have some nice commands ,j=byte test=word a_index=byte
array_get 2,DRIVE
array_put 2,DRIVE,1234
array_get 3,AMPS
a_index=1
array_get a_index,volts,j
array_get a_index,drive,test
even multiple arrays
array_get battery,a_index,volts,j
this is a work in progress ,whats lacking is a way to tell the usercommand the "size" of our elements as they are accessed .
at present the macros are customised to suit
Attached Files

Viewing all articles
Browse latest Browse all 4745

Trending Articles