HOME

Berlinuhr



'Titel                    : BerlinUhr
'Name                     : BerlinUhr.bas
'Autor                    : Arno Schweißinger
'Datum                    : 18.04.2009
'MicroController          : AtMega16 1MHz interner Takt
'Compiler                 : Bascom
'Hardware                 : Viele LEDs 7 rote und 16 grüne eine gelbe
'                           Quarz 32768Hz an Pin TOSC1/2
'                           3x 74HC374, 24 x 100 Ohm
'Stromversorgung:         : 5V für Logik und LEDs
'Besonderes               : RC5-IR zum Zeitstellen



Hier das Original am Europacenter.



Die Schaltung habe ich auf einer Lochrasterplatine 160mm x 100mm aufgebaut.
Die drei ICs 74HC374(8 Bit D-Zwischenspeicher) sind noch nicht gesteckt.


Die Platine ist mit Kupferlackdraht von 0.3mm Stärke verdrahtet.






Der Lautsprecher ist für das Stundensignal. Über den IR-Empfänger wird die Uhrzeit gestellt.
Das ist einfacher, als mühsam die Zeit über zwei Taster zu stellen.



Verdrahtung der LEDs





Skizze der Anschlussbelegung.



Achtung: In der Schaltung ist der ATMega16 und nicht wie geplant der ATMega8.
Die Ports und Beschaltung muss angepasst werden!



Download Sourcecode : Berlinuhr.bas



'-----------------------------------------------------------------------------------------
'Titel : BerlinUhr
'Name : BerlinUhr.bas
'Autor : Arno Schweißinger
'Datum : 18.11.2007
'MicroContorller : AtMega16 6MHz
'Hardware : Viele LEDs rot grün
' Quarz 32768Hz an Pin TOSC1/2
' 3x 74HC374
'Stromversorgung: : 5V für Logik,
'Besonderes : RC5-IR zum Zeitstellen
'
'PB.0=1 PA=MMMmmmms s=1xSek; m=4x1Min; 11x5Min
'PB.1=1 PA=MMMMMMMM 11x5Min
'PB.2=1 PA=SSSSssss S=4x1Std; s=4x5Std
'
'
'
'
'-----------------------------------------------------------------------------------------

$regfile = "m16def.dat"

$crystal = 1000000
$lib "mcsbyte.lbx" 'use byte library for smaller code

Config Porta = Output
Config Portb = Output
'Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , E = Portc.5 , Rs = Portc.4
'Config Lcd = 40 * 2
Config Rc5 = Pind.7 ', Timer = 1
Config Date = Dmy , Separator = . ' ANSI-Format
Config Clock = Soft 'this is how simple it is

Enable Interrupts

Declare Sub Zeitstellen
Declare Sub Getziffer
Declare Sub Stundensignal
Declare Sub Set_led
Declare Sub Led_updat
Declare Sub Led_lauflicht
Declare Sub Led_minuten_aus
Declare Sub Led_stunden_aus

Declare Sub Bestaetigung
Soundpin
Alias Pind.6

Dim I As Byte
' Dim J As Byte ' Zählschleife
Dim Led_sec As Byte , Led_min As Byte , Led_hour As Byte
Dim Temp As Byte
Dim Port As Byte , Led As Byte
Dim Address As Byte , Command As Byte 'reserve space for variables
Dim S As String * 1 ' sendecode
Dim Zeit As String * 8
Dim Datum As String * 8
Dim Togglebit As Bit
Dim Togglealt As Bit
Date$ = "26.11.07"
Time$ = "00:00:01"


'-------------------------
' Hauptprogramm
'-------------------------
'Begin
Sound Soundpin , 40 , 80 ' Bereitschaftston
Call Led_lauflicht
Sound Soundpin , 40 , 80 ' Bereitschaftston
Call Zeitstellen
Do
Waitms 10 ' Warteschleife
Led_sec
= _sec : Led_min = _min : Led_hour = _hour
Call Stundensignal
Call Led_updat
Loop
End ' ende Hauptprogramm

Sub Led_updat
If _sec = 0 Then
If _min = 0 Then
If _hour = 0 Then Call Led_stunden_aus
Call Led_minuten_aus
End If
End If

Porta = 0
Temp
= Led_sec And 1
If Temp = 1 Then Set Porta.0 ' LED im zwei Sekundentakt

Temp
= Led_min / 5
If Temp > 10 Then Set Porta.7 ' LED Minuten
If Temp > 09 Then Set Porta.6
If Temp > 08 Then Set Porta.5

Temp
= Temp * 5
Temp
= Led_min - Temp
If Temp > 3 Then Set Porta.4 ' LED 5er Minuten
If Temp > 2 Then Set Porta.3
If Temp > 1 Then Set Porta.2
If Temp > 0 Then Set Porta.1

Set Portb.0
Waitus 10
Reset Portb.0

Porta = 0
Temp
= Led_min / 5
If Temp > 7 Then Set Porta.7 ' LED 5er Minuten
If Temp > 6 Then Set Porta.6
If Temp > 5 Then Set Porta.5
If Temp > 4 Then Set Porta.4
If Temp > 3 Then Set Porta.3
If Temp > 2 Then Set Porta.2
If Temp > 1 Then Set Porta.1
If Temp > 0 Then Set Porta.0

Set Portb.1
Waitus 10
Reset Portb.1

Porta = 0
Temp
= Led_hour / 5
If Temp > 3 Then Set Porta.7 ' LED 5er Stunden
If Temp > 2 Then Set Porta.6
If Temp > 1 Then Set Porta.5
If Temp > 0 Then Set Porta.4

Temp
= Temp * 5
Temp
= Led_hour - Temp
If Temp > 3 Then Set Porta.3
If Temp > 2 Then Set Porta.2 ' LED 1er Stunden
If Temp > 1 Then Set Porta.1
If Temp > 0 Then Set Porta.0

Set Portb.2
Waitus 10
Reset Portb.2

End Sub

Sub Stundensignal
If _sec = 0 Then
If _min = 0 Then
' Sound Soundpin , 80 , 400
Sound Soundpin , 30 , 400
Waitms 500
End If
End If
End Sub

Sub Zeitstellen
Led_sec
= 1
For I = 0 To 05 Step 5
Led_min
= I
Call Led_updat
Getrc5(address , Command)
If Command <> 0 Then Exit For ' Timeout
Next I

If Command = 0 Then Exit Sub ' Eingabe Stunden Minuten
Zeit
= ""
For I = 1 To 4
Togglealt
= Togglebit
While Togglealt = Togglebit
Gosub Getziffer
Wend
Sound Soundpin , 10 , 40 ' Bereitschaftston
Call Bestaetigung
Zeit
= Zeit + S
If I = 2 Then Zeit = Zeit + ":"
Next I
Zeit
= Zeit + ":00"
Time$ = Zeit
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

Sub Bestaetigung
Led_min
= Val(s)
Led_min
= Led_min * 5
Call Led_updat
End Sub

Sub Led_lauflicht
Restore Lauflicht
Porta = 0 ' alle LEDs aus
Portb = 7
Waitus 1
Portb = 0
For I = 1 To 24 ' Lauflicht
Read Port ' Port
Read Led ' LED
Call Set_led
Next I
End Sub

Sub Led_stunden_aus
Port
= 2
Led
= 127
Call Set_led
Led
= 63
Call Set_led
Led
= 31
Call Set_led
Led
= 15
Call Set_led
Led
= 7
Call Set_led
Led
= 3
Call Set_led
Led
= 1
Call Set_led
Led
= 0
Call Set_led
End Sub

Sub Led_minuten_aus
Port
= 0
Led
= 126
Call Set_led
Led
= 62
Call Set_led
Led
= 30
Call Set_led

Port
= 1
Led
= 127
Call Set_led
Led
= 63
Call Set_led
Led
= 31
Call Set_led
Led
= 15
Call Set_led
Led
= 7
Call Set_led
Led
= 3
Call Set_led
Led
= 1
Call Set_led
Led
= 0
Call Set_led

Port
= 0
Led
= 14
Call Set_led
Led
= 6
Call Set_led
Led
= 2
Call Set_led
Led
= 0
Call Set_led
End Sub

Sub Set_led
 
Porta = Led
 
Set Portb.port
 
Waitms 100
 
Reset Portb.port
End Sub




'------------------------------------- Decodieren der Tastatur -----------------
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 "" , "" , "" , "" , "" , "" , "" , "" , "" , ""

Lauflicht
:
Data 0 , 2
Data 0 , 6
Data 0 , 14
Data 0 , 30
Data 1 , 1
Data 1 , 3
Data 1 , 7
Data 1 , 15
Data 1 , 31
Data 1 , 63
Data 1 , 127
Data 1 , 255
Data 0 , 62
Data 0 , 126
Data 0 , 254
Data 2 , 1
Data 2 , 3
Data 2 , 7
Data 2 , 15
Data 2 , 31
Data 2 , 63
Data 2 , 127
Data 2 , 255
Data 0 , 255



Erstellt am 07.05.2009

Besucher seit dem 07.05.2009
Counter