Here is a start (not tested!). But it should get you going in the right direction. I only included the acceleration stuff to keep the logic simpler.
You will need the include files (Get Darrel's from http://darreltaylor.com/DT_INTS-18/downloads.html), and make sure the file names match.
Code:
' PIC18F4431 initializationDEFINE OSC 40
DEFINE LCD_DREG PORTD
DEFINE LCD_EREG PORTB
DEFINE LCD_RSREG PORTB
DEFINE LCD_EBIT 6
DEFINE LCD_RSBIT 7
tacc var BYTE
tdec var BYTE
cacc var word
cdec var word
ref var word
fmin var word
freq var WORD
cacc_div VAR BYTE
cdec_div VAR BYTE
tacc=1
tdec=10
fmin=10
ref=1200
PAUSE 4000
LCDOUT $fe,$1
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
INCLUDE "TimerControl.pbp" ; Timer Control Routines
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _UpdateTickCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
GOSUB ResetTime ' Reset Timer and mSec_Ticks = 0
IF tacc > 65 THEN
cacc_div = 10
ELSE
cacc_div = 1
ENDIF
cacc = ((1000/cacc_div) * tacc) / (ref - fmin)
GOSUB StartTimer ' Start Counting mSec_Ticks
Main:
IF mSec_Ticks > (cacc * cacc_div) THEN
IF freq < ref THEN freq = freq + 1
mSec_Ticks = mSec_Ticks - (cacc * cacc_div)
IF freq >= ref THEN
GOSUB StopTimer
GOSUB ResetTime
ENDIF
LCDOUT $fe,$2,DEC5 freq
IF PORTC.0=%1 THEN ref=500
GOTO Main
I may not be much use the next couple of days, but the building blocks are here (hopefully without too many errors/typos)
Bookmarks