Zegar rtc DS3221
: 06 paź 2017, 15:39
Proszę o pomoc forumowiczów w dokończeniu poniższego wsadu do zegarka RTC. Kontroler M16, zegar DS3221. Problem polega na wyświetlaniu dużych fontów na LCD 4*20. Czytałem poradnik na powyższej stronie lecz nie do końca rozumię o co tam chodzi. Napisałem część kodu lecz nie wiem co dalej. Chciałbym również dorobić zdalny odczyt temperatury na odbiorniku RF, odbiornik RF podpięty do wyjścia TX. Czy ma ktoś jakiś pomysł jak to zrobić. Za pomoc serdecznie dziękuję.
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $regfile = "m16def.dat"
- $crystal = 8000000
- $hwstack = 40
- $swstack = 16
- $framesize = 32
- Config Submode = New
- '**************************
- 'Konfiguracja wejsc i wyjsc
- '**************************
- Config Lcdpin = Pin , Db4 = Porta.5 , Db5 = Porta.4 , Db6 = Porta.3 , Db7 = Porta.2 , E = Porta.6 , Rs = Porta.7
- Config Lcd = 20x4
- Cursor Off , Noblink
- Cls
- Deflcdchar 0 , 31 , 31 , 31 , 32 , 32 , 32 , 32 , 32 'górna belka
- Deflcdchar 1 , 28 , 30 , 31 , 31 , 31 , 31 , 31 , 31 'prawy górny narożnik
- Deflcdchar 2 , 31 , 31 , 31 , 31 , 31 , 31 , 30 , 28 'prawy dolny narożnik
- Deflcdchar 3 , 32 , 32 , 32 , 32 , 32 , 31 , 31 , 31 'dolna kreska
- Deflcdchar 4 , 31 , 31 , 31 , 31 , 31 , 31 , 15 , 7 'lewy dolny narożnik
- Deflcdchar 5 , 7 , 15 , 31 , 31 , 31 , 31 , 31 , 31 'lewy górny narożnik
- Deflcdchar 6 , 32 , 32 , 32 , 32 , 32 , 32 , 31 , 31 'środkowa kreska
- Config 1wire = Portb.4
- Config Sda = Portc.1
- Config Scl = Portc.0
- I2cinit
- Const Ds1307w = 208
- Const Ds1307r = 209
- Config Timer1 = Timer , Prescale = 8 'Konfiguracja TIMER1
- On Timer1 Przerwanie_30s
- Config Pinc.4 = Input : Portc.4 = 1 'podciągnięcie do vcc
- Config Pinc.5 = Input : Portc.5 = 1
- Config Pinc.6 = Input : Portc.6 = 1
- Config Pinc.7 = Input : Portc.7 = 1
- Config Porta.1 = Output : Porta.1 = 0 'stan poczatkowy portu niski
- Config Portd.1 = Output : Portd.1 = 0
- Config Portd.2 = Output : Portd.2 = 0
- '*******
- 'Zmienne
- '*******
- Dim Time_sek As Byte
- Dim Time_min As Byte
- Dim Time_godz As Byte
- Dim Date_dzi_tyg As Byte
- Dim Date_m As Byte
- Dim Date_d As Byte
- Dim Date_r As Byte
- Dim Old_sec As Byte
- Dim Timeout As Word
- Dim Get_timeout As Byte
- Dim Temp_wew As String * 5
- Dim Dsid1(8) As Byte
- Dim T As Integer
- Dim Get_temp As Byte
- Dim Licznik_temper As Word
- Declare Sub Set_time
- Declare Sub Ustaw_czas
- Declare Sub Ustaw_data
- Declare Sub Pomiar_ds18b20
- '************
- 'Nazwy portów
- '************
- Sw1_mode Alias Pinc.4
- Sw2_up Alias Pinc.5
- Sw3_down Alias Pinc.6
- Sw4_write Alias Pinc.7
- Led Alias Porta.1
- Data_ Alias Portd.0
- Buzzer Alias Portd.2
- Locate 1 , 4
- Lcd "RADIO ZEGAR RTC "
- Lowerline
- Locate 2 , 1
- Lcd "ELECTRONICSS SERWICE"
- Thirdline
- Locate 3 , 4
- Lcd "ELESTER - PKP &"
- Fourthline
- Locate 4 , 3
- Lcd "RAFAL PIWOWARCZYK"
- Set Led
- Set Buzzer
- Wait 1
- Reset Led
- Reset Buzzer
- Wait 1
- Set Led
- Set Buzzer
- Wait 1
- Reset Led
- Reset Buzzer
- Wait 1
- Set Led
- Wait 3
- Cls
- '*********************
- 'Petla glowna programu
- '*********************
- Enable Interrupts
- Do
- Gosub Get_time
- If Old_sec <> Time_sek Then
- Old_sec = Time_sek
- Locate 1 , 1
- Lcd "CZAS: " ; Bcd(time_godz) ; ":" ; Bcd(time_min) ; ":" ; Bcd(time_sek) ;
- Fourthline
- Locate 4 , 1
- Lcd "DATA: " ; Bcd(date_d) ; "/" ; Bcd(date_m) ; "/20" ; Bcd(date_r) ;
- End If
- Home
- Enable Timer1
- Reset Buzzer
- Set Led
- If Sw1_mode = 0 Then
- Call Ustaw_czas
- End If
- If Sw2_up = 0 Then
- Call Ustaw_data
- End If
- If Get_temp = 1 Then
- Get_temp = 0
- Call Pomiar_ds18b20
- End If
- Loop
- End
- '*******************
- 'Odczyt czasu DS3221
- '*******************
- Get_time:
- I2cstart
- I2cwbyte Ds1307w
- I2cwbyte 0
- I2cstart
- I2cwbyte Ds1307r
- I2crbyte Time_sek , Ack
- I2crbyte Time_min , Ack
- I2crbyte Time_godz , Ack
- I2crbyte Date_dzi_tyg , Ack
- I2crbyte Date_d , Ack
- I2crbyte Date_m , Ack
- I2crbyte Date_r , Nack
- I2cstop
- Return
- '******************
- 'Zapis czasu DS3221
- '******************
- Sub Set_time:
- I2cstart
- I2cwbyte Ds1307w
- I2cwbyte 0
- I2cwbyte Time_sek
- I2cwbyte Time_min
- I2cwbyte Time_godz
- I2cwbyte Date_dzi_tyg
- I2cwbyte Date_d
- I2cwbyte Date_m
- I2cwbyte Date_r
- I2cstop
- End Sub
- '*********************
- 'Podprogram ustaw_czas
- '*********************
- Sub Ustaw_czas:
- Timeout = 0 'wyzerowanie Timeoutu przy wejściu w Sub
- Cls
- Wait 1
- Do
- Locate 1 , 6
- Lcd "USTAW CZAS:"
- Thirdline
- Locate 3 , 9
- Lcd ; Bcd(time_godz) ; ":" ; Bcd(time_min) ;
- If Sw2_up = 0 Then 'ustaw godziny
- Timeout = 0 'odwleka czas do automatycznego wyjścia
- Time_godz = Makedec(time_godz)
- Incr Time_godz
- If Time_godz > 23 Then
- Time_godz = 0
- End If
- Waitms 250
- Time_godz = Makebcd(time_godz)
- End If
- If Sw3_down = 0 Then 'ustaw minuty
- Timeout = 0 'odwleka czas do automatycznego wyjścia
- Time_min = Makedec(time_min)
- Incr Time_min
- If Time_min > 59 Then
- Time_min = 0
- End If
- Waitms 250
- Time_min = Makebcd(time_min)
- End If
- If Sw4_write = 0 Then 'wyjście i zapis czasu
- Time_sek = 0
- Timeout = 0 'odwleka czas do automatycznego wyjścia
- Waitms 250
- Call Set_time
- Exit Do
- End If
- If Get_timeout = 1 Then 'samoczynne wyjście z menu po 30 sek.
- Get_timeout = 0
- Set Buzzer
- Reset Led
- Waitms 500
- Cls
- Exit Do
- End If
- Loop
- End Sub
- '*********************
- 'Podprogram ustaw_data
- '*********************
- Sub Ustaw_data:
- Timeout = 0
- Cls
- Wait 1
- Do
- Locate 1 , 6
- Lcd "USTAW DATE:"
- Thirdline
- Locate 3 , 7
- Lcd ; Bcd(date_d) ; "/" ; Bcd(date_m) ; "/20" ; Bcd(date_r) ;
- If Sw1_mode = 0 Then 'ustaw dzień
- Timeout = 0 'odwleka czas do automatycznego wyjścia
- Date_d = Makedec(date_d)
- Incr Date_d
- If Date_d > 31 Then
- Date_d = 1
- End If
- Waitms 250
- Date_d = Makebcd(date_d)
- End If
- If Sw2_up = 0 Then 'ustaw miesiąc
- Timeout = 0 'odwleka czas do automatycznego wyjścia
- Date_m = Makedec(date_m)
- Incr Date_m
- If Date_m > 12 Then
- Date_m = 1
- End If
- Waitms 250
- Date_m = Makebcd(date_m)
- End If
- If Sw3_down = 0 Then 'ustaw rok
- Timeout = 0 'odwleka czas do automatycznego wyjścia
- Date_r = Makedec(date_r)
- Incr Date_r
- If Date_r > 99 Then
- Date_r = 1
- End If
- Waitms 250
- Date_r = Makebcd(date_r)
- End If
- If Sw4_write = 0 Then
- Waitms 250
- Call Set_time
- Exit Do
- End If
- If Get_timeout = 1 Then 'samoczynne wyjście z menu po 30 sek.
- Get_timeout = 0
- Set Buzzer
- Reset Led
- Waitms 500
- Cls
- Exit Do
- End If
- Loop
- End Sub
- '******************
- 'Odczyt temperatury
- '******************
- Sub Pomiar_ds18b20:
- Disable Timer1
- Dsid1(1) = 1wsearchfirst()
- 1wreset
- 1wwrite &HCC
- 1wwrite &H44
- Waitms 750
- 1wreset
- 1wwrite &H55
- 1wverify Dsid1(1)
- 1wwrite &HBE
- T = 1wread(2)
- T = T * 8
- T = T / 16
- Temp_wew = Str(t)
- Temp_wew = Format(temp_wew , "+0.0")
- Cls
- Cursor Off
- Locate 1 , 6
- Lcd "TEMPERATURA"
- Thirdline
- Locate 3 , 8
- Lcd ; Temp_wew ; Chr(223) ; "C "
- Wait 5
- Cls
- End Sub
- '********************
- 'Przerwanie od timer1
- '********************
- Przerwanie_30s:
- Incr Timeout
- If Timeout > 458 Then ' odlicz do 30 sek.
- Timeout = 0
- Get_timeout = 1
- End If
- Incr Licznik_temper
- If Licznik_temper > 305 Then 'odlicz do 20 sek.
- Licznik_temper = 0
- Get_temp = 1
- End If
- Return