Sourcecode
Download
Sourcecode
Sourcecode

'-----------------------------------------------------------------------------------------

'-----------------------------------------------------------------------------------------

'Titel                    : TürklingelUhr Softclock
'Name                     : *.bas
'Autor                    : Arno Schweißinger
'Datum                    : 26.03.2007
'MicroContorller          : AtMega32 4MHz
'Hardware                 : Display HD 44780-kompatibel,
'                           Quarz 32768Hz an Pin TOSC1/2
'                           mit RC5-IR Zeitstellen
'Stromversorgung:         : 5V für Logik,
'In Planung               :
'-----------------------------------------------------------------------------------------

$regfile = "m16def.dat"

'$crystal = 4000000
'$crystal = 3686400
'$baud = 9600
$crystal = 3579545
$lib "mcsbyte.lbx"                                          'use byte library for smaller code

Declare Sub Zeitstellen
Declare Sub Getziffer
Declare Sub Tuerruf

Config Lcd = 40 * 4
Config Lcdpin = Pin , Db4 = Porta.0 , Db5 = Porta.1 , Db6 = Porta.2 , Db7 = Porta.3 , E = Porta.5 , Rs = Porta.4
Config Pinb.1 = Input                                       ' Klingel gedrückt
Config Rc5 = Pinb.0                                         ' IR Fernbedienung
Config Date = Dmy , Separator = .                           ' ANSI-Format
Config Clock = Soft                                         ' this is how simple it is

Enable Interrupts

Const C_tuer = "Tuer "
Const C_zeit = "Zeit "

Dim Temp As Byte
Dim I As Byte
Dim Address As Byte , Command As Byte                       'reserve space for variables
Dim S As String * 1
Dim Datum As String * 8
Dim Zeit As String * 8
Dim Togglebit As Bit
Dim Togglealt As Bit

Date$ = "28.03.07"
'Time$ = "12:34:56"
Togglebit = 1

'-------------------------
'      Hauptprogramm
'-------------------------
'Begin
 Cursor Off
 Cls
 Lcd "Version " ; Date$
 Waitms 200
 Gosub Zeitstellen
 Do
   Home                                                    'cursor home
   Lcd C_zeit ; Date$ ; "  " ; Time$                       'show the date and time
   Waitms 200
   If Pinb.1 = 1 Then Tuerruf
 Loop
End                                                         ' ende Hauptprogramm
'-------------------------

Sub Tuerruf
 Locate 2 , 1
 Lcd C_tuer ; Date$ ; "  " ; Time$
 Home
 Lcd "    Türruf          "
 Wait 5
End Sub


Sub Zeitstellen
Datum = ""
Home
Lcd "Datum eingeben: TT MM JJ"
Locate 2 , 1
For I = 1 To 6
  Togglealt = Togglebit
  While Togglealt = Togglebit
    Gosub Getziffer
  Wend
  Datum = Datum + S
  If I = 2 Then Datum = Datum + "."
  If I = 4 Then Datum = Datum + "."
  Locate 1 , 17
  Lcd Datum
Next I
Date$ = Datum
Cls
Lcd "Datum: " ; Date$
Waitms 300

Zeit = ""
Cls
Lcd "Zeit eingeben: SS MM"
Locate 2 , 1
For I = 1 To 4
  Togglealt = Togglebit
  While Togglealt = Togglebit
    Gosub Getziffer
  Wend
  Zeit = Zeit + S
  If I = 2 Then Zeit = Zeit + ":"
  Locate 1 , 16
  Lcd Zeit
Next I
Zeit = Zeit + ":00"
Time$ = Zeit
Cls
Lcd "Zeit: " ; Time$
Waitms 300
End Sub

Sub Getziffer
Do
 Getrc5(address , Command)
 If Address <> 255 Then
   If Command > 127 Then                                   ' bx0000000 (Bit 7)
     Togglebit = 1                                         ' Togglebit merken
    Else
     Togglebit = 0
   End If
   Command = Command And &B00111111                        ' clear the toggle bit
   S = Lookupstr(command , Asciidaten )
 End If

 Temp = Asc(s)
 If Temp > &H2F Then
   If Temp < &H3A Then Exit Do
 End If
Loop
End Sub

Asciidaten:
Data "1" , "2" , "9" , "4" , "0" , "p" , "<" , "5" , "8" , "o"
Data "v" , "r" , "L" , "b" , "ä" , "k" , "7" , "ü" , "l" , "S"
Data "E" , "y" , "#" , "j" , "4" , "i" , "3" , "u" , "m" , "x"
Data "O" , "f" , "6" , "2" , "z" , "n" , "L" , "1" , "d" , "g"
Data "5" , "t" , "q" , "w" , "e" , "3" , "s" , "a" , "?" , " "
Data "?" , "h" , "R" , "c" , "U" , "ö" , "?" , "?" , "?" , "?"
Data "?" , "?" , "?" , "R"
Data "" , "" , "" , "" , "" , "" , "" , "" , "" , ""