bardzo dziękuje za podpowiedź. posprawdzam połaczenia wyświetlacza bo myślałem że rozmieszczenie jest standatdowe, ale upewnie się. co do procedur inicjalizujących lcd to nie mam pojęcia bo jestem zielony z programowania. wklepałem gotowy listing i go skompilowałem.
jeśli ktoś potrafi zweryfikowac i ewentualnie wskazac błedy w listingu to byłbym wdzięczny.[
$crystal = 12000000
$large
Dim Klawisz As Byte , Pomoc As Byte , Pomoc1 As Byte
Dim Adres As Byte , Licznik As Byte
Dim Wartosc As Byte , Wartosc1 As Byte
Dim Wartosc2 As Byte , Stan1 As Byte
Dim Licznik1 As Word
Declare Sub Zapis_p(adres As Byte , Wartosc As Byte)
Declare Sub Odczyt_p(adres As Byte , Wartosc As Byte)
Dim Addressw As Const 174 , Addressr As Const 175
P0 = 255
P2 = 255
P3 = 255
P1 = 0
P2.1 = 0
Cursor Off
Cls
Lcd "Centrala 89C51"
Locate 2 , 1
Lcd "właściciel"
Wait 3
If P2.5 = 0 Then
Gosub Pamiec
End If
Gosub Sprawdz_stan
'Glowna Petla Programu
Do
Cls
Lcd "Wlacz alarm - 1"
Locate 2 , 1
Lcd "Zmien kod - 2"
Do
Gosub Wybor
Loop Until Klawisz <> 0
If Klawisz = 1 Then
Gosub Aktywacja
End If
Loop
'Podprogram Ustaw
Ustaw:
Klawisz = 0
Pomoc = 0
Cls
Lcd "Wpisz stary kod"
Wait 2
Gosub Kasuj_blok1
Gosub Wyswietlacz1
Do
Gosub Klawiatura
Loop Until Klawisz = 11
Klawisz = 0
Gosub Sprawdz
If Pomoc = 0 Then
Gosub Wyswietlacz2
Return
End If
Cls
Lcd "Wpisz nowy kod"
Wait 2
Gosub Kasuj_blok1
Gosub Wyswietlacz1
Do
Gosub Klawiatura
Loop Until Klawisz = 11
Gosub Przepisz1
Cls
Lcd "Nowy kod wpisany"
Wait 2
Pomoc = 0
Return
'Podprogram Pamiec
Pamiec:
Klawisz = 0
Cls
Lcd " Czy chcesz "
Locate 2 , 1
Lcd "skasowac pamiec?"
Wait 3
Cls
Lcd " TAK - 1; NIE - 2 "
Do
Gosub Wybor
Loop Until Klawisz <> 0
If Klawisz = 1 Then
Cls
Lcd " Kasowanie "
Gosub Kasuj_2416
Wait 1
Adres = 0
Klawisz = 0
Gosub Wyswietlacz1
Do
Gosub Klawiatura
Loop Until Klawisz = 11
Gosub Przepisz1
Gosub Kasuj_blok1
End If
Klawisz = 0
Return
'Podprogram Przepisz1
Przepisz1:
Adres = 0
Licznik = 0
For Licznik = 0 To 15
Adres = Licznik
Call Odczyt_p(adres , Wartosc)
Adres = Licznik + 20
Call Zapis_p(adres , Wartosc)
Next Licznik
Adres = 0
Licznik = 0
Return
'Podprogram Aktywacja
Aktywacja:
P2.1 = 1
P2.3 = 0
Pomoc = 0
Stan1 = 1
Licznik1 = 0
Call Zapis_p(51 , 0)
Cls
Lcd "ALARM WLACZONY "
Do
If Stan1 = 1then
Gosub Stan
End If
Gosub Wybor
If Klawisz = 13 Then
Gosub Wylacz
End If
Loop Until Pomoc = 1
Call Zapis_p(51 , 255)
P2.3 = 1
P2.1 = 0
P2.0 = 1
Cls
Lcd "ALARM WYLACZONY "
Wait 2
Adres = 0
Wartosc = 0
Pomoc = 1
Klawisz = 0
Licznik = 0
Stan1 = 0
Return
'Podprogram Stan
Stan:
If P0 <> 0 Then
Gosub Alarm
Return
End If
If P2.4 = 1 Then
Gosub Alarm
Return
End If
If P2.7 = 1 Then
Gosub Alarm
Return
End If
If P2.6 = 1 Then
Gosub Zwloka
Return
End If
Return
'Podprogram Zwloka
Zwloka:
Waitms 10
Incr Licznik1
If Licznik1 > 2000 Then
Gosub Alarm
End If
Return
'Podprogram Wylacz
Wylacz:
Adres = 0
Klawisz = 0
Pomoc = 0
Klawisz = 0
Gosub Wyswietlacz1
Do
Do
If Stan1 = 1 Then
Gosub Stan
End If
If Pomoc1 = 1 Then
Gosub Wyswietlacz1
Pomoc1 = 0
End If
Gosub Klawiatura
Loop Until Klawisz = 11
Gosub Sprawdz
Gosub Kasuj_blok1
Gosub Wyswietlacz1
Adres = 0
Klawisz = 0
Loop Until Pomoc = 1
Stan1 = 0
Return
'Podprogram Sprawdz
Sprawdz:
Adres = 0
Licznik = 0
Pomoc = 0
Klawisz = 0
For Licznik = 0 To 15
Adres = Licznik
Call Odczyt_p(adres , Wartosc)
Wartosc1 = Wartosc
Adres = Licznik + 20
Call Odczyt_p(adres , Wartosc)
Wartosc2 = Wartosc
If Wartosc1 <> Wartosc2 Then
Return
End If
Next Licznik
Pomoc = 1
Return
'Podprogram Alarm
Alarm:
P2.0 = 0
Klawisz = 0
Stan1 = 0
Licznik = 0
Adres = 0
Pomoc = 0
Stan1 = 0
Cls
Lcd " W L A M A N I E "
Gosub Kasuj_blok1
Stan1 = 0
Pomoc1 = 1
Return
'Podprogram Wybor
Wybor:
Adres = 0
Klawisz = 0
Reset P3.7
If P3.3 = 0 Then
Klawisz = 1
Gosub Opoznienie
End If
If P3.0 = 0 Then
Klawisz = 13
Gosub Opoznienie
End If
P3 = 255
Reset P3.6
If P3.3 = 0 Then
Klawisz = 2
Gosub Opoznienie
End If
P3 = 255
Return
'Podprogram Sprawdz Stan
Sprawdz_stan:
Call Odczyt_p(51 , Wartosc)
If Wartosc = 0 Then
Gosub Aktywacja
End If
Return
'Podprogram Kasowania 2416
Kasuj_2416:
Adres = 0
For Adres = 0 To 51
Call Zapis_p(adres , 255)
Next Adres
Adres = 0
Return
'Podprogram Opoznienie
Opoznienie:
Licznik = 0
P2.2 = 0
Waitms 50
P2.2 = 1
Do
P3.7 = 0
P3.6 = 0
P3.5 = 0
P3.4 = 0
If P3 = 00001111 Then
Licznik = 1
End If
If Stan1 = 1 Then
Gosub Stan
End If
Loop Until Licznik = 1
Waitms 50
P3 = 255
Return
'Podprogram Klawiatura
Klawiatura:
P3 = 255
Reset P3.7
If P3.3 = 0 Then
Klawisz = 1
Lcd "1"
Wartosc = Klawisz
Call Zapis_p(adres , Wartosc)
Gosub Opoznienie
Incr Adres
Gosub Klawiatura2
Elseif P3.2 = 0 Then
Klawisz = 5
Lcd "5"
Wartosc = Klawisz
Call Zapis_p(adres , Wartosc)
Gosub Opoznienie
Incr Adres
Gosub Klawiatura2
Elseif P3.1 = 0 Then
Klawisz = 9
Lcd "9"
Wartosc = Klawisz
Call Zapis_p(adres , Wartosc)
Gosub Opoznienie
Incr Adres
Gosub Klawiatura2
End If
P3 = 255
Reset P3.6
If P3.3 = 0 Then
Klawisz = 2
Lcd "2"
Wartosc = Klawisz
Call Zapis_p(adres , Wartosc)
Gosub Opoznienie
Incr Adres
Gosub Klawiatura2
Elseif P3.2 = 0 Then
Klawisz = 6
Lcd "6"
Wartosc = Klawisz
Call Zapis_p(adres , Wartosc)
Gosub Opoznienie
Incr Adres
Gosub Klawiatura2
Elseif P3.1 = 0 Then
Klawisz = 0
Lcd "0"
Wartosc = Klawisz
Call Zapis_p(adres , Wartosc)
Gosub Opoznienie
Incr Adres
Gosub Klawiatura2
End If
P3 = 255
Reset P3.5
If P3.3 = 0 Then
Klawisz = 3
Lcd "3"
Wartosc = Klawisz
Call Zapis_p(adres , Wartosc)
Gosub Opoznienie
Incr Adres
Gosub Klawiatura2
Elseif P3.2 = 0 Then
Klawisz = 7
Lcd "7"
Wartosc = Klawisz
Call Zapis_p(adres , Wartosc)
Gosub Opoznienie
Incr Adres
Gosub Klawiatura2
Elseif P3.1 = 0 Then
Klawisz = 11
Gosub Opoznienie
If Adres > 16 Then
Gosub Klawiatura2
End If
Return
End If
P3 = 255
Reset P3.4
If P3.3 = 0 Then
Klawisz = 4
Lcd "4"
Wartosc = Klawisz
Call Zapis_p(adres , Wartosc)
Gosub Opoznienie
Incr Adres
Gosub Klawiatura2
Elseif P3.2 = 0 Then
Klawisz = 8
Lcd "8"
Wartosc = Klawisz
Call Zapis_p(adres , Wartosc)
Gosub Opoznienie
Incr Adres
Gosub Klawiatura2
Elseif P3.1 = 0 Then
Klawisz = 12
Gosub Opoznienie
Adres = 17
Gosub Klawiatura2
End If
P3 = 255
Return
'Podprogram Klawiatura2 , Pomocniczy
Klawiatura2:
If Adres > 16 Then
Gosub Kasuj_blok1
Locate 2 , 1
Lcd " "
Locate 2 , 1
Adres = 0
Klawisz = 0
End If
Return
'Podprogram Kasuj_blok1
Kasuj_blok1:
Adres = 0
For Adres = 0 To 19
Call Zapis_p(adres , 255)
Next Adres
Adres = 0
Return
'Podprogram Wyswietlacz1
Wyswietlacz1:
Cls
Lcd " Podaj kod "
Locate 2 , 1
Return
'Podprogram Wyswietlacz2
Wyswietlacz2:
Cls
Lcd " Nieprawidlowy kod "
Locate 2 , 1
Return
'Procedura Zapisu Pamieci Eeprom 24c04
Sub Zapis_p(adres As Byte , Wartosc As Byte)
I2cstart
I2cwbyte Addressw
I2cwbyte Adres
I2cwbyte Wartosc
I2cstop
Waitms 10
End Sub
'Procedura Odczytu Pamieci Eeprom 24c04
Sub Odczyt_p(adres As Byte , Wartosc As Byte)
I2cstart
I2cwbyte Addressw
I2cwbyte Adres
I2cstart
I2cwbyte Addressr
I2crbyte Wartosc , 9
I2cstop
End Sub
tex][/tex]