{"id":1921,"date":"2025-04-14T11:25:43","date_gmt":"2025-04-14T11:25:43","guid":{"rendered":"https:\/\/webprojects.cloud\/wordpress\/splatco\/?post_type=spl_knowledgebase&#038;p=1921"},"modified":"2025-06-10T08:48:37","modified_gmt":"2025-06-10T08:48:37","slug":"sx10504-example-program","status":"publish","type":"spl_knowledgebase","link":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/","title":{"rendered":"SX10504: Example program"},"content":{"rendered":"\n<h6 class=\"wp-block-heading\">Example program demonstrating how to interface with a SX10504<\/h6>\n\n\n\n<pre class=\"wp-block-preformatted\"> \n \n* For use with MMI202 and SX10504 *\n* 2x16 LCD *\n \n** Setup **\n \n* The SX10504 is interfaced to the MMI202 over <a href=\"https:\/\/www.splatco.com\/skb\/352.htm#o3808\">X<\/a>-Wire protocol by setting the communications jumper to \n* \tthe X position.\n* No board ID jumpers are installed as the X-Wire address for the SX10504 is address 0.\n* If it is a MMI202 the X-Wire cable is connected from the Spice connector on the MMI202 to the X1 connector on the SX10504.\n* If it is a MMI202a the X-Wire cable is connected from the CN12 connector on the MMI202a to the X1 connector on the SX10504. \n* 10k thermistors are connected to the analog inputs and the associated jumpers are set to the T position.\n \n** Program operation **\n \n* The thermistor drive voltage is set to 10 volts.\n \n* Conductivity Channels. \n* \tThese can be triggered by causing conduction to ground.\n* \tInput 0 on the MMI202 will toggle the Conductivity Control bit which will turn on and off all conductivity\n*\tchannels.\n \n* Pressing front panel button IN8 advances to the next screen.\n \n* Analog Inputs.\n*\tFrom left to right fAI_AnIn0, fAI_AnIn1, fAI_AnIn2.\n*\tInput voltage is displayed for the analog inputs.\n \n* Pressing front panel button IN8 advances to the next screen.\n \n* Analog Outputs.\n*\tFrom left to right fAO_AnOut0, fAO_AnOut1.\n*\tCurrent output voltage is displayed for the analog outputs.\n* \tPressing front panel button IN12 increments AnOut0 by 1 volt.\n* \tPressing front panel button IN11 decrements AnOut0 by 1 volt.\n* \tPressing front panel button IN10 increments AnOut1 by 1 volt.\n* \tPressing front panel button IN9 decrements AnOut1 by 1 volt.\n*\tThe voltage range is 0 to 10 Volts.\n \n* If at any time there are Xwire communications errors the front panel LED on output 15 will light.\n \n* Equates *\n \n* XWire Receive data block *\n* Data block of 13 bytes *\n \nfAI_Anin0:\t\tmequ\t\t100,4\t;Location where Analog Input 0 from SX10504 is returned. \nfAI_Anin1:\t\tmequ\t\t104,4\t;Location where Analog Input 1 from SX10504 is returned. \nfAI_Anin2:\t\tmequ\t\t108,4\t;Location where Analog Input 2 from SX10504 is returned. \nbCC_Conduct_Data:\tmequ\t\t112\t;Bits 0-4 conductivity channels (reads back true when conducting). \n \t\t\t\t\t\t;Bit 7 = readings available bit (reads back true when reading ready).\n \n* XWire Transmit data block *\n* Data block of 13 bytes *\n \nfAO_Anout0:\t\tmequ\t\t10,4\t;Location where Analog Output 0 value is stored for SX10504 to take.\nfAO_Anout1:\t\tmequ\t\t14,4\t;Location where Analog Output 1 value is stored for SX10504 to take.\nbAI_Thermistor_Drive:\tmequ\t\t18,4\t;Location where Thermistor Drive value is stored for SX10504 to take.\nbCC_CCB:\t\tmequ\t\t22\t;Bits 0-6 conductivity channels time factor.\n \t\t\t\t\t\t;Bit 7 disables ALL channels when set true.\n \n* Input equates *\n \niCC_ConductToggle:\tiequ\t\t0\t;this input is used to toggle the conductivity control bit, to force on\/off conductivity testing.\niAO_AnOut0_Up_Btn:\tiequ\t\t12\t;increments analog output 0 by 10%\niAO_AnOut0_Dn_Btn:\tiequ\t\t11\t;decrements analog output 0 by 10%\niAO_AnOut1_Up_Btn:\tiequ\t\t10\t;increments analog output 1 by 10%\t\niAO_AnOut1_Dn_Btn:\tiequ\t\t9\t;decrements analog output 1 by 10%\n \n* Output Equates *\n \noXW_XWireError:\t\toequ\t\t15\t;LED turns on when there is an Xwire communication error.\t\n \n *******************\n ** Program start **\n *******************\n \nStart\n \t\tXwireMaster \tXWireTab\t\t;start xwire going\n\t\tlaunchtask\tAnalog_Out_Task\t\t;start the Analog Output task running\n\t\tlaunchtask\tAnalog_In_Task\t\t;start the Analog Input task running\n\t\tlaunchtask\tConductivity_Task\t;start the Conductivity Task running\n\t\tlaunchtask\tLCD_Task\t\t;start the Display task running\n\t\tlaunchtask\tXwire_Task\t\t;start the XWire error checking task running\n\t\truntasksforever\n \n \n \n ************************\n ** Analog Output Task **\n ************************\n \n* Entry points * \n \nAO_GET_AnOut0:\n\t\tfrecallw\tfAO_Anout0              ;recall user set analog out 0 voltage (returns value in W as a value 0-1)\n\t\treturn\nAO_GET_AnOut1:\n\t\tfrecallw\tfAO_Anout1              ;recall user set analog out 1 voltage (returns value in W as a value 0-1)   \n                return\n                \nAnalog_Out_Task:\n \nAO0:\n\t\tyieldtask\n\t\tgoifink\t\tiAO_AnOut0_Up_Btn,AO1\t;does the user wish to increase the voltage on AnOut 0?\n\t\tgoifink\t\tiAO_AnOut0_Dn_Btn,AO3\t;does the user wish to decrease the voltage on AnOut 0?\n \n\t\tgoifink\t\tiAO_AnOut1_Up_Btn,AO5\t;does the user wish to increase the voltage on AnOut 1?\n\t\tgoifink\t\tiAO_AnOut1_Dn_Btn,AO7\t;does the user wish to decrease the voltage on AnOut 1?\n\t\tgoto\t\tAO0\n \n ;; AnOut0 ;;\n \nAO1:\n\t\tfrecallq\tfAO_Anout0\t\t;limit check to prevent attempting to set voltage higher than maximum\n\t\tfloadw\t\t.9\n\t\tfsub\n\t\tfgoifpos\tAO2\n \t\t\n\t\tfrecallq\tfAO_Anout0\t\t;below upper limit so increment AnOut 0 value by 10%\n\t\tfloadw\t\t.1\n\t\tfadd\n\t\tfstore\t\tfAO_Anout0\n\t\tgoto\t\tAO0\nAO2:\n\t\tfloadw\t\t1\t\t\t;reached limit so increment no further\n\t\tfstore\t\tfAO_Anout0\t\n\t\tgoto\t\tAO0\nAO3:\n\t\tfrecallq\tfAO_Anout0\t\t;limit check to prevent attempting to set voltage lower than minimum\n\t\tfloadw\t\t.1\n\t\tfsub\n\t\tfgoifneg\tAO4\n \n\t\tfrecallq\tfAO_Anout0\t\t;above lower limit so decrement AnOut 0 value by 10%\n\t\tfloadw\t\t.1\n\t\tfsub\n\t\tfstore\t\tfAO_Anout0\n\t\tgoto\t\tAO0\nAO4:\n\t\tfloadw\t\t0\t\t\t;reached limit so decrement no further\n\t\tfstore\t\tfAO_Anout0\t\n\t\tgoto\t\tAO0\n \n ;; AnOut1 ;;\n \nAO5:\n\t\tfrecallq\tfAO_Anout1\t\t;limit check to prevent attempting to set voltage higher than maximum\n\t\tfloadw\t\t.9\n\t\tfsub\n\t\tfgoifpos\tAO6\n \t\t\n\t\tfrecallq\tfAO_Anout1\t\t;below upper limit so increment AnOut 0 value by 10%\n\t\tfloadw\t\t.1\n\t\tfadd\n\t\tfstore\t\tfAO_Anout1\n\t\tgoto\t\tAO0\nAO6:\n\t\tfloadw\t\t1\t\t\t;reached limit so increment no further\n\t\tfstore\t\tfAO_Anout1\t\n\t\tgoto\t\tAO0\nAO7:\n\t\tfrecallq\tfAO_Anout1\t\t;limit check to prevent attempting to set voltage lower than minimum\n\t\tfloadw\t\t.1\n\t\tfsub\n\t\tfgoifneg\tAO8\n \n\t\tfrecallq\tfAO_Anout1\t\t;above lower limit so decrement AnOut 0 value by 10%\n\t\tfloadw\t\t.1\n\t\tfsub\n\t\tfstore\t\tfAO_Anout1\n\t\tgoto\t\tAO0\nAO8:\n\t\tfloadw\t\t0\t\t\t;reached limit so decrement no further\n\t\tfstore\t\tfAO_Anout1\t\n\t\tgoto\t\tAO0\n \n \n ***********************\n ** Analog Input Task **\n ***********************\n \n* Define Memory *\n \t\t\nfAI_AnalogVal0:\t\t\tdefFloat\t\t;Where the data from the returned analog reading is stored as a voltage.\nfAI_AnalogVal1:\t\t\tdefFloat\t\t\nfAI_AnalogVal2:\t\t\tdefFloat\t\t\n \n* Entry points *\n \nAI_GET_AnIn0:\n\t\tfrecallw\tfAI_AnalogVal0\t\t;display task gets the analog input voltage value. (Return in W as value 0-5V)\n\t\treturn\nAI_GET_AnIn1:\n\t\tfrecallw\tfAI_AnalogVal1\t\n\t\treturn\nAI_GET_AnIn2:\n\t\tfrecallw\tfAI_AnalogVal2\t\n\t\treturn\n \nAnalog_In_Task:\n\t\tfloadw\t\t.5\t\t\t;set thermistor drive voltage to 10 volts \n\t\tfstore\t\tbAI_Thermistor_Drive\n\t\tpause\t\t200\t\t\t;allow the drive voltage to settle\nAI0:\n\t\tyieldtask\n\t\tfrecallw\tfAI_Anin0\t\t;get the analog reading from AnIn channel 0.\n\t\tfloadq\t\t5\t\t\t;load Q with maximum possible analog input voltage. (5 volts)\n\t\tfmul\t\t\t\t\t;multiply to convert to volts.\n\t\tfstore \t\tfAI_AnalogVal0\t\t;store calculation.\n \n\t\tfrecallw\tfAI_Anin1\t\t;get the analog reading from AnIn channel 1.\n\t\tfloadq\t\t5\t\t\t;load Q with maximum possible analog input voltage. (5 volts)\n\t\tfmul\t\t\t\t\t;multiply to convert to volts.\n\t\tfstore \t\tfAI_AnalogVal1\t\t;store calculation.\n \n\t\tfrecallw\tfAI_Anin2\t\t;get the analog reading from AnIn channel 2.\n\t\tfloadq\t\t5\t\t\t;load Q with maximum possible analog input voltage. (5 volts)\n\t\tfmul\t\t\t\t\t;multiply to convert to volts.\n\t\tfstore \t\tfAI_AnalogVal2\t\t;store calculation.\n\t\tgoto\t\tAI0\n \n *******************************\n ** Conductivity Channel Task **\n *******************************\n \n* Define Memory *\n \nbCC_Conduct_Ch1:\tdefbyte\t\t\t\t;byte is true when channel is conducting and is false when it is not.\nbCC_Conduct_Ch2:\tdefbyte\t\t\t\t\nbCC_Conduct_Ch3:\tdefbyte\t\t\t\t\nbCC_Conduct_Ch4:\tdefbyte\t\t\t\t\t\nbCC_Conduct_Ch5:\tdefbyte\t\t\t\t\t\n \n* Entry points *\n \nCC_GET_CondCh1:\n\t\trecall\t\tbCC_Conduct_Ch1\t\t;returns a true in X if conducting and false if not conducting.\n\t\treturn\nCC_GET_CondCh2:\n\t\trecall\t\tbCC_Conduct_Ch2\t\t\n\t\treturn\nCC_GET_CondCh3:\n\t\trecall\t\tbCC_Conduct_Ch3\t\t\n\t\treturn\nCC_GET_CondCh4:\n\t\trecall\t\tbCC_Conduct_Ch4\t\t\n\t\treturn\nCC_GET_CondCh5:\n\t\trecall\t\tbCC_Conduct_Ch5\t\t\n\t\treturn\n \nConductivity_Task:\n                loadx\t\t%00111011\t\t;enable conductivity testing by clearing bit 7.\n\t\t\t\t\t\t\t;set the conductivity time factor by setting appropriate bits of 0-6. (59 + 1) x .05 = 3 seconds.\n\t\tstore\t\tbCC_CCB\nCC0:\t\t\t\t\t\t\t\n\t\tyieldtask\n\t\tgoifink\t\tiCC_ConductToggle,CC1\t;toggle the conductivity control bit to enable\/disable conductivity channels.\n\t\tgoto\t\tCC3\nCC1:\n\t\trecall\t\tbCC_CCB\n\t\tloadx\t\t%10000000\n\t\tandm\t\t\t\t\t;separate the conductivity control 'bit' out of the Conductivity Control 'Byte'\n\t\tgoift\t\tCC2\n \t\t\n\t\trecall\t\tbCC_CCB\t\t\t;bit previously not set so OR %10000000 with CCB to set bit.\n\t\tloadx\t\t%10000000\n\t\torm\n\t\tstore\t\tbCC_CCB\n\t\tgoto\t\tCC3\nCC2:\n\t\trecall\t\tbCC_CCB\t\t\t;bit previously was set so AND %01111111 with CCB to Clear bit.\n\t\tloadx\t\t%01111111\n\t\tandm\n\t\tstore\t\tbCC_CCB\nCC3:\n \n ;; Check if reading is valid ;;\n \n\t\trecall\t\tbCC_Conduct_Data\n\t\tloadx\t\t%10000000\n\t\tandm\n\t\tgoiff\t\tCC0\t\t\t;if bit 7 is true then conductivity channel readings are stable and ready to be read.\n \n ;; Check conductivity channels ;;\n \n\t\trecall\t\tbCC_Conduct_Data\t\t;check conductivity channel 5\n\t\tloadx\t\t%00010000\t\t;mask all unwanted bits\n\t\tandm\t\t\t\t\t\n\t\tstore\t\tbCC_Conduct_Ch5\t\t;store channel status\n \n\t\trecall\t\tbCC_Conduct_Data\t\t;check conductivity channel 4\n\t\tloadx\t\t%00001000\t\t;mask all unwanted bits\n\t\tandm\n\t\tstore\t\tbCC_Conduct_Ch4\t\t;store channel status\n \n\t\trecall\t\tbCC_Conduct_Data\t\t;check conductivity channel 3\n\t\tloadx\t\t%00000100\t\t;mask all unwanted bits\n\t\tandm\n\t\tstore\t\tbCC_Conduct_Ch3\t\t;store channel status\n \n\t\trecall\t\tbCC_Conduct_Data\t\t;check conductivity channel 2\n\t\tloadx\t\t%00000010\t\t;mask all unwanted bits\n\t\tandm\n\t\tstore\t\tbCC_Conduct_Ch2\t\t;store channel status\n \t\t\n\t\trecall\t\tbCC_Conduct_Data\t\t;check conductivity channel 1\n\t\tloadx\t\t%00000001\t\t;mask all unwanted bits\n\t\tandm\n\t\tstore\t\tbCC_Conduct_Ch1\t\t;store channel status\n\t\tgoto\t\tCC0\n \n ******************\n ** Display Task **\n ******************\n \n* Input equates *\n \niLCD_Cycle:\tiequ\t\t8\t\t\t;this input is used to cycle the data on the LCD\n \nLCD_Task:\n\t\toblcd_CLS\n        \t\t\n ;; Display Conductivity channels ;;\n        \t\t\nLCD0:           \n                yieldtask\n\t\tgoifink\t\tiLCD_Cycle,LCD10\t;if toggle button is pressed change LCD display\n\t\toblcd_setcur\t0,0\n\t\t;\t\t\"0123456789012345\"\n\t\toblcd_text\t\"Chan: 1 2 3 4 5 \"\n\t\toblcd_setcur\t1,0\n\t\toblcd_text\t\"Cond: \"\n\t\tgosub\t\tCC_GET_CondCh1\t\t;get channel 1 current conductivity status. Returned in X as true if conducting.\n\t\tgoifF\t\tLCD1\n\t\toblcd_text\t\"Y \"\t\t\t;yes channel is conducting\n\t\tgoto\t\tLCD2\t\t\nLCD1:\t\t\n\t\toblcd_text\t\"N \"\t\t\t;no channel is not conducting\t\t\nLCD2:\n\t\tgosub\t\tCC_GET_CondCh2\t\t;get channel 2 current conductivity status. Returned in X as true if conducting.\n\t\tgoifF\t\tLCD3\n\t\toblcd_text\t\"Y \"\t\t\t;yes channel is conducting\n\t\tgoto\t\tLCD4\t\t\nLCD3:\t\t\n\t\toblcd_text\t\"N \"\t\t\t;no channel is not conducting\t\t\nLCD4:\n\t\tgosub\t\tCC_GET_CondCh3\t\t;get channel 3 current conductivity status. Returned in X as true if conducting.\n\t\tgoifF\t\tLCD5\n\t\toblcd_text\t\"Y \"\t\t\t;yes channel is conducting\n\t\tgoto\t\tLCD6\t\t\nLCD5:\t\t\n\t\toblcd_text\t\"N \"\t\t\t;no channel is not conducting\t\t\nLCD6:\n\t\tgosub\t\tCC_GET_CondCh4\t\t;get channel 4 current conductivity status. Returned in X as true if conducting.\n\t\tgoifF\t\tLCD7\n\t\toblcd_text\t\"Y \"\t\t\t;yes channel is conducting\n\t\tgoto\t\tLCD8\t\t\nLCD7:\t\t\n\t\toblcd_text\t\"N \"\t\t\t;no channel is not conducting\t\t\nLCD8:\n\t\tgosub\t\tCC_GET_CondCh5\t\t;get channel 5 current conductivity status. Returned in X as true if conducting.\n\t\tgoifF\t\tLCD9\n\t\toblcd_text\t\"Y \"\t\t\t;yes channel is conducting\n\t\tgoto\t\tLCD0\t\t\nLCD9:\t\t\n\t\toblcd_text\t\"N \"\t\t\t;no channel is not conducting\t\n\t\tgoto\t\tLCD0\n \n ;; Display Analog Inputs ;;\n\t \nLCD10:\n\t\tyieldtask\n\t\tgoifink\t\tiLCD_Cycle,LCD_17\t;if toggle button is pressed change LCD display\n\t\toblcd_setcur\t0,0\n\t\t;\t\t\"0123456789012345\"\n\t\toblcd_text\t\"Analog Inputs:  \"\n\t\toblcd_setcur\t1,0\n\t\tgosub\t\tAI_GET_AnIn0   \n \n ;; Check for LCD formatting issue ;;\n  \n                gosub           CF_Lower                ;check lower limit, FALSE will return in X if it is NOT a floating point value of 1\n                goiff           LCD_11                  ;if returns TRUE check the upper limit\n \n ;; Analog In 0 ;;\n  \n \t        gosub\t        AI_GET_AnIn0\n                gosub           CF_Upper                ;check upper limit, FALSE will return in X if it is NOT a floating point value of 1        \n                goiff           LCD_11                  ;if returns TRUE run the LCD formatting issue workaround        \n        \toblcd_text\t\"1.0\"                   ;value to display is floating point value of 1, therefore use OBLCD_Text instruction to display 1.0\n                goto            LCD_12        \nLCD_11: \n\t\tgosub\t\tAI_GET_AnIn0       \n\t\toblcd_fdispw\t3,1\t\t\t;display AnIn channel 0 voltage\nLCD_12:\n\t\toblcd_text\t\"V \"\t\t\n \n ;; Analog In 1 ;;\n  \n\t\tgosub\t\tAI_GET_AnIn1\n                gosub           CF_Lower                ;check lower limit, FALSE will return in X if it is NOT a floating point value of 1\n                goiff           LCD_13                  ;if returns TRUE check the upper limit\n\t        gosub\t        AI_GET_AnIn1\n                gosub           CF_Upper                ;check upper limit, FALSE will return in X if it is NOT a floating point value of 1        \n                goiff           LCD_13                  ;if returns TRUE run the LCD formatting issue workaround \n        \toblcd_text\t\"1.0\"                   ;value to display is floating point value of 1, therefore use OBLCD_Text instruction to display 1.0\n                goto            LCD_14        \t\nLCD_13:        \n\t\tgosub\t\tAI_GET_AnIn1\n\t\toblcd_fdispw    3,1\t\t\t;display AnIn channel 1 voltage  \nLCD_14:\t\t\n\t\toblcd_text\t\"V \"\t\n \n ;; Analog In 2 ;;\n  \n\t\tgosub\t\tAI_GET_AnIn2\n                gosub           CF_Lower                ;check lower limit, FALSE will return in X if it is NOT a floating point value of 1\n                goiff           LCD_15                  ;if returns TRUE run the LCD formatting issue workaround\n\t        gosub\t        AI_GET_AnIn2\n                gosub           CF_Upper                ;check upper limit, FALSE will return in X if it is NOT a floating point value of 1        \n                goiff           LCD_15                  ;if returns TRUE run the LCD formatting issue workaround         \n        \toblcd_text\t\"1.0\"                   ;value to display is floating point value of 1, therefore use OBLCD_Text instruction to display 1.0\n                goto            LCD_16\nLCD_15:        \n\t\tgosub\t\tAI_GET_AnIn2\n\t\toblcd_fdispw    3,1\t\t\t;display AnIn channel 2 voltage\nLCD_16:\n\t\toblcd_text\t\"V  \"\n\t\tgoto\t\tLCD10\n \n ;; Display Analog Outputs ;;\n \nLCD_17:\n\t\tyieldtask\n\t\tgoifink\t\tiLCD_Cycle,LCD0\t\t;if toggle button is pressed change LCD display\n\t\toblcd_setcur\t0,0\n\t\t;\t\t\"0123456789012345\"\n\t\toblcd_text\t\"Analog Outputs: \"\n\t\toblcd_setcur\t1,0\n \n ;; Analog Out 0 ;;\n  \t\n\t        gosub           AO_Get_AnOut0\t\t;recalls user set voltage in W as a value 0-1\n\t\tfloadq\t\t10     \t\t\t;load Q with maximum possible output voltage\n\t\tfmul\t\t\t\t\t;multiply to get user set voltage out\t\n  \n ;; Check for LCD formatting issue ;;\n  \n                gosub           CF_Lower                ;check lower limit, FALSE will return in X if it is NOT a floating point value of 1\n                goiff           LCD_18                  ;if returns TRUE check the upper limit\n\t        gosub           AO_Get_AnOut0\t\t;recalls user set voltage in W as a value 0-1\n\t\tfloadq\t\t10     \t\t\t;load Q with maximum possible output voltage\n\t\tfmul\t\t\t\t\t;multiply to get user set voltage out\n                gosub           CF_Upper                ;check upper limit, FALSE will return in X if it is NOT a floating point value of 1        \n                goiff           LCD_18                  ;if returns TRUE run the LCD formatting issue workaround        \n        \toblcd_text\t\"1.0\"                   ;value to display is floating point value of 1, therefore use OBLCD_Text instruction to display 1.0\n                goto            LCD_19        \nLCD_18: \t\n\t        gosub           AO_Get_AnOut0\t\t;recalls user set voltage in W as a value 0-1\n\t\tfloadq\t\t10     \t\t\t;load Q with maximum possible output voltage\n\t\tfmul\t\t\t\t\t;multiply to get user set voltage out\n\t\toblcd_fdispw    3,1\t\t\t;display AnOut channel 0 voltage\t\nLCD_19:\t\n\t\toblcd_text\t\"V \"    \n \n ;; Analog Out 1 ;;\n  \t\t\n\t        gosub           AO_Get_AnOut1\t\t;recalls user set voltage in W as a value 0-1\n\t\tfloadq\t\t10     \t\t\t;load Q with maximum possible output voltage\n\t\tfmul\t\t\t\t\t;multiply to get user set voltage out\t\n  \n ;; Check for LCD formatting issue ;;\n  \n                gosub           CF_Lower                ;check lower limit, FALSE will return in X if it is NOT a floating point value of 1\n                goiff           LCD_20                  ;if returns TRUE check the upper limit\n\t        gosub           AO_Get_AnOut1\t\t;recalls user set voltage in W as a value 0-1\n\t\tfloadq\t\t10     \t\t\t;load Q with maximum possible output voltage\n\t\tfmul\t\t\t\t\t;multiply to get user set voltage out\n                gosub           CF_Upper                ;check upper limit, FALSE will return in X if it is NOT a floating point value of 1        \n                goiff           LCD_20                  ;if returns TRUE run the LCD formatting issue workaround        \n        \toblcd_text\t\"1.0\"                   ;value to display is floating point value of 1, therefore use OBLCD_Text instruction to display 1.0\n                goto            LCD_21        \nLCD_20: \t\n\t        gosub           AO_Get_AnOut1\t\t;recalls user set voltage in W as a value 0-1\n\t\tfloadq\t\t10     \t\t\t;load Q with maximum possible output voltage\n\t\tfmul\t\t\t\t\t;multiply to get user set voltage out\n\t\toblcd_fdispw    3,1\t\t\t;display AnOut channel 0 voltage\t\nLCD_21:\t\n\t\toblcd_text\t\"V      \"\n\t\tgoto\t\tLCD_17\n \n \n;; Subroutines ;;\n \n ;; Check Floating point value of 1 ;;\n   \nCF_Lower:                                               ;following subroutines test if LCD formatting workaround needs to be run.\n                floadq          .95\n                fsub\n                fgoifpos        CF_0\n\t\tloadx           255                     ;Return with X TRUE if above lower limit check, this will cause an upper limit check.\n\t\tgoto            CF_1 \nCF_0:          \n                loadx           0                       ;Return FALSE in X if no action is needed\nCF_1:           return\n \nCF_Upper:\n                floadq          1.05\n                fsub\n                fgoifneg        CF_2\n\t\tloadx           255                     ;Return with X TRUE if both limit checks find the floating point number is 1 and-\n\t\tgoto            CF_3                    ;LCD format workaround needs to be run\nCF_2:              \n                loadx           0                       ;Return FALSE in X if no action is needed\nCF_3:           return       \n \n \n ****************************\n ** Xwire Error Check Task **\n ****************************\n \nXwire_Task:\n \nXW0:\n\t\tyieldtask\n\t\txwiregeterrcount\t\t\t;get the xwire error count\n\t\tgoiff\t\tXW1\n\t\ton\t\toXW_XWireError\t\t;turn on error LED if there are XWire errors\n\t\tpause\t\t1\n\t\tgoto\t\tXW0\nXW1:\t\toff\t\toXW_XWireError\t\n\t\tgoto\t\tXW0\n \n \n ** X-Wire Master table **\n \n        NVEM0\nXWireTab:\n        NV0Byte         0,10,13,100,13\t\t\t;slave address 0, memory 10 is transmit data block, 13 bytes, 100 is Receive data block, 13 bytes.\n        NV0Byte         255    ;End of table sentinel.\n <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Example program demonstrating how to interface with a SX10504 * For use with MMI202 and SX10504 * * 2&#215;16 LCD * ** Setup ** *&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1903,"menu_order":7,"template":"","class_list":["post-1921","spl_knowledgebase","type-spl_knowledgebase","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SX10504: Example program - SPLat Controls<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SX10504: Example program - SPLat Controls\" \/>\n<meta property=\"og:description\" content=\"Example program demonstrating how to interface with a SX10504 * For use with MMI202 and SX10504 * * 2x16 LCD * ** Setup ** *...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/\" \/>\n<meta property=\"og:site_name\" content=\"SPLat Controls\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-10T08:48:37+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/\",\"name\":\"SX10504: Example program - SPLat Controls\",\"isPartOf\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website\"},\"datePublished\":\"2025-04-14T11:25:43+00:00\",\"dateModified\":\"2025-06-10T08:48:37+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Product documentation\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Product documentation: Xwire peripherals\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"SX10504: Water Level Detector + Analog I\/O\",\"item\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"SX10504: Example program\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\",\"name\":\"SPLat Controls\",\"description\":\"OEM Embedded Machine Controllers\",\"publisher\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization\",\"name\":\"SPLat Controls\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg\",\"contentUrl\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg\",\"caption\":\"SPLat Controls\"},\"image\":{\"@id\":\"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SX10504: Example program - SPLat Controls","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"SX10504: Example program - SPLat Controls","og_description":"Example program demonstrating how to interface with a SX10504 * For use with MMI202 and SX10504 * * 2x16 LCD * ** Setup ** *...","og_url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/","og_site_name":"SPLat Controls","article_modified_time":"2025-06-10T08:48:37+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/","name":"SX10504: Example program - SPLat Controls","isPartOf":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website"},"datePublished":"2025-04-14T11:25:43+00:00","dateModified":"2025-06-10T08:48:37+00:00","breadcrumb":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/sx10504-example-program\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/"},{"@type":"ListItem","position":2,"name":"Product documentation","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/"},{"@type":"ListItem","position":3,"name":"Product documentation: Xwire peripherals","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/"},{"@type":"ListItem","position":4,"name":"SX10504: Water Level Detector + Analog I\/O","item":"https:\/\/webprojects.cloud\/wordpress\/splatco\/knowledgebase\/product-documentation\/product-documentation-xwire-peripherals\/sx10504-water-level-detector-analog-i-o\/"},{"@type":"ListItem","position":5,"name":"SX10504: Example program"}]},{"@type":"WebSite","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#website","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/","name":"SPLat Controls","description":"OEM Embedded Machine Controllers","publisher":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webprojects.cloud\/wordpress\/splatco\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#organization","name":"SPLat Controls","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/","url":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg","contentUrl":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-content\/uploads\/2024\/10\/logo.svg","caption":"SPLat Controls"},"image":{"@id":"https:\/\/webprojects.cloud\/wordpress\/splatco\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase\/1921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase"}],"about":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/types\/spl_knowledgebase"}],"author":[{"embeddable":true,"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/users\/1"}],"up":[{"embeddable":true,"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/spl_knowledgebase\/1903"}],"wp:attachment":[{"href":"https:\/\/webprojects.cloud\/wordpress\/splatco\/wp-json\/wp\/v2\/media?parent=1921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}