' * - - * - * * - - - - - - - - - - - - - - - - - - - - - - - - - - - 
'Made by Szymon Dyja
'from www.pro-qwerty.com
'' * - - * - * * - - - - - - - - - - - - - - - - - - - - - - - - - - 

$crystal = 8000000
$baud = 19200

Declare Sub Lover_text()

Config Pind.2 = Input
Config Pind.3 = Input
Config Pind.4 = Input
Config Pind.6 = Output
Portd.2 = 1
Portd.3 = 1
Portd.4 = 1
Portd.6 = 0

Dim A As Integer
Dim Secounds As Byte
Dim Minutes As Byte
Dim Hours As Byte
Let Secounds = 0
Let Minutes = 0
Let Hours = 0
Let A = 0

Config Lcd = 16 * 2
Deflcdchar 0 , 32 , 21 , 14 , 4 , 4 , 10 , 17 , 17          ' replace ? with number (0-7)
Deflcdchar 1 , 32 , 4 , 14 , 14 , 14 , 4 , 4 , 4            ' replace ? with number (0-7)

Config Timer1 = Timer , Prescale = 1024
On Ovf1 Tim1_isr
Load Timer1 , 7812

Setclock:
Disable Interrupts
Let Secounds = 0
Cls

Cursor On Blink

Lcd "Time: "
Lowerline
Lcd "Set Clock!"
Locate 1 , 9
Lcd ":"
Locate 1 , 12
Lcd "."


Do
  If Pind.3 = 0 Then
      Minutes = Minutes + 1
      If Minutes = 60 Then Minutes = 0
      Waitms 200
   End If
   If Pind.2 = 0 Then
      Hours = Hours + 1
      If Hours = 24 Then Hours = 0
      Waitms 200
   End If
   If Pind.4 = 0 Then Exit Do
   Locate 1 , 7
   Lcd "  "
   Locate 1 , 7
   Lcd Hours
   Locate 1 , 10
   Lcd "  "
   Locate 1 , 10
   Lcd Minutes
   Locate 1 , 13
   Lcd "  "
   Locate 1 , 13
   Lcd Secounds
   Waitms 50
Loop


Enable Timer1
Enable Interrupts

Cursor Off Noblink

Call Lover_text()

Do
  Toggle Portd.6
  Waitms 100
  If Pind.4 = 0 Then
      Waitms 10
      While Pind.4 = 0
         Nop
      Wend
      Goto Setclock
  End If
Loop

Tim1_isr:
   Load Timer1 , 7812

   If Secounds = 60 Then
      Secounds = 0
      Minutes = Minutes + 1
      If Minutes = 60 Then
         Minutes = 0
         Locate 1 , 10
         Lcd "  "
         Hours = Hours + 1
         If Hours = 24 Then
            Hours = 0
            Locate 1 , 7
            Lcd "  "
            Call Lover_text()
            nop
            nop
         End If
      End If
   End If

   Locate 1 , 7
   Lcd Hours
   Locate 1 , 10
   Lcd Minutes
   Locate 1 , 13
   Lcd "  "
   Locate 1 , 13
   Lcd Secounds

   Locate 1 , 16
   If A = 0 Then
      Lcd Chr(0)
      A = 1
   Elseif A = 1 Then
      Lcd Chr(1)
      A = 0
   End If
   Secounds = Secounds + 1
Return

End


Sub Lover_text()
   Locate 2 , 0
   Lcd "   Hello! "
End Sub