$regfile = "m16def.dat"
$crystal = 12000000
$baud = 9600 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40
'==============================
' LCD inisialisation
' mode 4 bit
' Pin R/W ground just for write
'==============================
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.1 , Rs = Portb.0
Config Lcd = 20 * 2
Cls
Cursor Off Noblink
'====================================
'Eksternal Interrupt 0 inisialisation
'For Detect Zero Crossing Signal
'====================================
On Int0 Start_timer0
Config Int0 = Falling
Dim Status As Bit
Dim Displaystatus As Bit
'====================================================================
' Timer 1 Inisialisation for Countdown Zero Crossing
' IT MEANS 1024/12000000(CRSYTAL) = 0.08ms
' so timer 1 will overflow every (0.08ms * 65535 = 5242.8 ms = 5.2s)
'=====================================================================
Config Timer1 = Timer , Prescale = 1024
Dim Nilaitimer1 As Integer
Dim Waktu As Single
Dim Z As String * 5
Config Porta.7 = Output
Triac Alias Porta.7
Config Portd.2 = Input
Ddrd.2 = 0
'==========================
' Main Program
'==========================
Main:
Locate 1 , 1
Lcd "Program Zero Cross"
Locate 2 , 1
Lcd "By Deny Bodat'z"
Reset Status
Enable Timer1
Enable Int0
Enable Interrupts
Cls
Do
While Displaystatus = 0
Wend
Displaystatus = 0
Waktu = Nilaitimer1 * 0.08
Locate 1 , 1
Lcd "Timer1: " ; Nilaitimer1
Locate 2 , 1
Z = Str(waktu)
Z = Fusing(waktu , "#.##")
Lcd "Time: " ; Z ; " ms"
Loop
'=============================
' External Interrupt 0 Vektor
'=============================
Start_timer0:
If Status = 0 Then
Timer1 = 0
Start Timer1
While Pind.2 = 0
Wend
Waitms 25
Set Triac
Waitms 40
Reset Triac
Set Status
Else
Stop Timer1
While Pind.2 = 0
Wend
Waitms 25
Set Triac
Waitms 40
Reset Triac
Reset Status
Nilaitimer1 = Timer1
Displaystatus = 1
End If
Return
End