Bascom

Oto kolejne programy Piórnika szkolnego. Eksperymenty zostały przeprowadzone pod kątem pełnego wykorzystania wewnętrznej i zewnętrznej pamięci Eprom oraz zastosowania krótkich procedur w programie.

'Piornik06.bas

'Program do wyświetlania ściągi.

'Z pełnym wykorzystaniem Eprom (512 znaków).

'W czasie pisania tekstu pozostaje on cały czas w okienku wyświetlacza.

'Pozwoli zapisać treść w postaci 512 znaków.

'Aby zapisać tekst, należy w Portc.3 ustawić 1 i nacisnąć RESET.

'Aby odczytać zapisany tekst, należy ustawić 0 w Portc.3, nacisnąć RESET

'oraz przycisk w Portc.4. Wyświetli się pierwsza paczka tekstu, czyli 32 znaki.

'Ponowne naciśnięcie przycisku w Portc.4 wyświetli następną paczkę tekstu.

'Zerowanie pamięci Eprom: ustaw 1 w Portc.3, naciśnij RESET, naciśnij Esc.

'Opracował Henryk Wydmuch.

'Pamięć zajęta w 65%

'Fusebit ustawiony na generator wewnętrzny 4MHz (0011).

'Schemat: taki sam jak Piornik02.png.

 

$regfile = "m8def.dat"                                      'Dyrektyway dla kompilatora.

 $crystal = 4000000                                         'Zastosujemy generator wewnętrzny 4MHz.

 Config Lcd = 16 * 2                                        'Konfiguracja Lcd.

Config Lcdpin = Pin , Db4 = Portd.2 , Db5 = Portd.3 , Db6 = Portd.4 , Db7 = Portd.6 , E = Portd.1 , Rs = Portd.0

                                       'LCD dłączony do Portd. 2, 3, 4, 6, 1, 0.

 

Config Timer0 = Timer , Prescale = 1024                     'Konfiguruj Timer0, jako czasomierz, podział wstępny przez 1024.

 

Config Pinc.3 = Input                                       'Przełącznik: zapis albo odczyt.

Set Portc.3                                                 'Podciągnij Port.

Config Pinc.4 = Input                                       'Przycisk przsuwania napisu na Lcd.

Set Portc.4                                                 'Podciągnij Port.

Config Pinc.5 = Output                                      'Led migająca.

Set Portc.5                                                 'Podciągnij Port.

Config Pind.7 = Output                                      'Synał dźwiękowy (alarm przepełnienia pamięci).

Set Portd.7                                                 'Podciągnij Port.

 

Dim Kodklaw As Byte                                         'Jeden bajt dla Kodklaw (znaki ASCI klawiatury).

Dim Q As Long                                               'Jeden bajt dla Q (kolejność naciskania klawisza).

Dim Suma As Byte                                            'Jeden bajt dla Suma (numer klawisza w ASCI).

Dim Przep As Byte                                           'Zmienna zawierająca ilość zajętych okienek Lcd.

Dim Policzlcd As Long                                       'Zmienna pilnująca, aby tekst zawsze był w okienku Lcd.

Dim Krok As Long                                            'Zmienna pamiętająca kroki pętli For - Next.

 

Enable Interrupts                                           'Odblokuj przerwania.

Enable Timer0                                               'Odblokuj przerwania Timer0.

 

Config Keyboard = Pinc.0 , Data = Pinc.1 , Keydata = Keydata       'Konfiguruj klawiaturę.

On Timer0 Mig                                               'Włącz podprogram Mig Timera.

Cls                                                         'Czyść.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Do                                                          'Pierwsza pętla.

  If Pinc.3 = 1 Then                                        'Jeśli przełącznik w Pinc.3 = 1...

  Gosub Druga                                               'Skocz do podprogramu zapisującego Druga.

  Else                                                      'W przeciewnym razie (gdy Pinc.3 = 0)...

  Gosub Odczyt                                              'Skocz do podprogramu odczytującego.

  End If                                                    'Koniec warunku.

Loop                                                        'Powtarzaj pętlę.

End                                                         'Koniec tej pętli.

 

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Druga:                                                      'Podprogram drugiej pętli.

Do                                                          'Pętla.

  Kodklaw = Getatkbd()                                      '

  If Kodklaw > 0 And Kodklaw < 127 Then                     'Jeśli naciśnięto klawisz, a liczba ASCI jest od 0 do 127...

  Incr Q                                                    'Po naciśnięciu klawisza powiększ Q o jeden.

  Suma = Kodklaw                                            'Suma zawiera kod ASCII, taki jak KOdklaw.

'Zapis.

  Writeeeprom Suma , Q                                      'Zapisz Suma do Eprom, adres zawartość Q.

  Lcd Chr(kodklaw)                                          'Pokaż naciśnięty klawisz.

    'Policzlcd pilnuje, aby w czasie zapisywania znaki znajdowały się zawsze w okienku Lcd.

     Incr Policzlcd                                         'Po naciśnięciu klawisza powiększ Policzlcd o jeden.

     Select Case Policzlcd                                  'Sprawdzanie zawartości Policzlcd.

     Case 16 : Locate 2 , 1                                 'Jeśli Policzlcd zawiera 16, ustaw kursor w drugiej linii, pozycja 1.

     Case 32 : Locate 1 , 1                                 '

     Cls

     Case 48 : Locate 2 , 1                                 '

     Case 64 : Locate 1 , 1                                 '

     Cls

     Case 80 : Locate 2 , 1                                 '

     Case 96 : Locate 1 , 1                                 '

     Cls

     Case 112 : Locate 2 , 1                                '

     Case 128 : Locate 1 , 1                                '

     Cls

     Case 144 : Locate 2 , 1                                '

     Case 160 : Locate 1 , 1                                '

     Cls

     Case 176 : Locate 2 , 1                                '

     Case 192 : Locate 1 , 1                                '

     Cls

     Case 208 : Locate 2 , 1                                '

     Case 224 : Locate 1 , 1                                '

     Cls

     Case 240 : Locate 2 , 1                                '

     Case 256 : Locate 1 , 1                                '

     Cls

     Case 272 : Locate 2 , 1                                '

     Case 288 : Locate 1 , 1                                '

     Cls

     Case 304 : Locate 2 , 1                                '

     Case 320 : Locate 1 , 1                                '

     Cls

     Case 336 : Locate 2 , 1                                '

     Case 352 : Locate 1 , 1                                '

     Cls

     Case 368 : Locate 2 , 1                                '

     Case 384 : Locate 1 , 1                                '

     Cls

     Case 400 : Locate 2 , 1                                '

     Case 416 : Locate 1 , 1                                '

     Cls

     Case 432 : Locate 2 , 1                                '

     Case 448 : Locate 1 , 1                                '

     Cls

     Case 464 : Locate 2 , 1                                '

     Case 480 : Locate 1 , 1                                '

     Cls

     Case 496 : Locate 2 , 1                                '

     Case 512 : Locate 1 , 1                                '                                                                                                                        '                                              '                                           '                                              '

     End Select                                             'Koniec przeglądu zmiennej.

 

  If Kodklaw = 1 Then                                       'Jeśli naciśnięto Esc...

  Gosub Kasuj                                               'Skocz do podprogramu kasującego.

  End If                                                    '

 

    If Q = 512 Then                                         'Jeśli zmienna Q zawiera 512 znaków - alarm.

    Gosub Alarm                                             '

    End If                                                  '

End If                                                      'Koniec warunku "gdy naciśnięto klawisz".

Loop                                                        'Powtarzaj pętlę.

End                                                         'Koniec tej pętli.

Return                                                      'Wróć do pierwszej pętli.

 

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Odczyt:                                                     'Podprogram odczytujący z Eprom.

   Waitms 300                                               'Czekaj 300 mS.

   Bitwait Pinc.4 , Reset                                   'Reaguj, kiedy Pinc.4 = 0.

   Cls                                                      'Czyść Lcd.

'''''''''''''''''''''''''

Locate 1 , 1                                                'Pisz w Lcd w pierwszej linii od początku.

  For Krok = 1 To 16                                        'Pętla krocząca od 1 do 16, zapisuje cyry do Krok.

  Readeeprom Suma , Krok                                    'Odczytaj z Eprom, z pierwszej komórki zawartość Suma.

  Lcd Chr(suma)                                             'Pokaż na Lcd zawartość Suma i zamień ją na znak klawiatury.

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 17 To 32                                       '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

''''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 33 To 48                                       '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 49 To 64                                       '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

''''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 65 To 80                                       '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 81 To 96                                       '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

'''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 97 To 112                                      '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 113 To 128                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

'''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 129 To 144                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 145 To 160                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

'''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 161 To 176                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 177 To 192                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

'''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 193 To 208                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 209 To 224                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

'''''''''''''''''''''''                                     '

Locate 1 , 1                                                '

  For Krok = 225 To 240

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 241 To 256                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

'''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 257 To 272                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 273 To 288                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

'''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 289 To 304                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 305 To 320

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

'''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 321 To 336                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 337 To 352                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

'''''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 353 To 368                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 369 To 384                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

''''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 385 To 400                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 401 To 416

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

''''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 417 To 432                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 433 To 448                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

'''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 449 To 464                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 465 To 480                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Waitms 300                                               '

   Bitwait Pinc.4 , Reset                                   '

   Cls                                                      '

'''''''''''''''''''''''

Locate 1 , 1                                                '

  For Krok = 481 To 496                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

 

Locate 2 , 1                                                '

  For Krok = 497 To 512                                     '

  Readeeprom Suma , Krok                                    '

  Lcd Chr(suma)                                             '

  Suma = 0                                                  '

  Next Krok                                                 '

'''''''''''''''''''''''''

   Return                                                   'Wróć do Druga.

 

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Kasuj:                                                      'Podprogram kasowania Eprom.

 Suma = 0                                                   'Zeruj zmienną Suma.

 For Krok = 1 To 512                                        'Krocząsy krok jest adresem.

 Writeeeprom Suma , Krok                                    'Wpisz wyzerowaną zmienną do Eprom, komórka 1.

 Next Krok                                                  '

Return                                                      'Wróć do pętli Druga.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'Z tej pętli wychodzimy przy pomocy RESET.

Alarm:                                                      'Po zapełnieniu pamięci alarm dźwiękowy.

Do                                                          'Pętla.

  Sound Portd.7 , 400 , 500                                 'Sygnał Dźwiękowy.

  Waitms 150                                                'Krótka przerwa.

  Sound Portd.7 , 400 , 400                                 'Sygnał Dźwiękowy.

  Waitms 300                                                '

  Cls                                                       'Czyść.

  Lcd "Memory MAX!"                                         'Komunikat o przepełnieniu pamięci.

  Lowerline                                                 '

  Lcd "RESET"                                               '

  Loop                                                      'Powtarzaj pętlę.

End                                                         'Koniec tej pętli.

Return                                                      'Wróć do Zapis.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Mig:                                                        'Podprogram Timer0 (miganie diody).

 Incr Przep                                                 'Po załadowaniu Timer0, zwiększaj zmienną Przep o 1.

 If Przep = 25 Then                                         'Jeśli uzbiera się 25 przepełnień...

 Przep = 0                                                  'Zeruj zmienną.

  Portc.5 = 0                                               'Zmień poziom w Prtc.5 (zaświeć diodę).

  Waitms 100                                                'Trzymaj świecenie przez 100mS.

  Portc.5 = 1                                               'Wyłącz diodę.

 End If                                                     '

Return                                                      'Wróć do Timer0.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 'Tablica numerów przycisków klawiatury AT w kodzie ASCI:

   Keydata:                                                 'Podprogram tablicy.

     'Małe litery

   Data 0 , 5 , 0 , 3 , 4 , 5 , 6 , &H07 , 5 , 5 , 5 , &H0B , &H0C , 0,       ''''''''''''A

   Data 63 , 63 , 63 , 63 , 63 , 63 , 63 , 113 , 49 , 63 , 63 , 63 , 122,       ''''''''''B

   Data 115 , 97 , 119 , 50 , 63 , 63 , 99 , 120 , 100 , 101 , 52 ,       ''''''''''''''''C

   Data 51 , 63 , 63 , 32 , 118 , 102 , 116 , 114 , 53 , 63 , 63 , 110 ,       '''''''''''D

   Data 98 , 104 , 103 , 121 , 54 , 63 , 63 , 63 , 109 , 106 , 117 , 55 ,       ''''''''''E

   Data 56 , 63 , 63 , 44 , 107 , 105 , 111 , 48 , 57 , 63 , 63 , 46 , 47 ,       ''''''''F

   Data 108 , 59 , 112 , 95 , 63 , 63 , 63 , 63 , 63 , 63 , 61 , 63 , 63 , 63 ,       ''''G

   Data 63 , 13 , 63 , 63 , 124 , 63 , 63 , 63 , 63 , 63 , 63 , 63 , 63 , 63 , 63,       'H

   Data 63 , 49 , 63 , 52 , 55 , 63 , 63 , 63 , 48 , 127 , 50 , 53 , 54 , 56,       ''''''I

   Data 1 , 63 , 5 , 43 , 51 , 45 , 42 , 57 , 63 , 63       ''''''''''''''''''''''''''''''J

 

    'Duże litery

  Data 0 , 0 , 0 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0,       ''''''''''K

  Data 0 , 0 , 0 , 0 , 0 , 0 , 81 , 33 , 03 , 0 , 0 , 90 , 83 , 65,       ''''''''L

  Data 87 , 64 , 0 , 0 , 67 , 88 , 68 , 69 , 36 , 35 , 0 , 0 , 0 , 86,       '''''M

  Data 70 , 84 , 82 , 37 , 0 , 0 , 78 , 66 , 72 , 71 , 89 , 94 , 0,       ''''''''N

  Data 0 , 0 , 77 , 74 , 85 , 38 , 42 , 0 , 0 , 60 , 75 , 73 , 79,       '''''''''O

  Data 41 , 40 , 0 , 0 , 62 , 63 , 76 , 58 , 80 , 0 , 0 , 0 , 0 , 0,       '''''''P

  Data 0 , 123 , 43 , 0 , 0 , 0 , 0 , 0 , 125 , 0 , 0 , 0 , 0 , 0 , 0,       '''''Q

  Data 0 , 0 , 0 , 0 , 0 , 0 , 49 , 49 , 0 , 52 , 55 , 0 , 0 , 0 , 48,       '''''R

  Data 44 , 50 , 53 , 54 , 56 , 0 , 0 , 0 , 43 , 51 , 45 , 42 , 57 , 0 , 0       'S