regfile = "2313def.DAT"
$crystal = 11059200
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portb.5 , Db5 = Portb.4 , Db6 = Portb.3 , Db7 = Portb.2 , E = Portb.6 , Rs = Portb.7
'Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.1 , Db6 = Portb.0 , Db7 = Portd.6 , E = Portb.3 , Rs = Portb.4
Cursor Off
Config Pind.6 = 1
Config Pind.0 = 0
Portd.0 = 1
Portd.6 = 1
Dim Czestotliwosc As Long
Const Licznik = 22333 '22336
Config Timer1 = Timer , Prescale = 256
Config Timer0 = Counter , Edge = Falling
Deflcdchar 1 , 2 , 4 , 14 , 16 , 16 , 17 , 14 , 32 ' replace ? with number (0-7)
Deflcdchar 0 , 2 , 4 , 14 , 16 , 14 , 1 , 30 , 32
Deflcdchar 2 , 32 , 32 , 14 , 17 , 31 , 16 , 14 , 4 ' replace ? with number (0-7)
On Timer1 Czas
On Timer0 Zlicz
Kasuj Alias Portd.6
Mnoznik Alias Pind.0
Cls
Lcd " MIERNIK"
Lowerline
Lcd " CZESTOTLIWOSCI"
Wait 1
Cls
Enable Interrupts
Enable Timer1
Enable Timer0 'Pomiar czasu
Counter1 = Licznik
Do
Set Kasuj
Loop
End
Czas:
Stop Timer0
Stop Timer1
Czestotliwosc = Czestotliwosc * 256
Czestotliwosc = Czestotliwosc + Counter0
If Mnoznik = 0 Then
Czestotliwosc = Czestotliwosc * 4
Else
Czestotliwosc = Czestotliwosc * 40
End If
Locate 1 , 2 : Lcd "Cz" ; Chr(2) ; "stotliwo" ; Chr(0) ; Chr(1)
If Czestotliwosc < 1000 Then Gosub Wyswietl_hz
If Czestotliwosc >= 1000 And Czestotliwosc < 1000000 Then Gosub Wyswietl_khz
If Czestotliwosc >= 1000000 Then Gosub Wyswietl_mhz
Reset Kasuj : Waitms 2 : Set Kasuj 'Kasuj przerzutniki
Czestotliwosc = 0
Counter0 = 0
Counter1 = Licznik
Start Timer0
Start Timer1
Return
Zlicz:
Incr Czestotliwosc
Return
Wyswietl_hz:
Locate 2 , 2
Lcd " " ; Czestotliwosc ; " "
Locate 2 , 9 : Lcd " Hz "
Return
Wyswietl_khz:
Locate 2 , 3
Lcd " " ; Czestotliwosc ; " "
Czestotliwosc = Czestotliwosc \ 1000
Locate 2 , 2
Lcd " " ; Czestotliwosc ; "."
Locate 2 , 11 : Lcd " kHz "
Return
Wyswietl_mhz:
Locate 2 , 3
Lcd Czestotliwosc ; " "
Czestotliwosc = Czestotliwosc \ 1000000
Locate 2 , 2
Lcd Czestotliwosc ; "."
Locate 2 , 11 : Lcd " MHz "
Return