Skip to content

Instantly share code, notes, and snippets.

@rafalw
Last active December 10, 2015 12:50
Show Gist options
  • Save rafalw/b4ea1f376d0cfd476ee4 to your computer and use it in GitHub Desktop.
Save rafalw/b4ea1f376d0cfd476ee4 to your computer and use it in GitHub Desktop.
Przykład do zajęć - zegar na wyswietlaczu LED wersja uproszczona (konieczność poprawnej implementacji nastawiania zegara). Link do schematu zestawu: http://1drv.ms/1TCZHoL
' Zegar czasu rzeczywistego z wyświetlaczem LED 7-segm.
' - wersja prymitywna
$regfile = "attiny2313.dat"
$Crystal=4000000
$hwstack=40
$swstack=16
$framesize=32
'Config Timer1 = Timer , Prescale = 1
Config Timer1 = Timer , Prescale = 64
On Timer1 Odczyt
Enable Interrupts
Enable Timer1
Config Timer0 = Timer , Prescale = 64
On Timer0 Multipleks
Enable Timer0
Enable Interrupts
Const Zero = &B11000000
Const Jeden = &B11111001
Const Dwa = &B10100100
Const Trzy = &B10110000
Const Cztery = &B10011001
Const Piec = &B10010010
Const Szesc = &B10000010
Const Siedem = &B11111000
Const Osiem = &B10000000
Const Dziewiec = &B10010000
Config Portd = &B1111100
Portd = &B1111111
Config Portb = Output
Portb = &B11111111
Dim I As Byte
Dim Sekundy As Byte
Dim Minuty As Byte
Dim Godziny As Byte
Dim Godz_dzies As Byte
Dim Godz_jedn As Byte
Dim Min_dzies As Byte
Dim Min_jedn As Byte
Dim Tmp As Byte
Do
' Nastawianie czasu
' - przyciski S1 i S2 są analizowane co 100ms
If Pind.0 = 0 Then
Gosub Zmiana_godzin
End If
If Pind.1 = 0 Then
Gosub Zmiana_minut
End If
Waitms 100
Loop
End
Multipleks:
Select Case I
Case 0:
' Portd = &B0111111
Portd.6 = 0
Portd.5 = 1
Portd.4 = 1
Portd.3 = 1
If Godziny < 10 Then
Portb = Zero
Else
Select Case Godz_dzies
Case 1:
Portb = Jeden
Case 2:
Portb = Dwa
End Select
End If
Case 1:
' Portd = &B1011111
Portd.6 = 1
Portd.5 = 0
Portd.4 = 1
Portd.3 = 1
Select Case Godz_jedn
Case 0:
Portb = Zero
Case 1:
Portb = Jeden
Case 2:
Portb = Dwa
Case 3:
Portb = Trzy
Case 4:
Portb = Cztery
Case 5:
Portb = Piec
Case 6:
Portb = Szesc
Case 7:
Portb = Siedem
Case 8:
Portb = Osiem
Case 9:
Portb = Dziewiec
End Select
Case 2:
' Portd = &B1101111
Portd.6 = 1
Portd.5 = 1
Portd.4 = 0
Portd.3 = 1
If Minuty < 10 Then
Portb = Zero
End If
Select Case Min_dzies
Case 1:
Portb = Jeden
Case 2:
Portb = Dwa
Case 3:
Portb = Trzy
Case 4:
Portb = Cztery
Case 5:
Portb = Piec
End Select
Case 3:
' Portd = &B1110111
Portd.6 = 1
Portd.5 = 1
Portd.4 = 1
Portd.3 = 0
Select Case Min_jedn
Case 0:
Portb = Zero
Case 1:
Portb = Jeden
Case 2:
Portb = Dwa
Case 3:
Portb = Trzy
Case 4:
Portb = Cztery
Case 5:
Portb = Piec
Case 6:
Portb = Szesc
Case 7:
Portb = Siedem
Case 8:
Portb = Osiem
Case 9:
Portb = Dziewiec
End Select
End Select
I = I + 1
If I = 4 Then
I = 0
End If
Return
Odczyt:
Portd.2 = Not Portd.2
Incr Sekundy
' Sekundy = Sekundy + 10
If Sekundy >= 60 Then
Sekundy = 0
Gosub Zmiana_minut
End If
Godz_dzies = Godziny \ 10
Tmp = Godz_dzies * 10
Godz_jedn = Godziny - Tmp
Min_dzies = Minuty \ 10
Tmp = Min_dzies * 10
Min_jedn = Minuty - Tmp
Return
Zmiana_minut:
Minuty = Minuty + 1
If Minuty = 60 Then
Minuty = 0
Gosub Zmiana_godzin
End If
Return
Zmiana_godzin:
Godziny = Godziny + 1
If Godziny = 24 Then
Godziny = 0
End If
Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment