'******************************************************************************* $large '******************************************************************************* '******************************************************************************* 'Zegar binarny 'Miroslaw Firlej '******************************************************************************* 'Zmienne '******************************************************************************* Dim Flaga_praca As Bit , Wygaszenie As Bit , Stan_buzzer As Bit , Help_bit As Bit Dim Poz_menu As Byte , Inwersja_wysw As Bit , Kolejnosc As Bit , Buzzer_onoff As Bit Dim Co2ms As Byte , Co4ms As Byte , Co1sek As Byte Dim Sp1 As Byte , Auto_powrot As Byte , Licz_miganie As Byte Dim Sekundy As Byte , Minuty As Byte , Godziny As Byte Dim Minuty_buz As Byte , Godziny_buz As Byte , Sekundy_buz As Byte Dim Poz_wyswietlana As Byte , Ustawianie As Byte Dim Przycisk As Byte , Przycisk2 As Byte , Przycisk3 As Byte Dim P_plus As Bit , P_minus As Bit , P_menu As Bit '******************************************************************************* 'stawienia Początkowe '******************************************************************************* Enable Interrupts Config Timer0 = Timer , Gate = Internal , Mode = 2 Load Timer0 , 250 Enable Timer0 Start Timer0 On Timer0 Przerwanie_timer '******************************************************************************* 'Nazwy Wyprowadzeń '******************************************************************************* Buzzer Alias P3.7 Test_napiecia Alias P1.4 Prz_plus Alias P1.5 Prz_minus Alias P1.7 Prz_menu Alias P1.6 '******************************************************************************* 'Wartosci poczatkowe '******************************************************************************* Buzzer = 1 P1 = 255 Prz_plus = 1 Prz_minus = 1 Prz_menu = 1 Test_napiecia = 1 Inwersja_wysw = 1 Kolejnosc = 1 Poz_wyswietlana = 5 Ustawianie = 0 Poz_menu = 0 '0=czas ,1=budzik 2=ustawienia Auto_powrot = 0 '******************************************************************************* 'Program Glowny '******************************************************************************* Do If Test_napiecia = 1 Then P1 = 255 Buzzer = 1 Idle Else If Flaga_praca = 1 Then Gosub Praca End If Loop End '******************************************************************************* 'Przerwanie Timera '******************************************************************************* Przerwanie_timer: Incr Co2ms If Co2ms = 8 Then Co2ms = 0 Set Flaga_praca 'co 2ms Incr Co4ms If Co4ms = 2 Then Co4ms = 0 Incr Co1sek If Co1sek = 250 Then Co1sek = 0 Incr Sekundy If Sekundy >= 60 Then Sekundy = 0 Incr Minuty If Minuty >= 60 Then Minuty = 0 Incr Godziny If Godziny >= 24 Then Godziny = 0 End If End If End If End If End If End If Return '******************************************************************************* 'Wykonywane co 2ms '******************************************************************************* Praca: Flaga_praca = 0 Incr Poz_wyswietlana If Poz_wyswietlana = 6 Then Poz_wyswietlana = 0 'multipleksuje cyfry Gosub Obsl_przyciskow Gosub Sterowanie Incr Licz_miganie If Licz_miganie = 125 Then Licz_miganie = 0 Wygaszenie = Not Wygaszenie End If Select Case Poz_wyswietlana Case 0: '1 cyfra Set P3.5 '************ Select Case Poz_menu Case 0: Sp1 = Godziny / 10 Case 1: Sp1 = Godziny_buz / 10 Case 2: Sp1 = 1 End Select If Inwersja_wysw = 1 Then Sp1 = Not Sp1 Gosub Kasuj If Ustawianie = 1 Then If Wygaszenie = 1 Then P1 = 255 Else P1 = Sp1 Else P1 = Sp1 End If '************ Reset P3.0 Case 1: '2 cyfra Set P3.0 '************ Select Case Poz_menu Case 0: Sp1 = Godziny Mod 10 Case 1: Sp1 = Godziny_buz Mod 10 Case 2: Sp1 = 1 End Select If Inwersja_wysw = 1 Then Sp1 = Not Sp1 Gosub Kasuj If Ustawianie = 1 Then If Wygaszenie = 1 Then P1 = 255 Else P1 = Sp1 Else P1 = Sp1 End If '************ Reset P3.1 Case 2: Set P3.1 '************ Select Case Poz_menu Case 0: Sp1 = Minuty / 10 Case 1: Sp1 = Minuty_buz / 10 Case 2: Sp1 = 6 End Select If Inwersja_wysw = 1 Then Sp1 = Not Sp1 Gosub Kasuj If Ustawianie = 2 Then If Wygaszenie = 1 Then P1 = 255 Else P1 = Sp1 Else P1 = Sp1 End If '************ Reset P3.2 Case 3: Set P3.2 '************ Select Case Poz_menu Case 0: Sp1 = Minuty Mod 10 Case 1: Sp1 = Minuty_buz Mod 10 Case 2: Sp1 = 6 End Select If Inwersja_wysw = 1 Then Sp1 = Not Sp1 Gosub Kasuj If Ustawianie = 2 Then If Wygaszenie = 1 Then P1 = 255 Else P1 = Sp1 Else P1 = Sp1 End If '************ Reset P3.3 Case 4: Set P3.3 '************ Select Case Poz_menu Case 0: Sp1 = Sekundy / 10 Case 1: Sp1 = Sekundy_buz / 10 Case 2: If Buzzer_onoff = 1 Then Sp1 = 2 Else Sp1 = 14 End Select If Inwersja_wysw = 1 Then Sp1 = Not Sp1 Gosub Kasuj If Ustawianie = 3 Then If Wygaszenie = 1 Then P1 = 255 Else P1 = Sp1 Else P1 = Sp1 End If '************ Reset P3.4 Case 5: Set P3.4 '************ Select Case Poz_menu Case 0: Sp1 = Sekundy Mod 10 Case 1: Sp1 = Sekundy_buz Mod 10 Case 2: If Buzzer_onoff = 1 Then Sp1 = 7 Else Sp1 = 14 End Select If Inwersja_wysw = 1 Then Sp1 = Not Sp1 Gosub Kasuj If Ustawianie = 3 Then If Wygaszenie = 1 Then P1 = 255 Else P1 = Sp1 Else P1 = Sp1 End If '************ Reset P3.5 End Select Return '******************************************************************************* 'Obsluga Przyciskow '******************************************************************************* Obsl_przyciskow: If Prz_plus = 0 Then Incr Przycisk If Przycisk = 30 Then Set P_plus Else Reset P_plus Else Przycisk = 0 Reset P_plus End If If Prz_minus = 0 Then Incr Przycisk2 If Przycisk2 = 30 Then Set P_minus Else Reset P_minus Else Przycisk2 = 0 Reset P_minus End If If Prz_menu = 0 Then Incr Przycisk3 If Przycisk3 = 30 Then Set P_menu Else Reset P_menu Else Przycisk3 = 0 Reset P_menu End If '**************************************** If P_menu = 1 Then '******** If Ustawianie = 0 Then Incr Poz_menu If Poz_menu = 3 Then Poz_menu = 0 Else Incr Ustawianie If Ustawianie = 4 Then Ustawianie = 0 End If '******** End If If P_plus = 1 And P_minus = 0 Then '******** Select Case Ustawianie Case 0: Ustawianie = 1 Case 1: Select Case Poz_menu Case 0: Incr Godziny If Godziny = 24 Then Godziny = 0 Case 1: Incr Godziny_buz If Godziny_buz = 24 Then Godziny_buz = 0 Case 2: Kolejnosc = Not Kolejnosc End Select Case 2: Select Case Poz_menu Case 0: Incr Minuty If Minuty = 60 Then Minuty = 0 Case 1: Incr Minuty_buz If Minuty_buz = 60 Then Minuty_buz = 0 Case 2: Inwersja_wysw = Not Inwersja_wysw End Select Case 3: Select Case Poz_menu Case 0: Sekundy = 0 Case 1: Incr Sekundy_buz If Sekundy_buz = 60 Then Sekundy_buz = 0 Case 2: Buzzer_onoff = Not Buzzer_onoff End Select End Select '******** End If If P_plus = 0 And P_minus = 1 Then '******** Select Case Ustawianie Case 0: Case 1: Select Case Poz_menu Case 0: Decr Godziny If Godziny = 255 Then Godziny = 23 Case 1: Decr Godziny_buz If Godziny_buz = 255 Then Godziny_buz = 23 Case 2: Kolejnosc = Not Kolejnosc End Select Case 2: Select Case Poz_menu Case 0: Decr Minuty If Minuty = 255 Then Minuty = 59 Case 1: Decr Minuty_buz If Minuty_buz = 255 Then Minuty_buz = 59 Case 2: Inwersja_wysw = Not Inwersja_wysw End Select Case 3: Select Case Poz_menu Case 0: Sekundy = 0 Case 1: Decr Sekundy_buz If Sekundy_buz = 255 Then Sekundy_buz = 59 Case 2: Buzzer_onoff = Not Buzzer_onoff End Select End Select '******** End If '**************************************** Return '******************************************************************************* 'Sterowanie buzzera '******************************************************************************* Sterowanie: Return '******************************************************************************* 'Resetowanie '******************************************************************************* Kasuj: If Kolejnosc = 1 Then Help_bit = Sp1.0 Sp1.0 = Sp1.3 Sp1.3 = Help_bit Help_bit = Sp1.1 Sp1.1 = Sp1.2 Sp1.2 = Help_bit If Poz_wyswietlana = 0 Then Clr c Rotate Sp1 , Right , 2 End If End If Sp1.7 = 1 Sp1.6 = 1 Sp1.5 = 1 Sp1.4 = 1 Return '******************************************************************************* '******************************************************************************* '******************************************************************************* '*******************************************************************************