SX/B compiler error / address 295 is not whithin lower half of memory page?
High all, I'm writing one of my first larger programs for the SX, it's not huge but I'm getting this error
Line 238, error 44, pass2: Address 295 is not within lower half of memory page
Here's the program.. Sorry for the poor programming syntex I am working on it.· Any help would be appriciated.· I think one of the first things to do is make a subroutine for the pause command.· Other than that?
Russ
' =========================================================================
'
'·· File...... PhotoTimer
'·· Purpose... Help take time lapse photos
'·· Author....· Russell Wizinsky
'·· E-mail....· russw@professorwiz.com
'·· Started...· 4/16/07 for the Basic stamp
'·revision..· 8/20/07 for the Parallax SX Chip
'·· Updated...· 8/26/07
' =========================================================================
'
' Program Description
'
' Program will close shutter switch at set timed intervals.·
' One button will adjust the timing,
' timing will be shown as a number 0-9 on the 7 segment display
' When start button is depressed camera will start taking photos
' When start button is depressed again.· Camera will stop and
' 7 segment display will flash out count of how many pictures it took
' until the adjust button is pressed again.
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
' IO Pins
'
'RC Pins for Output for 7 Segment Display
'RB0 Pin for Pushbutton for start
'RB1 Change timing of shutter
'RB2 Output for Test LED
'RB3 Solid state Cmos switch
Segments··PIN·RC··output·'7 Segment display
StartButton··PIN·RB.0·INPUT·'PushButton Switch
TimeButton··Pin·RB.1·Input·'PushButton Switch
Shutter···Pin·RB.2·output·'Output to Cmos switch
'
' Constants
'
ISPRESSED ··CON·1·'FOR ACTIVE-HIGH INPUT
ISNOTPRESSED·CON·0
ISOpen···Con 1·'Shutter is opened
IsClosed··Con·0·'Shutter is closed
'
' Variables
'
idx····VAR······ BYTE·' Index for Data of 7 Segment display
counter··· ··VAR··············· Word ' timing variable
time····· ··VAR··············· Word ' variable for rc time
del1····· ··VAR··············· Word ' Delay Variable
pics······ ··VAR··············· Word ' Number of pictures taken
' =========================================================================
· PROGRAM Start
' =========================================================================
'
'··········· PROGRAM CODE
'
Start:
'gosub DisplayTiming
·Do
··read dig_map + counter, segments
··If TimeButton = ispressed then
···do
···loop until TimeButton = isnotpressed
···Inc counter
···If counter = 10 then
····counter = 0
···Endif
···Pause 250
··EndIf
·loop until· StartButton = ispressed
·Do
·loop until StartButton = isnotpressed·'Don't start until button is released
·gosub calctime·······'Calculate time between pictures
·gosub takepics·······'Trigger the shutter at calcuated time
·gosub dispcount·······'Display how many pictures where taken
Pause 1000
goto start
'
'··········· SUBROUTINES
'
····························
calctime:······················· 'Caclulate time between frames selected by pushbutton
··· IF counter = 0 THEN
·del1 = 1····· 'Time interval 1 sec
··· ENDIF
·IF counter = 1 THEN
·del1 = 2····· 'Time interval 2 sec
··· ENDIF
·IF counter = 2 THEN
·del1 = 3····· 'Time interval 3 sec
·ENDIF···
·IF counter = 3 THEN
·del1 = 5····· 'Time interval 5 sec
·ENDIF···
·IF counter = 4 THEN
·del1 = 10···· 'Time interval 10 sec
··· ENDIF
·IF counter = 5 THEN
·del1 = 20···· 'Time interval 20 sec
·ENDIF
··· IF counter = 6 THEN
·del1 = 30···· 'Time interval 30 sec
·ENDIF
··· IF counter = 7 THEN
·del1 = 50···· 'Time interval 50 sec
·ENDIF
··· IF counter = 8 THEN
·del1 = 100··· 'Time interval 100 sec
·ENDIF
··· IF counter = 9 THEN
·del1 = 120··· 'Time interval 120 sec
·ENDIF
RETURN
TakePics:········'Trigger the shutter at calcuated time
Do
Shutter = ISOpen
pause 50
Shutter = ISClosed
pause del1
loop until· StartButton = ispressed
RETURN
DispCount:········'Display how many pictures where taken
RETURN
'
' end of form
'
'data
'
DIG_MAP:
··'· BAFG.CDE
·DATA ·%11100111·'0
·DATA·%10000100·'1
·DATA·%11010011·'2
·DATA·%11010110·'3
·DATA·%10110100·'4
·DATA·%01110110·'5
·DATA·%01110111·'6
·DATA·%11000100·'7
·DATA·%11110111·'8
·DATA·%11110110·'9
Line 238, error 44, pass2: Address 295 is not within lower half of memory page
Here's the program.. Sorry for the poor programming syntex I am working on it.· Any help would be appriciated.· I think one of the first things to do is make a subroutine for the pause command.· Other than that?
Russ
' =========================================================================
'
'·· File...... PhotoTimer
'·· Purpose... Help take time lapse photos
'·· Author....· Russell Wizinsky
'·· E-mail....· russw@professorwiz.com
'·· Started...· 4/16/07 for the Basic stamp
'·revision..· 8/20/07 for the Parallax SX Chip
'·· Updated...· 8/26/07
' =========================================================================
'
' Program Description
'
' Program will close shutter switch at set timed intervals.·
' One button will adjust the timing,
' timing will be shown as a number 0-9 on the 7 segment display
' When start button is depressed camera will start taking photos
' When start button is depressed again.· Camera will stop and
' 7 segment display will flash out count of how many pictures it took
' until the adjust button is pressed again.
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
' IO Pins
'
'RC Pins for Output for 7 Segment Display
'RB0 Pin for Pushbutton for start
'RB1 Change timing of shutter
'RB2 Output for Test LED
'RB3 Solid state Cmos switch
Segments··PIN·RC··output·'7 Segment display
StartButton··PIN·RB.0·INPUT·'PushButton Switch
TimeButton··Pin·RB.1·Input·'PushButton Switch
Shutter···Pin·RB.2·output·'Output to Cmos switch
'
' Constants
'
ISPRESSED ··CON·1·'FOR ACTIVE-HIGH INPUT
ISNOTPRESSED·CON·0
ISOpen···Con 1·'Shutter is opened
IsClosed··Con·0·'Shutter is closed
'
' Variables
'
idx····VAR······ BYTE·' Index for Data of 7 Segment display
counter··· ··VAR··············· Word ' timing variable
time····· ··VAR··············· Word ' variable for rc time
del1····· ··VAR··············· Word ' Delay Variable
pics······ ··VAR··············· Word ' Number of pictures taken
' =========================================================================
· PROGRAM Start
' =========================================================================
'
'··········· PROGRAM CODE
'
Start:
'gosub DisplayTiming
·Do
··read dig_map + counter, segments
··If TimeButton = ispressed then
···do
···loop until TimeButton = isnotpressed
···Inc counter
···If counter = 10 then
····counter = 0
···Endif
···Pause 250
··EndIf
·loop until· StartButton = ispressed
·Do
·loop until StartButton = isnotpressed·'Don't start until button is released
·gosub calctime·······'Calculate time between pictures
·gosub takepics·······'Trigger the shutter at calcuated time
·gosub dispcount·······'Display how many pictures where taken
Pause 1000
goto start
'
'··········· SUBROUTINES
'
····························
calctime:······················· 'Caclulate time between frames selected by pushbutton
··· IF counter = 0 THEN
·del1 = 1····· 'Time interval 1 sec
··· ENDIF
·IF counter = 1 THEN
·del1 = 2····· 'Time interval 2 sec
··· ENDIF
·IF counter = 2 THEN
·del1 = 3····· 'Time interval 3 sec
·ENDIF···
·IF counter = 3 THEN
·del1 = 5····· 'Time interval 5 sec
·ENDIF···
·IF counter = 4 THEN
·del1 = 10···· 'Time interval 10 sec
··· ENDIF
·IF counter = 5 THEN
·del1 = 20···· 'Time interval 20 sec
·ENDIF
··· IF counter = 6 THEN
·del1 = 30···· 'Time interval 30 sec
·ENDIF
··· IF counter = 7 THEN
·del1 = 50···· 'Time interval 50 sec
·ENDIF
··· IF counter = 8 THEN
·del1 = 100··· 'Time interval 100 sec
·ENDIF
··· IF counter = 9 THEN
·del1 = 120··· 'Time interval 120 sec
·ENDIF
RETURN
TakePics:········'Trigger the shutter at calcuated time
Do
Shutter = ISOpen
pause 50
Shutter = ISClosed
pause del1
loop until· StartButton = ispressed
RETURN
DispCount:········'Display how many pictures where taken
RETURN
'
' end of form
'
'data
'
DIG_MAP:
··'· BAFG.CDE
·DATA ·%11100111·'0
·DATA·%10000100·'1
·DATA·%11010011·'2
·DATA·%11010110·'3
·DATA·%10110100·'4
·DATA·%01110110·'5
·DATA·%01110111·'6
·DATA·%11000100·'7
·DATA·%11110111·'8
·DATA·%11110110·'9
Comments
Check out this link:
http://forums.parallax.com/showthread.php?p=594708
It's a thread on this forum that explains the problem you're having. Also, check out the sticky at the top of this forum titled Best SX Threads index ....updated 7-11-07. Lots of good info there, including the answer to your problem.
Thanks,
PeterM
Note that toward the end of that help section you find this statement, “Subroutines do not have to be declared, but doing so allows the subroutine code to be placed anywhere in the listing (without declaration the code must be in the first half of a code page)”.
- Sparks
I added the delay used in page 95, I declared it as a sub.· Declared the tmpW1 as a word variable, and it's giving me a INVALID PARAMETER "_PARAMCNT".·
'USE:· DELAY_MS ms
'-- 'ms' is delay in milliseconds, 1 - 65535
SUB DELAY_MS
·if _PARAMCNT = 1 then
··tmpW1 = _PARAM1
·else
··tmpW1 = _WPARAM12
·endif
·pause tmpW1
·ENDSUB
I looked though the thread you had pointed me to and I couldn't see where the problem came up except when someone was using interupts. I'm not using any of those. I did scan though the best of and just didn't see anything that pointed me to that problem.
Russ
The special aliases such as “__PARAMCNT” start with TWO underscore characters. Some fonts make this particularly difficult to observe.
- Sparks
It's there, but it's not the most obvious thing to find. Look for the group called "SX error messages and quirks."
Then look for the topic called "SX-B code page-Addresses ...."
BTW, the first link I provided is the direct link to "SX-B code page-Addresses ...."
Thanks,
PeterM
Here's the updated code.
' =========================================================================
'
'·· File...... PhotoTimer
'·· Purpose... Help take time lapse photos
'·· Author....· Russell Wizinsky
'·· E-mail....· russw@professorwiz.com
'·· Started...· 4/16/07 for the Basic stamp
'·· revision..· 8/20/07 for the Parallax SX Chip
'·· Updated...· 8/28/07
' =========================================================================
'
' Program Description
'
' Program will close shutter switch at set timed intervals.·
' One button will adjust the timing,
' timing will be shown as a number 0-9 on the 7 segment display
' When start button is depressed camera will start taking photos
' When start button is depressed again.· Camera will stop and
' 7 segment display will flash out count of how many pictures it took
' until the adjust button is pressed again.
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
' IO Pins
'
'RC Pins for Output for 7 Segment Display
'RB0 Pin for Pushbutton for start
'RB1 Change timing of shutter
'RB2 Output for Test LED
'RB3 Solid state Cmos switch
Segments··PIN·RC·output·'7 Segment display
StartButton··PIN·RB.0·INPUT·'PushButton Switch
TimeButton··PIN·RB.1·Input·'PushButton Switch
testled···PIN·RB.2·output·'Test LED
Shutter···PIN·RB.3·output·'Output to Cmos switch
'
' Constants
'
ISPRESSED ··CON·1·'FOR ACTIVE-HIGH INPUT
ISNOTPRESSED·CON·0
ISOpen···Con 1·'Shutter is opened
IsClosed··Con·0·'Shutter is closed
'
' Variables
'
idx····VAR······ BYTE·' Index for Data of 7 Segment display
counter··· ··VAR··············· Word ' timing variable
time····· ··VAR··············· Word ' variable for rc time
del1····· ··VAR··············· Word ' Delay Variable
pics······ ··VAR··············· Word ' Number of pictures taken
tmpW1···VAR······ Word ' Delay in MS
'
'· Subroutines DECLARATIONS
'
DELAY_MS··SUB···1,2
TakePics··SUB···0
Dispcount··SUB···0
calctime··SUB···0
'
'· Subroutines
'
'USE:· DELAY_MS ms
'-- 'ms' is delay in milliseconds, 1 - 65535
SUB DELAY_MS
·if __PARAMCNT = 1 then
··tmpW1 = __PARAM1
·else
··tmpW1 = __WPARAM12
·endif
·pause tmpW1
·ENDSUB
'
SUB DispCount········'Display how many pictures where taken
ENDSUB
'
SUB calctime··············
··· IF counter = 0 THEN
·del1 = 1····· 'Time interval 1 sec
··· ENDIF
·IF counter = 1 THEN
·del1 = 2····· 'Time interval 2 sec
··· ENDIF
·IF counter = 2 THEN
·del1 = 3····· 'Time interval 3 sec
·ENDIF···
·IF counter = 3 THEN
·del1 = 5····· 'Time interval 5 sec
·ENDIF···
·IF counter = 4 THEN
·del1 = 10···· 'Time interval 10 sec
··· ENDIF
·IF counter = 5 THEN
·del1 = 20···· 'Time interval 20 sec
·ENDIF
··· IF counter = 6 THEN
·del1 = 30···· 'Time interval 30 sec
·ENDIF
··· IF counter = 7 THEN
·del1 = 50···· 'Time interval 50 sec
·ENDIF
··· IF counter = 8 THEN
·del1 = 100··· 'Time interval 100 sec
·ENDIF
··· IF counter = 9 THEN
·del1 = 120··· 'Time interval 120 sec
·ENDIF
ENDSUB
'
SUB TakePics········'Trigger the shutter at calcuated time
Do
Shutter = ISOpen
DELAY_MS 50
Shutter = ISClosed
DELAY_MS del1
loop until· StartButton = ispressed
ENDSUB
' =========================================================================
· PROGRAM Start
' =========================================================================
'
'··········· PROGRAM CODE
'
Start:
'gosub DisplayTiming
·Do
··read dig_map + counter, segments
··If TimeButton = ispressed then
···do
···loop until TimeButton = isnotpressed
···Inc counter
···If counter = 10 then
····counter = 0
···Endif
···DELAY_MS 250
··EndIf
·loop until· StartButton = ispressed
·Do
·loop until StartButton = isnotpressed·'Don't start until button is released
·gosub calctime·······'Calculate time between pictures
·gosub takepics·······'Trigger the shutter at calcuated time
·gosub dispcount·······'Display how many pictures where taken
DELAY_MS 1000
goto start
'
'data
'
DIG_MAP:
··'· BAFG.CDE
·DATA ·%11100111·'0
·DATA·%10000100·'1
·DATA·%11010011·'2
·DATA·%11010110·'3
·DATA·%10110100·'4
·DATA·%01110110·'5
·DATA·%01110111·'6
·DATA·%11000100·'7
·DATA·%11110111·'8
·DATA·%11110110·'9
If I comment out the lines with the nested if then statement it compiles fine.?!
Start:
'DisplayTiming + change timing
Do
read dig_map + counter, segments
If TimeButton = ispressed then
do
loop until TimeButton = isnotpressed
Inc counter
'If counter = 10 then
' counter = 0
'ENDIF
DELAY_MS 250
EndIf
loop until StartButton = ispressed
Do
loop until StartButton = isnotpressed 'Don't start until button is released
gosub calctime 'Calculate time between pictures
gosub takepics 'Trigger the shutter at calcuated time
gosub dispcount 'Display how many pictures where taken
DELAY_MS 1000
goto start
Russ
You could also use READ instead of LOOKUP if you wanted to have a bigger table of time values.
In use, you'd do this:
For the greatest code re-use you'll want to avoid using global variables in your subroutines and functions -- instead, pass values back and forth as parameters.
I added the lines in, and it's giving me an invalid number of parameters on the line that calls it up. It makes good sense to make reusable code, and I knew there had to be a cleverer way to do what I was doing.· Thanks for the tip, and any help you can give me what I did wrong.
Here's the main loop
'DisplayTiming + change timing
·Do
··read dig_map + counter, segments
··If TimeButton = ispressed then
···do
···loop until TimeButton = isnotpressed
···Inc counter
···IF counter = 10 then
····counter = 0
····DELAY_MS 1
···ENDIF
···DELAY_MS 250
··EndIf
·loop until· StartButton = ispressed
·Do
·loop until StartButton = isnotpressed·'Don't start until button is released
·counter = CALC_TIME·del1····'Calculate time between pictures
·takepics·······'Trigger the shutter at calcuated time
·dispcount·······'Display how many pictures where taken
DELAY_MS 1000
goto start
Here's the Function section:
'
'· FUNCTIONS
'
FUNC CALC_TIME
·TMPB1 = __PARAM1
·LOOKUP TMPB1, 1, 2, 3, 5, 10, 20, 30, 50, 100, 120, TMPB1
·RETURN TMPB1
·ENDFUNC
In this line
······· READ Dig_Map + idx, Segments
······· Segments.3 = 1
I assume that the Segments.3 would change the digit for the dot which would be the 3rd one over in Binary correct?· Sorry for a simple question, still learning.
Russ