since the last update I have encountered 2 problems, one relating to the timer and the other in a module that I use for a button verification.
I have attached 2 zip with assembly and full list generated with latest and previous version.
Problem 1
On PORTA.1 I have a led with two different periods of on and off and will never come on.
If I put a single TOGGLE (PORTA.1) in OnTimer SUB it works, if I add the counters and check on status directly not working and never lights up.
Problem 2
On PORTB.4 have a pullup resistor and a button to gnd if test in main loop the state of PORTB.4 directly usart report "Pressed" when use the module "Button.BAS" nothing happens.
I reproduced both of these problems in the program and a module below:
Code: Select all
Device = 18F4685
Clock = 40
Include "Config_V3_NOWDT.bas"
Include "ISRTimer.bas"
#option BTN1_PIN = PORTB.4
Include "button"
Include "usart"
Dim HLTH_PIN As PORTA.1
Dim HealthOn As Integer // led on cycles
Dim HealthOff As Integer // led off cycles
Const Timer1 = 0 // flashing timer
{
****************************************************************************
* Name : OnTimer (PRIVATE) *
****************************************************************************
}
Private Sub OnTimer()
If HLTH_PIN = 0 Then
If HealthOff > 200 Then
High(HLTH_PIN)
HealthOff = 0
HealthOn = 0
Else
Inc(HealthOff)
End If
Else
If HealthOn > 10 Then
Low(HLTH_PIN)
HealthOff = 0
HealthOn = 0
Else
Inc(HealthOn)
End If
End If
End Sub
{
****************************************************************************
* Name : Initialize (PRIVATE) *
****************************************************************************
}
Private Sub Initialize()
Output(HLTH_PIN) // Health Led
HealthOff = 0
HealthOn = 0
Timer.Initialize(1)
Timer.Items(Timer1).Interval = 10 // 10ms
Timer.Items(Timer1).OnTimer = @OnTimer // timer event handler
Timer.Items(Timer1).Enabled = true
Timer.Start
USART.SetBaudrate(br115200)
DelayMS(1000)
End Sub
Initialize()
Stato = False
While 1 = 1
If IsP1Pressed() Then
USART.Write("Pressed",13,10)
End If
' if PORTB.4 = 0 then
' usart.write("Pressed",13,10)
' end if
Wend
Code: Select all
Module Button
#if IsOption(BTN1_PIN) And Not IsValidPortPin(BTN1_PIN)
#error BTN1_PIN, "Invalid option. BTN1_PIN must be a valid port pin."
#endif
#option BTN1_PIN = PORTB.4
#if isoption(COMMON_PRESS_CYCLES)
Const cCommonCycle As Integer = COMMON_PRESS_CYCLES
#else
Const cCommonCycle As Integer = 100
#endif
Dim
bBTN1_PIN As BTN1_PIN.BTN1_PIN@
Private Dim lastP1 As Boolean
Private Dim testP1 As Integer
{
****************************************************************************
* Name : IsP1Pressed (PUBLIC) *
****************************************************************************
}
Public Function IsP1Pressed() As Boolean
result = false
If testP1 > cCommonCycle Then
If bBTN1_PIN = 0 Then
If lastP1 = false Then
lastP1 = true
result = true
End If
Else
lastP1 = false
End If
testP1 = 0
Else
Inc(testP1)
End If
End Function
{
****************************************************************************
* Name : Initialize (PRIVATE) *
* Purpose : *
****************************************************************************
}
Private Sub Initialize()
Input(bBTN1_PIN)
lastP1 = false
testP1 = 0
End Sub
Initialize()
Code: Select all
Module Config_V3_NOWDT
#if _Device in (18F4685,18F2682)
Config
OSC = HSPLL,
PWRT = On,
WDT = off,
WDTPS = 32768,
MCLRE = off,
LVP = OFF,
PBADEN = OFF,
STVREN = off,
#if isoption(PROTECT) And PROTECT = true
CP0 = On,
CP1 = On,
CP2 = On,
CP3 = On,
CP4 = On,
#if _device = 18F4685
CP5 = On,
#endif
EBTR0 = On,
EBTR1 = On,
EBTR2 = On,
EBTR3 = On,
EBTR4 = On,
#if _device = 18F4685
EBTR5 = On,
#endif
CPD = On,
CPB = On,
#else
CP0 = off,
#endif
BOREN = off
#else
#error "Invalid device for HSPLL."
#endif
Include "SetDigitalIO.bas"
SetAllDigital()