Device = 18F1220
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF
Include "IntOSC8.bas"
Include "LCD.bas"
Include "utils.bas"
Include "Convert.bas"
// some LCD options...
#option LCD_DATA = PORTB.4
#option LCD_RS = PORTB.2
#option LCD_EN = PORTB.3
Dim button As PORTA.0
Dim timer0_ON As T0CON.7
Dim timer0_OFF As T0CON.7
Dim TMR0 As TMR0L
//////////// sets up the timer0
Sub set_timer ()
T0CON.7 = 1 //sets timer0 on
T0CON.6 = 0 //sets to 16 bit timer
T0CON.5 = 1 //sets transition on T0CKI pin
T0CON.4 = 1 //sets hight to low transtion
T0CON.3 = 0 // turns on prescaler
T0CON.2 = 1
T0CON.1 = 1 //sets prescaler to 1:256
T0CON.0 = 1
TMR0 = 0
INTCON.5 = 1
End Sub
//////////////////////////////////////
Sub Get_fq()
Dim Acc_byte0 As Byte 'You can't use a . here so I change theat to underscore
Dim Acc_byte1 As Byte
Dim Acc_byte2 As Byte
Dim value As LongWord
//
// Timer0 frequency counter example, Mike McLaren, K8LH
//
TMR0H = 0 // clear Timer0 registers
TMR0L = 0 //
Input(PORTA.4) // gate Timer0 counter "on"
DelayMS(10) //
Output(PORTA.4) // gate Timer0 counter "off"
Acc_byte0 = 0 // count bits 00..07 (prescaler)
Acc_byte1 = TMR0L // count bits 08..15
Acc_byte2 = TMR0H // count bits 16..23
//
// toggle timer0 "source edge select" bit to 'bump' the prescaler
// until it overflows into the TMR0L register
//
While (TMR0L = Acc_byte1)
T0CON.4 = 1 // toggle T0SE "source edge select" bit
T0CON.4 = 0 //
Dec(Acc_byte1) //
//
While true (TMR0L = Acc_byte1)
value = Acc_byte1
LCD.MoveCursor (1,1)
LCD.Write(BinToStr (value))
Wend
Wend
End Sub
//////////////////////////////////////
ADCON1=$70 //sets portb Digital
timer0_ON = 1 // turns timer0 on
timer0_OFF = 0 // turns timer0 off
SetAllDigital
While true
//set_timer
Repeat
If button = 1 Then
EndIf
WriteAt(1,1,"Frequency Counter")
DelayMS(500)
Until button = 0
Cls
Get_fq // just for testing
Wend