PIC 18F47J53 DelayMS decimal places
Posted: Sun Feb 14, 2016 1:13 pm
Hi everyone,
Can anyone help with this problem i am having.
I need a LED to blink at the Frequency of 7.9hz which is 63.29114 on and 63.29114 off at the moment i can not place the decimal point in the code below. How can this be achieved?
any help would be greatly appreciated
Charlie
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 12/02/2016 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
{
*****************************************************************************
* Name : StrobeTest-04.BAS *
* Date : 08/01/2014 *
* *
*****************************************************************************
}
Device = 18F47J53
Clock = 48
Dim mS As Word,
TMR1IE As PIE1.0, 'TMR1 Interrupt Enable
TMR1IF As PIR1.0, 'TMR1 Interrupt Flag
TMR1ON As T1CON.0, 'TMR1 Count Enable
Timer1 As TMR1L.AsWord, 'A quick way of creating a Word Alias
Trpt As Word,
Trpt2 As Word,
LED0 As PORTB.0,
LED1 As PORTB.1,
LED2 As PORTB.2,
LED3 As PORTB.3,
LED4 As PORTB.4,
LED5 As PORTB.5,
LED6 As PORTD.0
Const
TMR1StartVal = 15536, 'User defined TMR1 starting value
TMR1ReloadVal = TMR1StartVal + 0
Interrupt TMR1_Interrupt()
Save(0) 'Back up system variables
If TMR1IF = 1 Then
TMR1ON = 0 'Disable TMR1
Timer1 = TMR1ReloadVal 'Reload a new start value (includes non-counted cycles while disabled)
TMR1ON = 1 'Enable TMR1
TMR1IF = 0 'Clear the TMR1 Interrupt
Inc(mS, 1) 'Increment mS by 1
EndIf
Restore 'Restore system variables
End Interrupt
'Start Of Main Program...
mS = 0 'Clear the mS counter
Trpt = 0
Trpt2 = 0
High(LED0)
High(LED1)
High(LED2)
High(LED3)
High(LED4)
High(LED5)
High(LED6)
DelayMS(150)
Low(LED0)
Low(LED1)
Low(LED2)
Low(LED3)
Low(LED4)
Low(LED5)
Low(LED6)
DelayMS(150)
While Trpt2 < 1
While Trpt < 34
PORTD = %111111
PORTB = %111111
DelayMS(63)
PORTD = %0000000
PORTB = %0000000
DelayMS(63)
Inc(Trpt)
Wend
Trpt = 0
DelayMS(50)
While Trpt < 3
PORTB = %111111
PORTD = %000001
DelayMS(9000)
PORTB = %000000
PORTD = %000000
DelayMS(9000)
Inc(Trpt)
Wend
Trpt = 1
DelayMS(50)
Inc(Trpt2)
Wend
Trpt2 = 1
Can anyone help with this problem i am having.
I need a LED to blink at the Frequency of 7.9hz which is 63.29114 on and 63.29114 off at the moment i can not place the decimal point in the code below. How can this be achieved?
any help would be greatly appreciated
Charlie
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 12/02/2016 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
{
*****************************************************************************
* Name : StrobeTest-04.BAS *
* Date : 08/01/2014 *
* *
*****************************************************************************
}
Device = 18F47J53
Clock = 48
Dim mS As Word,
TMR1IE As PIE1.0, 'TMR1 Interrupt Enable
TMR1IF As PIR1.0, 'TMR1 Interrupt Flag
TMR1ON As T1CON.0, 'TMR1 Count Enable
Timer1 As TMR1L.AsWord, 'A quick way of creating a Word Alias
Trpt As Word,
Trpt2 As Word,
LED0 As PORTB.0,
LED1 As PORTB.1,
LED2 As PORTB.2,
LED3 As PORTB.3,
LED4 As PORTB.4,
LED5 As PORTB.5,
LED6 As PORTD.0
Const
TMR1StartVal = 15536, 'User defined TMR1 starting value
TMR1ReloadVal = TMR1StartVal + 0
Interrupt TMR1_Interrupt()
Save(0) 'Back up system variables
If TMR1IF = 1 Then
TMR1ON = 0 'Disable TMR1
Timer1 = TMR1ReloadVal 'Reload a new start value (includes non-counted cycles while disabled)
TMR1ON = 1 'Enable TMR1
TMR1IF = 0 'Clear the TMR1 Interrupt
Inc(mS, 1) 'Increment mS by 1
EndIf
Restore 'Restore system variables
End Interrupt
'Start Of Main Program...
mS = 0 'Clear the mS counter
Trpt = 0
Trpt2 = 0
High(LED0)
High(LED1)
High(LED2)
High(LED3)
High(LED4)
High(LED5)
High(LED6)
DelayMS(150)
Low(LED0)
Low(LED1)
Low(LED2)
Low(LED3)
Low(LED4)
Low(LED5)
Low(LED6)
DelayMS(150)
While Trpt2 < 1
While Trpt < 34
PORTD = %111111
PORTB = %111111
DelayMS(63)
PORTD = %0000000
PORTB = %0000000
DelayMS(63)
Inc(Trpt)
Wend
Trpt = 0
DelayMS(50)
While Trpt < 3
PORTB = %111111
PORTD = %000001
DelayMS(9000)
PORTB = %000000
PORTD = %000000
DelayMS(9000)
Inc(Trpt)
Wend
Trpt = 1
DelayMS(50)
Inc(Trpt2)
Wend
Trpt2 = 1