Hi,
Doe anyone have a tick module for Firewing16?
I find it very useful and want to use on the 16 series device.
Thanks
Tim
module Tick
private const _fosc as single = _clock * 1000000 / 2 // instructions per second
private const _ms as single = _fosc / 1000 // instructions every 1 ms
public ms as uinteger = 0 // increment every millisecond
// interrupt will increment tick every millisecond...
private Interrupt OnTimer(Pic.T2Interrupt)
ms += 1 ' increment tick
IFS0.7 = 0 ' clear interrupt flag
End Interrupt
// init module...
sub main()
enable(OnTimer)
T2CON = 0 ' clear Timer 1 - no presccale
PR2 = _ms ' set timer period
IFS0.7 = 0 ' clear timer interrupt flag
T2CON.15 = 1 ' start timer
end sub
End module
// timeout variable...
private _timeoutValue as uinteger = 0
private _lastTime as uinteger = 0
'****************************************************************************
'* Name : SetKeepAliveTimeout *
'* Purpose : Set keepalive timeout value *
'****************************************************************************
private sub SetKeepAliveTimeout(value as uinteger)
_timeoutValue = value
_lastTime = tick.ms
end sub
'****************************************************************************
'* Name : KeepAliveTimeout *
'* Purpose : Check to see if keepalive timeout ocurred *
'****************************************************************************
private function KeepAliveTimeout() as boolean
return (tick.ms - _lastTime) >= _timeoutValue
end function
If KeepAliveTimeout() Then
// do something
SetKeepAliveTimeout((mKeepAliveSeconds * 1000))
End If
SetKeepAliveTimeout(mKeepAliveSeconds * 1000)
module Tick
private const _osc = _clock // alias for Code Explorer
private const _fosc as uinteger = _osc * 1000000 / 2 // instructions per second
private const _ms as ushort = _fosc / 1000 // instructions every 1 ms
private _ticks as uinteger = 0 // increment every millisecond
// interrupt will increment tick every millisecond...
private Interrupt OnTimer(Pic.T2Interrupt)
_ticks += 1 ' increment tick
IFS0.7 = 0 ' clear interrupt flag
End Interrupt
public function Time() as uinteger
disable(OnTimer)
Time = _ticks
enable(OnTimer)
end function
// alias for code compatability with existing MQTT module
public dim ms as Time
// init module...
sub main()
T2CON = 0 ' clear Timer 1 - no presccale
PR2 = _ms ' set timer period
IFS0.7 = 0 ' clear timer interrupt flag
T2CON.15 = 1 ' start timer
enable(OnTimer)
end sub
End module
Users browsing this forum: No registered users and 3 guests