PDA

View Full Version : Aliasing Ports



anj
- 1st March 2004, 03:33
Gday all
I have been mucking around with multiple DS18B20 temperature sensors ( on different ports )
I need to read the status of the port, then run the temp conversion routine. My problem is i have removable sensors, and if the sensor is removed whilst the process is going on, it never returns from the read loop.
To get around this i have "switched" connectors and can poll the status of the port, and if i get a certain result, i know the sensor is removed and can act accordingly.
I have tried to make the reads into a std subroutine but come a cropper if the ports are not aliased by the pins numbering
I am wondering if there is a way to referentially access a port within a subroutine, if it doesnt have a related pins id.
ie
'read sensor1 on port B2
Retval = 0
Refport = PORTB.1
gosub DoRead
sensor1val = retval
'read sensor2 on port B3
Retval = 0
Refport = PORTB.3
gosub DoRead
sensor2val = retval

DoRead
if RefPort = 1 then ' no sensor RefPort here is a referential link to a real port by name, not number
' read sensor
' process value
Retval = calculated value
return

I have been able to use pin ID integers in some cases but some functions require a real PORTX.Y syntax.
I can define this once but i want to be able to change this programmatically, for as many sensors as i have.
Is this possible?
Andrew