SOLVED
16F1936 at 32MHz:
1) Elapsed_INT.bas, used Preload from 16 MHz,
Code:
If OSC == 32
TimerConst = 063C7h
EndIF
2) Set TMR1CS to Fosc/4
3) Set T1CKPS to 1:2 Prescaler
It runs at same speed as timer on my cell phone.
Compete code:
Code:
@ ERRORLEVEL -301 ; turn off ADC clock ignored message
@ ERRORLEVEL -306 ; turn off crossing page boundary message
#CONFIG
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LVP_OFF
#ENDCONFIG
DEFINE OSC 32
SPLLEN CON %1 ' PLL enable
IRCF CON %1110 ' to enable 8 MHz
SCS CON %00 ' system clock determined by FOSC
OSCCON = (SPLLEN << 7) | (IRCF << 3) | SCS
INCLUDE "DT_INTS-14.bas"
INCLUDE "ReEnterPBP.bas"
Include "Elapsed_INT.bas"
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON = %00010101 ; Prescaler=1:1, TMR3ON.
' bit 7-6 TMR1CS<1:0>: Timer1 Clock Source Select bits
' 00 =Timer1 clock source is instruction clock (FOSC/4)
' bit 5-4 T1CKPS<1:0>: Timer1 Input Clock Prescale Select bits
' 01 = 1:2 Prescale value
' bit 3 T1OSCEN: LP Oscillator Enable Control bit
' 0 = Dedicated Timer1 oscillator circuit disabled
' bit 2 T1SYNC: Timer1 External Clock Input Synchronization Control bit
' 1 = Do not synchronize external clock input
' Unimplemented: Read as ‘0’
' bit 0 TMR1ON: Timer1 On bit
' 1 = Enables Timer1
DEFINE LCD_DREG PORTB ' Set LCD data port
DEFINE LCD_DBIT 0 ' Set starting data bit
DEFINE LCD_RSREG PORTC ' Set LCD register select port
DEFINE LCD_RSBIT 5 ' Set LCD register select bit
DEFINE LCD_EREG PORTC ' Set LCD enable port
DEFINE LCD_EBIT 4 ' Set LCD enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size
DEFINE LCD_LINES 4 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 1000 ' Set command delay time in microseconds
DEFINE LCD_DATAUS 50 ' Set data delay time in microseconds
define CCP4_REG PORTC ' PWM Pulse out to LCD contrast
DEFINE CCP4_BIT 1 ' 2N2907 PNP with 1K on base
define CCP5_REG PORTC ' PWM Pulse out to LCD backlight
DEFINE CCP5_BIT 2 ' 2N2222A NPN with 1K on base
ANSELA = %00000000
ANSELB = %00000000
TRISA = %00000111
TRISB = %00110000
TRISC = %10000000
TRISE = %00000000
HPWM 2,100,1953
HPWM 1,180,1953
@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
Gosub ResetTime ' Reset Time to 0d-00:00:00.00
Pause 500 ' Let PIC and LCD stabilize
LCDOUT $FE, 1 : Pauseus 1
GOSUB StartTimer ' Start the Elapsed Timer
Mainloop:
IF SecondsChanged = 1 THEN
SecondsChanged = 0
LCDOUT $FE,2, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
ENDIF
goto mainloop
end
Bookmarks