Need Help With Code Please?
Archiver
Posts: 46,084
Hi Group,
I need to pick your minds again please.
I have the following code in a program, and as you can see it's
pretty cumbersome. I an sure that it can be shortened to one loop
and I can work out how to read the eprom within a loop, I just can't
work out how to assign the read iiformation to the variable within a
loop. I have only posted the first two days here, but of course it
goes on for all seven days. Can anyone please show me how I can
shorten this code? I know this is embarrasingly simple to most, but
I just can't get my dumb head around it [noparse]:)[/noparse]
if it's monday it goes to lookupmonday..........
LookUpMonday
read setmonday+0,haon.lowbyte
read setmonday+1,haon.highbyte
read setmonday+2,haoff.lowbyte
read setmonday+3,haoff.highbyte
read setmonday+4,fpon.lowbyte
read setmonday+5,fpon.highbyte
read setmonday+6,fpoff.lowbyte
read setmonday+7,fpoff.highbyte
goto setmode
LookupTuesday:
read settuesday+0,haon.lowbyte
read settuesday+1,haon.highbyte
read settuesday+2,haoff.lowbyte
read settuesday+3,haoff.highbyte
read settuesday+4,fpon.lowbyte
read settuesday+5,fpon.highbyte
read settuesday+6,fpoff.lowbyte
read settuesday+7,fpoff.highbyte
goto setmodet how
I need to pick your minds again please.
I have the following code in a program, and as you can see it's
pretty cumbersome. I an sure that it can be shortened to one loop
and I can work out how to read the eprom within a loop, I just can't
work out how to assign the read iiformation to the variable within a
loop. I have only posted the first two days here, but of course it
goes on for all seven days. Can anyone please show me how I can
shorten this code? I know this is embarrasingly simple to most, but
I just can't get my dumb head around it [noparse]:)[/noparse]
if it's monday it goes to lookupmonday..........
LookUpMonday
read setmonday+0,haon.lowbyte
read setmonday+1,haon.highbyte
read setmonday+2,haoff.lowbyte
read setmonday+3,haoff.highbyte
read setmonday+4,fpon.lowbyte
read setmonday+5,fpon.highbyte
read setmonday+6,fpoff.lowbyte
read setmonday+7,fpoff.highbyte
goto setmode
LookupTuesday:
read settuesday+0,haon.lowbyte
read settuesday+1,haon.highbyte
read settuesday+2,haoff.lowbyte
read settuesday+3,haoff.highbyte
read settuesday+4,fpon.lowbyte
read settuesday+5,fpon.highbyte
read settuesday+6,fpoff.lowbyte
read settuesday+7,fpoff.highbyte
goto setmodet how
Comments
You have 7 days, numbered day=0 to day=6. Your eeprom data has 8
bytes (4 words) per day, starting at "setmonday".
' setpoints in eeprom. Call monday, day=0.
setmonday data word 1234,word 4321,word 5432, word 2345
settuesday data word 9876, word ...
' .... and so on 4 words per day
'define your 4 variables _in order_:
haon var word
haon0 var haon.byte0 ' byte sized alias
haoff var word
fpon var word
fpoff var word
'routine to read the setpoints
' enter with day=0,1,...,6
for i=0 to 7
read day*8+i+setmonday,haon0(i)
next
setmode:
' and so on ... that's it!
The trick is to define the variables _in order_, and to define the
first byte of the first word (haon0 var haon.byte0) as an alias. The
program loop grabs the bytes from eeprom in order and assigns them to
the variables. The loop calculates the offset into eeprom depending
on the the day number, the loop index, and the start of the data.
You might wonder about mixing bytes and words in a way that makes
everything come out all right. The Stamp stores data least
significant byte first, both in eeprom with (DATA word 1234) and in
RAM.
-- Tracy
>Hi Group,
>
>I need to pick your minds again please.
>
>I have the following code in a program, and as you can see it's
>pretty cumbersome. I an sure that it can be shortened to one loop
>and I can work out how to read the eprom within a loop, I just can't
>work out how to assign the read iiformation to the variable within a
>loop. I have only posted the first two days here, but of course it
>goes on for all seven days. Can anyone please show me how I can
>shorten this code? I know this is embarrasingly simple to most, but
>I just can't get my dumb head around it [noparse]:)[/noparse]
>
>if it's monday it goes to lookupmonday..........
>
>LookUpMonday
> read setmonday+0,haon.lowbyte
> read setmonday+1,haon.highbyte
> read setmonday+2,haoff.lowbyte
> read setmonday+3,haoff.highbyte
> read setmonday+4,fpon.lowbyte
> read setmonday+5,fpon.highbyte
> read setmonday+6,fpoff.lowbyte
> read setmonday+7,fpoff.highbyte
>goto setmode
>
>LookupTuesday:
> read settuesday+0,haon.lowbyte
> read settuesday+1,haon.highbyte
> read settuesday+2,haoff.lowbyte
> read settuesday+3,haoff.highbyte
> read settuesday+4,fpon.lowbyte
> read settuesday+5,fpon.highbyte
> read settuesday+6,fpoff.lowbyte
> read settuesday+7,fpoff.highbyte
>goto setmodet how