Created
June 11, 2013 18:06
-
-
Save rafalw/5759248 to your computer and use it in GitHub Desktop.
Mikroprocesorowy sterownik wyświetlacza alfanumerycznego typu 16*2 z dostępem przez łącze szeregowe (UART).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Stałe używane przez sterownik | |
Const Clean = 255 | |
Const Cleft = 254 | |
Const Cright = 253 | |
Const Con = 252 | |
Const Coff = 251 | |
Const Cblink = 250 | |
Const Cnoblink = 249 | |
Const Cupline = 248 | |
Const Cdownline = 247 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Mikroprocesorowy sterownik wyświetlacza alfanumerycznego typu 16*2 | |
' (dwa wiersze po szesnaście znaków; układ zgodny z HD44780). | |
' Właściwości: | |
' - komunikacja (wysyłanie danych do wyświetlenia i sterowanie LCD) poprzez UART | |
' - prędkość transmisji: 9600b/s (parametry: 8n1 - domyślne dla ATtiny2313 i innych) | |
' - podstawowe funkcjonalności: | |
' * wyświetlanie tekstu w podstawowym kodzie ASCII (kody od 32 do 126) | |
' * sterowanie wyświetlacza (czyszczenie, sterowanie kursorem) | |
' * ustalenie początku wyświetlania (Locate): | |
' należy wysłać do sterownika informacjępostaci: | |
' &B110xxxxy, gdzie xxxx to pozycja-w-wierszu - 1, a y to wiersz - 1, | |
' np. &B11000111 - wiersz 2, pozycja 4 | |
$regfile = "attiny2313.dat" | |
$crystal = 4000000 | |
$hwstack = 40 | |
$swstack = 16 | |
$framesize = 32 | |
$baud = 9600 | |
$lib "LCD4.LBX" | |
$include "slcddrv.bas" | |
' Konfiguracja LCD zgodnie z wymogiem biblioteki LCD4 | |
Config Lcdpin = Pin , Rs = Portb.0 , E = Portb.2 , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 | |
Config Lcd = 16 * 2 | |
' Buforowanie danych wejściowych - bez tego sterownik gubi znaki | |
Config Serialin = Buffered , Size = 32 | |
Enable Interrupts | |
Dim Znak As Byte | |
Dim Ile_znakow As Byte | |
Dim Poz_y As Byte | |
Dim Poz_x As Byte | |
Dim Linia As Bit | |
Dim Locate_odebrany As Bit | |
Cls | |
Do | |
Znak = Inkey() | |
If Znak = Clean Then | |
Cls | |
Ile_znakow = 0 | |
Linia = 0 | |
Elseif Znak = Cleft Then | |
Shiftcursor Left | |
Elseif Znak = Cright Then | |
Shiftcursor Right | |
Elseif Znak = Con Then | |
Cursor On | |
Elseif Znak = Coff Then | |
Cursor Off | |
Elseif Znak = Cblink Then | |
Cursor Blink | |
Elseif Znak = Cnoblink Then | |
Cursor Noblink | |
Elseif Znak = Cupline Then | |
If Linia = 1 Then | |
Upperline | |
Linia = 0 | |
End If | |
Elseif Znak = Cdownline Then | |
If Linia = 0 Then | |
Lowerline | |
Linia = 1 | |
End If | |
Elseif Znak >= 192 And Znak <= 223 Then | |
' Locate na podstawie przekazanych parametrów | |
Locate_odebrany = 1 | |
Poz_x = Znak And &B00011110 | |
Shift Poz_x , Right | |
Linia = Znak.0 | |
Ile_znakow = Poz_x | |
Poz_x = Poz_x + 1 | |
Poz_y = Znak.0 + 1 | |
Elseif Znak > 31 And Znak < 127 Then | |
If Ile_znakow > 15 Then | |
If Linia = 0 Then | |
Linia = 1 | |
Else | |
Linia = 0 | |
End If | |
Ile_znakow = 0 | |
End If | |
Incr Ile_znakow | |
If Locate_odebrany = 1 Then | |
Locate Poz_y , Poz_x | |
Locate_odebrany = 0 | |
Else | |
Poz_y = Linia + 1 | |
Locate Poz_y , Ile_znakow | |
End If | |
Lcd Chr(znak) | |
End If | |
Loop | |
End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment