This is an old revision of the document!
Vajalikud teadmised: [HW] lcd, [LIB] Alphanumeric LCD, [LIB] Delay, [PRT] Periodic interrupt
Alphanumeric LCD is liquid crystal display, which is meant for displaying letters and numbers. In simpler LCD is used liquid crystal which is put between transparent electrodes. The crystal changes the polarization of the passing light in electrical field. The electrodes are covered by polarization filters, which make sure that only one way polarized light can pass the screen. If the liquid crystal changes its polarity due to the electrical field then the light can not pass the screen or part (segment) of it and it looks dark.
Main characteristic of alphanumerical LCD is the placing of its segments. The screen is divided into many indicators. Each indicator has either enough segments for displaying letters and numbers or it is formed from matrix of little square segments (pixels). For example, a matrix of 5×7 pixels is enough to display all numbers, and letters of Latin alphabet. There are usually 1 – 4 rows of indicators and 8 – 32 columns. Each indicator has a small difference like the letters in text have
Alphanumerical LCD has besides screen, also controller which controls the segments of the screen according to the commands from the communication interface. There is a preprogrammed card of letters in the controller, where each letter, number or symbol has its own index. Displaying the text on the screen is basically done by sending the indexes to the controller. In reality there must be more control orders sent to the controller before anything can be displayed. For using LCD-s one has to introduce their data-sheets, because there are very different LCD-s.
Alphanumerical LCD-s are usually with passive matrix, where renewal of the electrical field of the segments is tone in turns. That is why the screens with passive matrix are slower and have not so good contrast as the active matrix screens where the charge of each segment is controlled by separate transistor. There are LCD-s with reflective back and with backlight sometimes even with several different backlights. But segment colors have alphanumerical LCD-s usually still one – black usually, but there is also screens with white and colorful writings.
Kodulabori digitaalse mooduli külge ühendub 2×16 märgine alfabeetiline LCD WC1602A. Ekraani juhtimiseks on 4-bitine andmesiin ja 3 juhtviiku, kuid selle suhtlusprotokoll on liiga mahukas, et siinkohal lahti seletada. Lihtsuse huvides on ekraani kasutamiseks kodulabori teegis olemas vastavad funktsioonid.
Esimene asi, mis ekraani kasutamiseks teha tuleb, on see seadistada. Vastavaks otstarbeks on lcd_alpha_init-funktsioon, millega saab määrata ekraanile ka vilkuva kursori. Ekraanil on olenemata sellest, kas seda on näha või mitte, pidevalt üks aktiivne kursori positsioon, kuhu järgmine täht sisestatakse. Seega tuleb enne teksti sisestamist viia kursor soovitud asukohale. Kursori asukoha muutmiseks on lcd_alpha_goto_xy ja teksti kuvamiseks lcd_alpha_write_string-funktsioon. Kõik alfabeetilise LCD funktsioonid on lahti seletatud selle teegis.
Järgnev programmikood demonstreerib alfabeetilise LCD kasutamist kellana. Kellaaeg algab alates 00:00:00 ja suureneb iga sekundiga (ligikaudu). Kuna aja lugemine toimub viite funktsiooniga, siis pole see päris täpne. Ebatäpsust selgitab perioodilise katkestuse harjutus. Programm loeb sekundeid ja teisendab need arvutuste abil minutiteks ja sekunditeks. Kellaaja kujule viimiseks on kasutusel C-keele standardfunktsioon sprintf.
// // Kodulabori alfabeetilise LCD kasutamise näide. // LCD-le kuvatakse kellaaeg programmi algusest alates. // #include <stdio.h> #include <homelab/module/lcd_alpha.h> #include <homelab/delay.h> // // Põhiprogramm // int main(void) { int seconds = 0; char text[16]; // LCD ekraani seadistamine lcd_alpha_init(LCD_ALPHA_DISP_ON); // LCD ekraani puhastamine lcd_alpha_clear(); // Programmi nimi lcd_alpha_write_string("Aja loendur"); // Lõputu tsükkel while (true) { // Sekundite teisendamine kellaaja kujule // hh:mm:ss sprintf(text, "%02d:%02d:%02d", (seconds / 3600) % 24, (seconds / 60) % 60, seconds % 60); // Kellaaja teksti kuvamine LCD teise rea alguses lcd_alpha_goto_xy(0, 1); lcd_alpha_write_string(text); // Sekundi suurendamine 1 võrra seconds++; // Riistvaraline paus 1000 millisekundit hw_delay_ms(1000); } }