I am after a little more info on the 'AddressOf" command.
Some background...
I have the below sub routine. It's job is to check a series of sensors and if each sensor is active then it sends some data to a speaker.
The issue i have is that the order in which the sensors are checked is hard coded. IE Sensor A will always report before sensor B for example. What i would like to do is to be able to configure the sensors in any order that the users wishes.
Code: Select all
Sub Timer_sensors()
If SensorA_Alarm_Timer_speak And SensorA_Sensor Then
Speak_data(17,SensorA.byte0,SensorA.byte1)
End If
If SensorB_Alarm_Timer_speak And SensorB_Sensor Then
Speak_data(17,SensorB.byte0,SensorB.byte1)
End If
If SensorC_Alarm_Timer_speak And SensorC_Sensor Then
Speak_data(17,SensorC.byte0,SensorC.byte1)
End If
If SensorD_Alarm_Timer_speak And SensorD_Sensor Then
Speak_data(17,SensorD.byte0,SensorD.byte1)
End If
If SensorE_Alarm_Timer_speak And SensorE_Sensor Then
Speak_data(17,SensorE.byte0,SensorE.byte1)
End If
End Sub
The issue with this is that the Subroutine must now be called 5 times (instead of just once) in order to ensure each sensor is covered and there is not enough time to complete this task before it needs to be back into another control loop. It is exacerbated by the fact that there is actually 11 sensors to monitor not just 5 in this example.
Code: Select all
SensorA_priority=5
SensorB_priority=2
SensorC_priority=1
SensorD_priority=3
SensorE_priority=4
Sub Timer_sensors( Priority as byte )
If SensorA_Alarm_Timer_speak And SensorA_Sensor and SensorA_priority=Priority Then
Speak_data(17,SensorA.byte0,SensorA.byte1)
End If
If SensorB_Alarm_Timer_speak And SensorB_Sensor and SensorB_priority=Priority Then
Speak_data(17,SensorB.byte0,SensorB.byte1)
End If
If SensorC_Alarm_Timer_speak And SensorC_Sensor and SensorB_priority=Priority Then
Speak_data(17,SensorC.byte0,SensorC.byte1)
End If
If SensorD_Alarm_Timer_speak And SensorD_Sensor and SensorB_priority=Priority Then
Speak_data(17,SensorD.byte0,SensorD.byte1)
End If
If SensorE_Alarm_Timer_speak And SensorE_Sensor and SensorB_priority=Priority Then
Speak_data(17,SensorE.byte0,SensorE.byte1)
End If
End Sub
Code: Select all
Sub A_sensor( )
If SensorA_Alarm_Timer_speak And SensorA_Sensor and SensorA_priority=Priority Then
Speak_data(17,SensorA.byte0,SensorA.byte1)
End If
end sub
Sub B_sensor( )
If SensorB_Alarm_Timer_speak And SensorB_Sensor and SensorB_priority=Priority Then
Speak_data(17,SensorB.byte0,SensorB.byte1)
End If
end sub
Sub C_sensor( )
If SensorC_Alarm_Timer_speak And SensorC_Sensor and SensorB_priority=Priority Then
Speak_data(17,SensorC.byte0,SensorC.byte1)
End If
end sub
etc etc..
Structure Address_type
Address as word
Priority as byte
end structure
Dim Sub_Address(3) as Address_type
Dim Temp_address as word
Sub_address.address(0) = Addressof (A_sensor)
Sub_address.Priority(0)=3
Sub_address.address(1) = Addressof (B_sensor)
Sub_address.Priority(1)=1
Sub_address.address(2) = Addressof (C_sensor)
Sub_address.Priority(2)=2
//Here call subroutine that sorts the structured array by Priority.
For Loop = 0 to 2
Temp_address=Sub_address.address(Loop)
asm
call Temp_address
end asm
next
Will the ASM call cause issues with context saving for example?
IS the a better way to do it?
Cheers
Lee