Reducing if .. then statements.
tore eilertsen
Posts: 15
Hi again..
Another problem. (when one is solved ....)
I have build a rather nice board housing 4 x PCF 8574 that gives 32 I/O ports, and working perfect.
I'm mainly using this ports for INPUT, and here is the problem
This is giving A LOTT of if .. then statements ( 8 per chip), and uses up almost all my programing space in the bs2p40.
Thanks to Phil Pilgrim and others in the forum I use
inbyte VAR Byte
mybit VAR inbyte.BIT4
...
IF (mybit) THEN action
action:
return
to decode which one of the ports is active
Now to my question Is there a clever way to reduce the amount of lines to do the decoding job ???
Another problem. (when one is solved ....)
I have build a rather nice board housing 4 x PCF 8574 that gives 32 I/O ports, and working perfect.
I'm mainly using this ports for INPUT, and here is the problem
This is giving A LOTT of if .. then statements ( 8 per chip), and uses up almost all my programing space in the bs2p40.
Thanks to Phil Pilgrim and others in the forum I use
inbyte VAR Byte
mybit VAR inbyte.BIT4
...
IF (mybit) THEN action
action:
return
to decode which one of the ports is active
Now to my question Is there a clever way to reduce the amount of lines to do the decoding job ???
Comments
My curiosity has gotten the best of me. Why do you need 72 I/O ports. There are 40 I/O ports already on a BS2P40 and your external chips add yet another 32 I/O ports.
If you think you're using up all the memory on your BS-2P40, my guess is you're not familiar with the 8 banks of 2K memory each (16K non-contiguous, total), that's available on that particular Stamp.
With a BS2P40 you can use the POLLING feature to determine which native ports are active. You will need to interrogate each of the external chips to determine what's active there.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The ting is that one of my hobbies is pinball machines (60's and 70's) some time ago I came over a machine that only
consisted of a complte playfield and backbox, the 'cpu' was missing, so I thought it could be funm trying to get it up and
runing wth some modern tech. playfiled form 72 and a basicstamp ... an unusual combination..
If one count over the switches, lamps and solenoids, you come to an impressive no of i/o ports..
tore
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Can you give us a sample of using ON ... GOTO, and ON ... GOSUB ?
I know I will be running into similar problem very soon.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Fernando Gomez
Never compare yourself with anyone else, there will always be someone bigger·or·smaller·than you.
ON idx GOTO Case_0, Case_1, Case_2 ──·where idx is a variable (in this case it's 0 , 1, or 2) and based on that variable the program will branch to a subroutine.
Put another way:
range·VAR nib
ON range GOTO low, med_low, med, med_high, high
So, range = {0, 1, 2, 3, 4}·--
when range = 0, the program will GOTO subroutine low
·····"·····= 1,··················"·············· med_low
·····"···· = 2,··················"···············med
·····"···· = 3,················· "···············med_high
·····"···· = 4,··················"·············· high
ANd ON...GOSUB works in a similar fashion, but GOSUB'ing entails a·RETURN to the ON...GOSUB, eventually; whereas with ON...GOTO you can run amok if you like.