Using multiple READ commands
Hello,
I have included a small program here with which I do need some help.
What I am trying to do is run a program with different values. What I would like to do is load some numbers into certian variables using the READ command from DATA tables. Which DATA table to read would be based upon dipswitch settings. I would like to load the DATA into the variables, then use these to run the program. Switching the dipswitches after the program is running will have no effect upon the values, switching the dipswitches, then pressing reset will load and use the values from a different DATA table.
Enclosed is·a basic·program for explaining my concept. The actual program will have more DATA tables and more variables.
My concern is the amout of·memory that all these READ statements take up.·There must be·a better way to do it. A loop possibly to use one READ statement? I'm not seeing a way to do it in a subroutine either, unless I'm missing something.
I also see in the SX/B help manual a mention of reading DATA in an array format, but don't see a good example. Perhaps this is a solution?
Is there also a better way to read the dip switches?
Thanks for the help,
Alex
'
' Program Description
'
' This is a sample problem to use different data based upon dipswitch settings
' and load them into variables for use by the program.
'
' Device Settings
'
DEVICE········· SX48, OSCXT1
FREQ··········· 4_000_000
ID··"SXB 1.50"
'
' IO Pins
'
DipRead0·PIN·RA.0·INPUT
DipRead1·PIN·RA.1·INPUT
DipRead2·PIN·RA.2·INPUT
'
' Constants
'
IsOff··CON·0
IsOn··CON·1
'
' Variables
'
VHigh··VAR·Byte
VMed··VAR·Byte
VLow··VAR·Byte
' =================================
· PROGRAM Start
' =================================
'
' Subroutine Declarations
'
'
' Program Code
'
Start:
· ' initialization code here
IF Dipread0 = IsOn THEN
· READ DipTable0 +1, VHigh
· READ DipTable0 +2, VMed
· READ DipTable0 +3, VLow
· ELSEIF Dipread1 = IsOn THEN
··· READ DipTable0 +1, VHigh
··· READ DipTable0 +2, VMed
··· READ DipTable0 +3, VLow
··· ELSEIF Dipread2 = IsOn THEN
····· READ DipTable0 +1, VHigh
····· READ DipTable0 +2, VMed
····· READ DipTable0 +3, VLow
ENDIF
Main:·····' run program with above variables
· BREAK
· WATCH VHigh
· WATCH VMed
· WATCH VLow
· END
'
' Subroutine Code
'
' =================================
' User Data
' =================================
DipTable0:
· DATA 100
· DATA 120
· DATA 130
DipTable1:
· DATA 110
· DATA 130
· DATA 150
DipTable2:
· DATA 120
· DATA 140
· DATA 160
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If at first you don't succeed, then skydiving is not for you.
I have included a small program here with which I do need some help.
What I am trying to do is run a program with different values. What I would like to do is load some numbers into certian variables using the READ command from DATA tables. Which DATA table to read would be based upon dipswitch settings. I would like to load the DATA into the variables, then use these to run the program. Switching the dipswitches after the program is running will have no effect upon the values, switching the dipswitches, then pressing reset will load and use the values from a different DATA table.
Enclosed is·a basic·program for explaining my concept. The actual program will have more DATA tables and more variables.
My concern is the amout of·memory that all these READ statements take up.·There must be·a better way to do it. A loop possibly to use one READ statement? I'm not seeing a way to do it in a subroutine either, unless I'm missing something.
I also see in the SX/B help manual a mention of reading DATA in an array format, but don't see a good example. Perhaps this is a solution?
Is there also a better way to read the dip switches?
Thanks for the help,
Alex
'
' Program Description
'
' This is a sample problem to use different data based upon dipswitch settings
' and load them into variables for use by the program.
'
' Device Settings
'
DEVICE········· SX48, OSCXT1
FREQ··········· 4_000_000
ID··"SXB 1.50"
'
' IO Pins
'
DipRead0·PIN·RA.0·INPUT
DipRead1·PIN·RA.1·INPUT
DipRead2·PIN·RA.2·INPUT
'
' Constants
'
IsOff··CON·0
IsOn··CON·1
'
' Variables
'
VHigh··VAR·Byte
VMed··VAR·Byte
VLow··VAR·Byte
' =================================
· PROGRAM Start
' =================================
'
' Subroutine Declarations
'
'
' Program Code
'
Start:
· ' initialization code here
IF Dipread0 = IsOn THEN
· READ DipTable0 +1, VHigh
· READ DipTable0 +2, VMed
· READ DipTable0 +3, VLow
· ELSEIF Dipread1 = IsOn THEN
··· READ DipTable0 +1, VHigh
··· READ DipTable0 +2, VMed
··· READ DipTable0 +3, VLow
··· ELSEIF Dipread2 = IsOn THEN
····· READ DipTable0 +1, VHigh
····· READ DipTable0 +2, VMed
····· READ DipTable0 +3, VLow
ENDIF
Main:·····' run program with above variables
· BREAK
· WATCH VHigh
· WATCH VMed
· WATCH VLow
· END
'
' Subroutine Code
'
' =================================
' User Data
' =================================
DipTable0:
· DATA 100
· DATA 120
· DATA 130
DipTable1:
· DATA 110
· DATA 130
· DATA 150
DipTable2:
· DATA 120
· DATA 140
· DATA 160
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If at first you don't succeed, then skydiving is not for you.
Comments
Read all the variables with one READ command.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·
I never thought of making the READ table address a variable, this sure made it simple.
Thanks Bean.
Alex
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If at first you don't succeed, then skydiving is not for you.