At first I´m a newbie to swordfish, pics and electronics. Totally newbie.
Trying to make a code to read some sensors, engine RPM (max to 6500), display then on a LCD, do some calculations and finally pulse a injector when engine needs extra fuel.
Searching forum I made some initial code, but totally lost when I try to count RPM from engine. Unfortunately, Swordfish doesn´t have Count command (like Proton Pic Basic).
Anyone can check my code and give-me some directions.
Thanks.
Code: Select all
Device = 18F452
Clock = 20
#option LCD_DATA = PORTB.0
#option LCD_RS = PORTB.4
#option LCD_EN = PORTB.5
Include "LCD.bas"
Include "ADC.bas"
Include "Convert.bas"
Include "ISRTimer.bas"
Dim LED As PORTD.0
Dim LED1 As PORTD.1
Const Timer1 = 0
Function GetCount() as Word
Dim PulseCount as word
toggle (LED1)
PulseCount.Byte1 = TMR0H 'get high byte first
PulseCount.Byte0 = TMR0L 'get low byte next
WriteAt (3,1, " ")
WriteAt (3,1, Pulsecount)
TMR0H = 0 'clear high byte
TMR0L = 0 'clear low byte
End Function
T0CON.7 = 0 'stop Timer0
T0CON.6 = 1 '1 16 bit mode
'0 8 bit mode
T0CON.5 = 1 'put Timer0 in counter mode
T0CON.4 = 0 ' 1 incrementa on falling edge (high to low)
' 0 incrementa on rising edge (low to high)
T0CON.3 = 1 'no prescaler
TMR0H = 0 'clear high byte of the count register
TMR0L = 0 'clear low byte of the count register
T0CON.7 = 1 'start timer
' main
Timer.initialize(1)
Timer.Items (Timer1).Interval = 100
Timer.items (Timer1).OnTimer = @GetCount
Timer.Items (Timer1).Enabled = True
Timer.Start
Output (LED)
Output (LED1)
Repeat
Toggle (LED)
Until false
End