'Remote IO Demo func main() dim cmdidx dim cmd dim cmddat0,cmddat1 dim timeoutcounter clear 'Lets use the hardware Uart hsersetup baud,HBAUD115200,start,txon,inwait,1000 '------------------------------------------------------ 'This is the main loop. At this point we collect the ' data. Once we have two bytes we go and process the ' commands. '------------------------------------------------------ cmdloop: inc timeoutcounter if timeoutcounter > 5 then timeoutcounter = 0 cmdidx = 0 goto cmdloop endif hserin cmdloop,cmd timeoutcounter = 0 branch cmdidx , cmd0, cmd1 'Fall through cmdidx = 0 goto cmdloop 'This is the first byte. It will be used to tell us what to do ' with the second byte. cmd0: cmddat0 = cmd cmdidx = cmdidx + 1 goto cmdloop 'This is the second byte. In our case its always the port number cmd1: cmddat1 = cmd cmdidx = 0 goto proccmds '-------------------------------------------------- 'At this point we have all the data lets process 'the data. The first byte is our command byte. '-------------------------------------------------- proccmds: branch cmddat0,dosetinput,dosetoutput,dogetinput,dosetoutputhigh,dosetoutputlow 'Fall through BAD COMMAND goto cmdloop dosetinput: input cmddat1 goto cmdloop dosetoutput: output cmddat1 goto cmdloop dogetinput: hserout ioport(cmddat1) goto cmdloop dosetoutputhigh: high cmddat1 goto cmdloop dosetoutputlow: low cmddat1 goto cmdloop endfunc