PDA

View Full Version : Software Multiplexing???



tommyc
01-21-2006, 01:19 AM
I am reading serial data into a BS2 from two sensors, and would like to reduce the program space required to process the input data (which is handled identically).·

Is there a way to use the same subroutine for two sets of I/O pins and variables?

Bruce Bates
01-21-2006, 01:30 AM
Tommy -

Sure, make the pin port number a variable name, and set it as you see fit.

Regards,

Bruce Bates

Jon Williams
01-21-2006, 01:38 AM
Here's one way to implement Bruce's suggestion:

SensorPin··· DATA··· 12, 15

sensorDat··· VAR··· ·Byte(2)
idx··········VAR···· Nib

Get_Sensors:
· FOR idx = 0 TO 1
··· READ SensorPin + idx,·sio
··· SERIN sio, Baud, [sensorDat(idx)]
· NEXT
· RETURN

If your serial pins are contiguous (grouped together), you can set the value of sio with math instead of reading the pin numbers from a table.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax