Another Function Question
Mike W
Posts: 105
I wanted to declare the following subroutine as a Function because I wanted it to return two variables signF and degF
I need more information about using FUNC and ENDFUNC.
And the RETURN degF, signF command before the endfunc
I am currently using SXB 1_51_03 The help file doesn’t really·get into·their use
I am familiar with using the label followed by a colon: (GET_TEMP[noparse]:)[/noparse] and ending with return
·
·
·
GET_TEMP·········· ··············· FUNC··············· 2, 0········· ······························· ··············· ' read temperature
·
'
FUNC GET_TEMP·········· ······························· ······························· ··············· ··············· ' read temperature in celsius and
·· Temp_Reset = 1······································ ····································································· ·' convert to fahrenheit
··· SHIFTOUT Temp_I_O, Temp_Clock, LSBFIRST, StartConvert·························· ·' start conversion
·· Temp_Reset = 0······················································
·DO······························································································
·· Temp_Reset = 1······················································
··· SHIFTOUT Temp_I_O, Temp_Clock, LSBFIRST, ReadConfig·························· ·' command read configuration register
···· SHIFTIN Temp_I_O, Temp_Clock, LSBPRE, tmpB1············ ······························ ' bit7 Wait for conversion to complete
·· Temp_Reset = 0······································ ··································································· ' 0 = still converting
·LOOP UNTIL tmpB1.7 = 1·········· ······························· ······························· ··············· ·' 1 = conversion complete
· Temp_Reset = 1························································
··· SHIFTOUT Temp_I_O, Temp_Clock, LSBFIRST, ReadTemp········· ··············· ' command read converted temperature
···· SHIFTIN Temp_I_O, Temp_Clock, LSBPRE, degC·············································' get celsius temp 8 bits
···· SHIFTIN Temp_I_O, Temp_Clock, LSBPRE, signC\1······· ······························ ' get celsius sign 1 bit 1=neg 0=pos
·· Temp_Reset = 0·······························································································
··· IF signC = 1 THEN···················· ······························· ··············· ····························· ' when degrees celsius goes negitave
···· degC = ~degC· ······························· ······························· ······································ ·' you need to convert degC from
··· ENDIF··············· ······························· ······························· ··············· ······················· ·' 2's compliment
···· tmp2 = degC.0· ······························· ······························· ······································· · ' save degC half bit
····· degC = degC >> 1······················· ······························· ··············· ·························· ·' remove half bit
··········· tmpW1 = degC */ $01CC····· ······························· ········································ · ' degC x 1.8 (9/5)
············ degF = tmpW1_LSB ······· ······························· ··············· ································ ·' if .5 degrees celsius
············ degF = degF + tmp2········· ······························· ··············· ······························· ·' then add 1 to degF
········ IF signC = 1 THEN····································································
·········· IF degF >= 32 THEN·································································
··········· degF = degF - 32·······································································
············ signF = NEGATIVE···········································································
·········· ELSE···············································································
··········· degF = 32 - degF······································································
············ signF = POSITIVE·············································································
·········· ENDIF························································································
········· ELSE·············································································
·········· degF = degF + 32··············································································
··········· signF = POSITIVE·············································································
········ ENDIF··········································································································
·RETURN··············· degF, signF·····················································································
ENDFUNC
'
·
·
·
·
Thanks
Mike
I need more information about using FUNC and ENDFUNC.
And the RETURN degF, signF command before the endfunc
I am currently using SXB 1_51_03 The help file doesn’t really·get into·their use
I am familiar with using the label followed by a colon: (GET_TEMP[noparse]:)[/noparse] and ending with return
·
·
·
GET_TEMP·········· ··············· FUNC··············· 2, 0········· ······························· ··············· ' read temperature
·
'
FUNC GET_TEMP·········· ······························· ······························· ··············· ··············· ' read temperature in celsius and
·· Temp_Reset = 1······································ ····································································· ·' convert to fahrenheit
··· SHIFTOUT Temp_I_O, Temp_Clock, LSBFIRST, StartConvert·························· ·' start conversion
·· Temp_Reset = 0······················································
·DO······························································································
·· Temp_Reset = 1······················································
··· SHIFTOUT Temp_I_O, Temp_Clock, LSBFIRST, ReadConfig·························· ·' command read configuration register
···· SHIFTIN Temp_I_O, Temp_Clock, LSBPRE, tmpB1············ ······························ ' bit7 Wait for conversion to complete
·· Temp_Reset = 0······································ ··································································· ' 0 = still converting
·LOOP UNTIL tmpB1.7 = 1·········· ······························· ······························· ··············· ·' 1 = conversion complete
· Temp_Reset = 1························································
··· SHIFTOUT Temp_I_O, Temp_Clock, LSBFIRST, ReadTemp········· ··············· ' command read converted temperature
···· SHIFTIN Temp_I_O, Temp_Clock, LSBPRE, degC·············································' get celsius temp 8 bits
···· SHIFTIN Temp_I_O, Temp_Clock, LSBPRE, signC\1······· ······························ ' get celsius sign 1 bit 1=neg 0=pos
·· Temp_Reset = 0·······························································································
··· IF signC = 1 THEN···················· ······························· ··············· ····························· ' when degrees celsius goes negitave
···· degC = ~degC· ······························· ······························· ······································ ·' you need to convert degC from
··· ENDIF··············· ······························· ······························· ··············· ······················· ·' 2's compliment
···· tmp2 = degC.0· ······························· ······························· ······································· · ' save degC half bit
····· degC = degC >> 1······················· ······························· ··············· ·························· ·' remove half bit
··········· tmpW1 = degC */ $01CC····· ······························· ········································ · ' degC x 1.8 (9/5)
············ degF = tmpW1_LSB ······· ······························· ··············· ································ ·' if .5 degrees celsius
············ degF = degF + tmp2········· ······························· ··············· ······························· ·' then add 1 to degF
········ IF signC = 1 THEN····································································
·········· IF degF >= 32 THEN·································································
··········· degF = degF - 32·······································································
············ signF = NEGATIVE···········································································
·········· ELSE···············································································
··········· degF = 32 - degF······································································
············ signF = POSITIVE·············································································
·········· ENDIF························································································
········· ELSE·············································································
·········· degF = degF + 32··············································································
··········· signF = POSITIVE·············································································
········ ENDIF··········································································································
·RETURN··············· degF, signF·····················································································
ENDFUNC
'
·
·
·
·
Thanks
Mike
Comments
Thanks for the reply however I have read through the help files and am still unclear on when I need to use the syntax
FUNC Label
or just
Label:
I realize that if you dont user the (FUNC Label) that you cannot use the ENDFUNC after the return. I just dont understand the correct usage·or the·advantages over one or the other.
If I define A function, and then label it with only A colon after the Label what happens.
mike
How are you trying to assign the function results ?
Please post the entire program... It makes things alot easier when we don't have to guess what you're trying to do.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Uhhhm, that was on fire when I got here...
www.iElectronicDesigns.com
·
Mike
When you use a function you usually use "var = functionname" this sets "var" to the value returned by the function.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Uhhhm, that was on fire when I got here...
www.iElectronicDesigns.com
·
All I wanted to do is display these two values (degF, signF) to a lcd display. which it did as a sub I am mearly trying to understand if it would be better programing by using the Function definition
Start:········'
· PLP_C = %00000111······' pull up unused pins
· LcdOut = 1 ·······' make output pin high
· WAIT_MS 100·······' let lcd initialize
degF = GET_TEMP
signC = GET_TEMP
As always Thank You
Mike