Pong-Uhr       

von Gerd Sinning              
Elektronik-Labor   Projekte   AVR 


 
Die PongUhr ist eine Anwendung des Bitmustergenerators PongC1, mit dem die Zahlen zusammengestellt wurden, leicht futuristisch.


 
Die PongUhr zeigt Stunden und Minuten an. Damit sie genauer geht hat sie einen 8 MHz Quarz, der ist auf die Rückseite der Platine gelötet, ohne Kondensatoren, der Quarz schwingt auch so. Man muss dann die Fuses entsprechend programmieren.



Die Platine klebt man mit Blue-Tack in eine Zip-Drive oder auch eine CD-Kassette, dann kann man sie gut an die Wand hängen. Zum Einstellen dient ein kleiner Taster an Int0, der inkrementiert die Stunden und stellt Minuten und Sekunden auf Null. Beim Zeitzeichen auf die Taste drücken.



Dpwnload: PongUhr4.zip


'*********************************************************************
' ATMega8 PongUhr GS 2013
' displays the time hh mm
' use 2 column futuristic numbers
'
' led matrix updated every 1 ms in Compare1a interrupt
'
'
' Int0 (lo) to set time every full Hour
' use pull-up resistor between P1 & P4 !!!
'
''***************************************************************************
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License.
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY;
'***************************************************************************
'
'***************************************************************************
' ATMega8 PDIP
'
' (RESET) PC6 1 28 PC5 (ADC5/SCL)
' (RXD) PD0 2 27 PC4 (ADC4/SDA)
' (TXD) PD1 3 26 PC3 (ADC3)
' (INT0) PD2 4 25 PC2 (ADC2)
' (INT1) PD3 5 24 PC1 (ADC1)
' (XCK/T0) PD4 6 23 PC0 (ADC0)
' VCC 7 22 GND
' GND 8 21 AREF
' (XTAL1/TOSC1)PB6 9 20 AVCC
' (XTAL2/TOSC2)PB7 10 19 PB5 (SCK)
' (T1) PD5 11 18 PB4 (MISO)
' (AIN0) PD6 12 17 PB3 (MOSI/OC2)
' (AIN1) PD7 13 16 PB2 (SS/OC1B)
' (ICP1) PB0 14 15 PB1 (OC1A)
'
'***************************************************************************

$crystal = 8000000
$regfile = "m8def.dat"
$hwstack = 64
$swstack = 64
$framesize = 64

Const C_value = 8000 - 1 'for 1 ms
Ipulse Alias Portd.3
Spulse Alias Portd.1


Dim Dispcnt As Byte 'display counter
Dim Icnt As Word 'ISR counter
Dim Hour_24 As Byte
Dim Minutes As Byte
Dim Seconds As Byte
Dim Col1 As Word
Dim Col2 As Word
Dim Mynum As Byte

Dim Leds(12) As Word
Dim Vhelp As Word
Dim Vy As Byte
Dim Col As Byte
Dim Portdout As Byte
Dim Portcout As Byte
Dim X As Byte
Dim Y As Byte

Declare Sub Test

'*********************************************************************

Config Portb = Output
Ddrc = &B00111111
Portc = &B00000000
Ddrd = &B11111010
Portd = &B00001111

' Config Timer1
Config Timer1 = Timer , Prescale = 1
Tccr1a = &B00000000 '
Tccr1b = &B00001001 'CTC, ck 1
Ocr1ah = High(c_value)
Ocr1al = Low(c_value) ' c_value Timer1 for Period of 1ms

Enable Compare1a
On Compare1a T1cmpa
Enable Timer1

Config Int0 = Falling 'Falling
On Int0 Int0_isr
Enable Int0

Enable Interrupts

Gosub Test


Hour_24 = 12 'start at 12
Mynum = Hour_24 / 10
Gosub Getcols
Leds(1) = Col1
Leds(2) = Col2
X = Mynum * 10
Mynum = Hour_24 - X
Gosub Getcols
Leds(4) = Col1
Leds(5) = Col2
Leds(7) = 511
Leds(8) = 511
Leds(10) = 511
Leds(11) = 511

Do 'loop
If Dispcnt = 1 Then
Dispcnt = 0
Incr Seconds

If Seconds = 60 Then
Seconds = 0
Incr Minutes
End If 'seconds

If Minutes = 60 Then
Minutes = 0
Incr Hour_24
If Hour_24 = 24 Then
Hour_24 = 0
End If 'Hour_24 =24
End If 'minutes


Mynum = Hour_24 / 10
Gosub Getcols
Leds(1) = Col1
Leds(2) = Col2
X = Mynum * 10
Mynum = Hour_24 - X
Gosub Getcols
Leds(4) = Col1
Leds(5) = Col2

Mynum = Minutes / 10
Gosub Getcols
Leds(7) = Col1
Leds(8) = Col2
X = Mynum * 10
Mynum = Minutes - X
Gosub Getcols
Leds(10) = Col1
Leds(11) = Col2

End If 'dispcnt
Loop


'*********************************************************************

T1cmpa: 'interrupt

Toggle Ipulse
Incr Icnt
If Icnt = 1000 Then
Icnt = 0 '1 second
Dispcnt = 1
End If 'Icnt

Col = Col + 1
If Col = 13 Then Col = 1
Vy = Col + 0
Portd = 0
Portb = 0
Portc = 0
If Col = 1 Then Portb.4 = 0 Else Portb.4 = 1
Portb.3 = 1 'cl
Portb.3 = 0
Portb.2 = 1 'Str
Portb.2 = 0
Portdout = Low(leds(vy))
Portcout = Portdout And 15
Portdout = Portdout And 240
Portd = Portdout
Portc = Portcout
Portb = High(leds(vy))

Return 'reti

Int0_isr: 'every full hour
Seconds = 0
Minutes = 0
Incr Hour_24 'set time
If Hour_24 = 24 Then
Hour_24 = 0
End If
Return 'reti


Sub Test
For X = 1 To 12
Leds(x) = 1023
Next X
Waitms 1000
For X = 1 To 12
For Y = 1 To 12
Leds(y) = 0
Next Y
Leds(x) = 1023
Waitms 100
Next X
For Y = 1 To 10
For X = 1 To 12
Vhelp = Y - 1
Vhelp = 2 ^ Vhelp
Leds(x) = Vhelp
Next X
Waitms 100
Next Y
For X = 1 To 12
Leds(x) = 0
Next X
End Sub

Getcols:
Select Case Mynum
Case 0:
Col1 = 511
Col2 = 511
Case 1:
Col1 = 0
Col2 = 511
Case 2:
Col1 = 497
Col2 = 287
Case 3:
Col1 = 273
Col2 = 511
Case 4:
Col1 = 31
Col2 = 496
Case 5:
Col1 = 287
Col2 = 497
Case 6:
Col1 = 511
Col2 = 497
Case 7:
Col1 = 1
Col2 = 511
Case 8:
Col1 = 495
Col2 = 495
Case 9:
Col1 = 31
Col2 = 511
End Select
Return


Elektronik-Labor   Projekte   AVR