DogFlu66
Member
It is a version of the arduino function "MILLIS", it is a general counter that increments every mSec. and that it takes several weeks to restart.
You can download the "_FuncionesPic16F88.bas" functions from this other thread:
Note: updated code improved (3/2023)
You can download the "_FuncionesPic16F88.bas" functions from this other thread:
Note: updated code improved (3/2023)
Code:
'***********************************************************************
'MILLIS function, long type geneal counter.
'For replacing absolute pauses generated with WaitMs.
'The _MILLIS function increments every mSec. so it takes
'approximately 49.7 days To reinitialize.
'That is, it will pass through a zero value.
'************************************************************************
'Pic16F88, OshonSoft Pic Basic Compiler v.8.42
'By COS, 03/2023
'************************************************************************
#define CONFIG = 0x2f50 'Fuse definition.
#define CONFIG2 = 0x3ffc
Define CLOCK_FREQUENCY = 8 'Clock a 8Mhz
'Define SIMULATION_WAITMS_VALUE = 1'Waitms is used activate for simulation.
Include "_FuncionesPic16F88.bas"
'************************************************************************
main:
'Pin configuration
AllDigital
ConfigPin PORTA = Output
ConfigPin PORTB = Output
'Clock internal 8Mhz.
Call _setup_oscillator_mode_select_bit(_oscillator_mode_defined_by_fosc)
Call _setup_oscillator(_osc_8mhz)
'Initialize Timer1 desborde 1mSec.
Call _setup_timer1(_tmr1_internal, _tmr1_div1)
Call _set_timer1(0xf831) 'Interruption every 1mSec.
Call _timer1(_on)
Call _enable_interrupts(_int_timer1)
'Call _enable_interrupts(_global)
'Assign names to the Leds
Symbol LedGreen = RB0
Symbol LedYellow = RA7
'********************************************************************
Call _SetUp_MILLIS() 'Setup _MILLIS functions, before activate interrupts
Call _enable_interrupts(_global)
Dim PreMillis As Long
Dim PreMillis1 As Long
'Loop
While True
Call _MILLIS() 'Repeat As few times As possible, so As Not To interfere with interruptions.
If (_MILLIS - PreMillis) >= 200 Then 'Wait time in mSec.
PreMillis = _MILLIS 'The last value of _MILLIS is stored.
Toggle LedYellow 'Invers the state of the led.
Endif
If (_MILLIS - PreMillis1) >= 400 Then 'Wait time in mSec.
PreMillis1 = _MILLIS 'The last value of _MILLIS is stored.
Toggle LedGreen 'Invers the state of the led.
Endif
Wend
End
'********************************************************************
'Function _MILLIS
'Requires the use of a timer and interrupts.
'**************************************************
'Call _SetUp_MILLIS() 'Before triggering interrupts
'Call _MILLIS() 'Update _MILLIS counter
'Call _CounterMillis() 'Incrementa contador Millis
'**************************************************
'Inicialize functions
Proc _SetUp_MILLIS()
_MILLIS = 0
_CounterMillis = 0
End Proc
'Return _MILLIS as Long and global variable
Function _MILLIS() As Long
Disable 'Stop interruption
_MILLIS = _CounterMillis
Enable 'Enable interruption
End Function
'Increment the counter Millis
'Return _CounterMillis as Long and global variable
Function _CounterMillis() As Long
_CounterMillis++ 'Increment counter millis
End Function
'********************************************************************
'Interrupt vector
On Interrupt 'Disable interruptions
Save System
If _tmr1if Then
Call _set_timer1(0xf831) 'Reload TMR1 registers to count 1mSec and clear _tmr1if.
Call _CounterMillis() 'Increments _CounterMILLIS every mSec.
Endif
Resume 'Enable interruptions
Last edited: