In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Mike_W wrote: 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:) 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 ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=274196 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)