Next revision | Previous revision |
en:examples:display:lcd [2015/03/26 14:27] – created heikopikner | en:examples:display:lcd [2020/07/20 09:00] (current) – external edit 127.0.0.1 |
---|
~~PB~~ | <pagebreak> |
====== Ekraan ====== | ====== LCD screen ====== |
| |
//Vajalikud teadmised: | //Necessary knowledge: |
[HW] [[et:hardware:homelab:digi]], | [HW] [[en:hardware:homelab:digi]], |
[LIB] [[et:software:homelab:library:module:lcd_alphanumeric]], [LIB] [[et:software:homelab:library:module:lcd_graphic]], \\ | [LIB] [[en:software:homelab:library:module:lcd_alphanumeric]], [LIB] [[en:software:homelab:library:module:lcd_graphic]], \\ |
[LIB] [[et:software:homelab:library:delay]]// | [LIB] [[en:software:homelab:library:delay]]// |
| |
===== Teooria ===== | ===== Theory ===== |
| |
[{{ :examples:display:lcd:lcd_element.jpg?250|Graafilise LCD element}}] | [{{ :examples:display:lcd:lcd_element.jpg?250|The graphical LCD element}}] |
/*[{{ :examples:display:lcd_alphanumeric:lcd_alphanumeric_abc.png?200|Alfabeetilise LCD pikslite maatriksitest moodustatud tekst}}]*/ | /*[{{ :examples:display:lcd_alphanumeric:lcd_alphanumeric_abc.png?200|Alfabeetilise LCD pikslite maatriksitest moodustatud tekst}}]*/ |
| |
[{{ :examples:display:lcd_graphic:lcd_graphic_smiley.png?200|Graafilise LCD pikslitest moodustatud pilt}}] | [{{ :examples:display:lcd_graphic:lcd_graphic_smiley.png?200|The picture formed of pixels of a graphic LCD}}] |
| |
Mikrokontrolleritega kasutatavad LCD ekraanid võib jaotada üldistatult kaheks: teksti LCD ehk alfabeetiline LCD ja graafiline LCD. Alfabeetiline LCD on vedelkristall-ekraan (inglise keeles //liquid crystal display//), mis on ette nähtud tähtede ja numbrite kuvamiseks. Inglise keeles nimetatakse seda kui //alphanumeric// LCD. Lihtsamates vedelkristall-ekraanides kasutatakse läbipaisvate elektroodide vahele paigutatud vedelat kristalli, mis muudab elektriväljas läbiva valguse polarisatsiooni. Elektroode katavad veel polarisatsioonifiltrid, mis tagavad, et kogu ekraani saab läbida vaid ühtpidi polariseeritud valgus. Kui vedelkristall elektrivälja mõjul polarisatsiooni muudab, siis valgus ekraani või selle osa (segmenti) läbida ei saa ning see paistab tumedana. | LCD screens, which are used with microcontrollers, can be divided mainly into a two parts: a text or alphanumeric LCD and a graphic LCD. Alphanumeric LCD is liquid crystal display, with the purpose of displaying letters and numbers. In basic LCD is used liquid crystal which is placed between transparent electrodes, and which changes the polarization of the passing light in electrical field. The electrodes are covered by polarization filters, which assure that only one way polarized light can pass the screen. If the liquid crystal changes its polarity due to an electrical field, the light can not pass the screen or part (segment) of it and it looks dark. |
| |
Põhiline iseloomustaja on alfabeetilise LCD juures tema segmentide paigutus. Ekraan on jagatud paljudeks indikaatoriteks. Igal indikaatoril on kas piisavalt palju segmente tähtede ja numbrite kuvamiseks või moodustub see väikeste ruudukujuliste segmentide (pikslite) maatriksist. Näiteks 5x7 pikslisest maatriksist piisab kõigi numbrite, ladina tähestiku ja täppidega tähtede kuvamiseks. Indikaatoreid on tavaliselt 1-4 rida ja 8-32 tulpa. Igal indikaatoril on väike vahe sees, täpselt nagu tekstis tähtedelgi. | 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 similar to the differences of the letters in text. |
| |
Alfabeetiline LCD ekraan koosneb peale ekraani enda veel ka kontrollerist, mis vastavalt sideliidesest tulevatele käskudele juhib ekraani segmente. Kontrollerisse on eelnevalt sisse programmeeritud tähekaart, kus igal tähel, numbril või märgil on oma järjekorranumber ehk indeks. Ekraanil teksti kuvamine toimub põhimõtteliselt LCD kontrollerile tähtede indekseid saates. Tegelikkuses tuleb LCD kontrolleritele ka mitmeid juhtkäske saata, enne kui midagi kuvama hakatakse. Iga konkreetse LCD ekraani kasutamiseks tuleb tutvuda enne selle andmelehega, kuna neid on väga erinevaid ning ühtlasi ka nende juhtimine toimub erinevalt. | Besides the screen Alphanumerical LCD has also controller which controls the segments of the screen according to the commands from the communication interface. A controller has a preprogrammed card of letters, 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. It is important to get familiarize with each LCD data-sheet, because there are many different types of LCDs and they all are controlled differently. |
/*Alfabeetilised LCD ekraanid on üldjuhul passiivmaatriksiga, kus segmentide elektrivälja uuendamine toimub kordamööda. Sellest tulenevalt on passiivmaatriksiga ekraanid aeglasemad ja kehvema kontrastiga kui aktiivmaatriks-ekraanid, kus iga segmendi laengut juhib eraldi transistor. LCD ekraane on nii peegelduva taustaga kui taustvalgustusega, vahel isegi mitme erinevat värvi taustvalgustusega. Segmendi värve on alfabeetlistel LCD ekraanidel enamasti siiski üks - reeglina must, kuid esineb ka valge ja värvilise kirjaga ekraane. | |
*/ | |
| |
Graafiline LCD on vedelkristall-ekraan, millega saab peale teksti ka kujundeid kuvada. Selle ehitus sarnaneb alfabeetilisele LCD-le ja põhiline erinevus seisneb selles, et graafilisel ekraanil on kõik pikslid jaotatud üle ekraani ühe suure maatriksina. Kui tegu on monokromaatilise graafilise LCD ekraaniga, siis piksel on üks pisike ruudukujuline segment. Värvilistel ekraanidel moodustab üks piksel kolmest alampikslist, millest igaüks laseb läbi värvifiltri kas punast, rohelist või sinist valgust. Kuna alampikslid on lähestikku, paistavad need kui üks piksel. | Graphical LCD liquid crystal display is a display which allows displaying pictures and text. Its construction is similar to the alphanumerical LCD, with a difference that on the graphic display all pixels are divided as one large matrix. If we are dealing with a monochrome LCD, then a pixel is one square segment. Color displays’ one pixel is formed of three subpixels. Each of the three subpixels lets only one colored light pass (red, green or blue). Since the subpixels are positioned very close to each other, they seem like one pixel. |
| |
Monokromaatilised graafilised ekraanid on tavaliselt passiivmaatriksiga, suured värvilised ekraanid, kaasa arvatud arvutiekraanid, on aktiivmaatriksiga. Kogu tausta- ja pikslite värvi puudutav info on graafilistel LCD-del sarnane alfabeetiliste LCD omadustega ja sarnaselt alfabeetiliste ekraanidega on ka graafilistel ekraanidel eraldi kontroller, mis hoolitseb sideliidese kaudu info vastuvõtmise ja segmentide elektrivälja tekitamise eest. | Monochrome graphic displays have usually passive matrix, large color displays including computer screens have active matrix. All information concerning the color of the background and the pixels of the graphic LCDs are similar to alphanumerical LCDs. Similar to the alphanumerical displays, graphic displays are also equipped with separate controller, which takes care of receiving information through the communication interface and generates the electrical field for the segments. |
| |
===== Praktika ===== | |
| |
Kodulabori III seeria Kasutajaliidese moodulile on paigaldatud 128 x 160 piksliga 1,8 tolline täisvärviline TFT LCD ekraan. Ekraani juhib Sitronixi ST7735 LCD kontroller, mida juhtakse üle SPI siini. Lisaks on juhitav ekraani taustavalgus, kuid ilma taustavalguseta ei ole võimalik ekraani kasutada. Ekraaniga suhtlemine pole kuigi keeruline, kuid funktsioonide suure arvu tõttu pole siinkohal seda lahti seletatud. Kodulabori teegis on olemas funktsioonid selle kasutamiseks. | ===== Practice ===== |
| |
Erinevalt Kodulabor III-st on Kodulabor II varustatud monokromaatilise graafilise 84 x 48 piksli LCD ekraaniga, mis on tundud ka vanemate Nokia mobiiltelefonide pealt. Ekraani küljes on Philipsi PCD8544 kontroller, millega saab suhelda läbi SPI-taolise järjestikliidese. Eraldi juhitav on veel ekraanimooduli taustvalgustus. | In the HomeLab III set is a 128×160 pixels and 1,8 inch full color TFT LCD screen. Sitronixi ST7735 controller is attached to the display which can be communicated through SPI serial interface. The background lighting of the display module is separately controlled, but without the background light, it is not possible to use the screen. Communicating with the display is not very difficult, but due to the large amount of the functions it is not explained here. Home-Labs library has functions for using it. |
| |
Graafilise LCD kasutamiseks tuleb esmalt ekraan algväärtustada funktsiooniga //lcd_gfx_init//. Teeki on sisse kirjutatud tähekaart kogu ladina tähestiku, numbrite ja üldkasutatavate märkidega. Tähe või teksti kuvamiseks tuleb eelnevalt //lcd_gfx_goto_char_xy// funktsiooniga määrata selle asukoht. Tähe kuvamiseks on //lcd_gfx_write_char// ja teksti kuvamiseks //lcd_gfx_write_string// funktsioon. Muid funktsioone näeb juba teegi dokumentatsioonist. Järgnevalt on toodud näide aja loenduri kohta. Programm loendab sekundeid (ligikaudu), minuteid ja tunde. Aja tekstiks teisendamiseks on kasutusel //sprintf// funktsioon. | Main difference compared to from HomeLab III to HomeLab II is a 84×48 pixels monochrome graphic LCD. It is the same display as used in Nokia 3310 mobile phones. Philips PCD8544 controller is attached to the display which can be communicated through SPI-like serial interface. The background lighting of the display module is separately controlled. |
| |
| First, the graphical LCD screen must be started with //lcd_gfx_init// function. There is a letter map in side of the library with full Latin alphabet, numbers and with most common signs written. To display a letter or text, first its position must be determined by using function //lcd_gfx_goto_char_xy//. For displaying s letter is //lcd_gfx_write_char// function and for displaying text //lcd_gfx_write_string// function. |
| |
| The following is an example of time counter. The program counts seconds (approximately), minutes and hours. For converting time to text sprintf function is used. |
| |
<code c> | <code c> |
// Kodulabori graafilise LCD kasutamise näide | // Example of using the graphic LCD of the HomeLab |
| // Time of day is displayed on LCD since the beginning of the program |
#include <stdio.h> | #include <stdio.h> |
#include <homelab/module/lcd_gfx.h> | #include <homelab/module/lcd_gfx.h> |
#include <homelab/delay.h> | #include <homelab/delay.h> |
| |
// Põhiprogramm | // Main program |
int main(void) | int main(void) |
{ | { |
int seconds = 0; | int seconds = 0; |
char text[16]; | char text[16]; |
| |
// LCD ekraani algseadistamine | // Set-up of the LCD |
lcd_gfx_init(); | lcd_gfx_init(); |
// Ekraani puhastamine | |
lcd_gfx_clear(); | |
// Taustavalgustuse tööle lülitamine | |
lcd_gfx_backlight(true); | |
// Programmi nime kuvamine | |
lcd_gfx_goto_char_xy(1, 1); | |
lcd_gfx_write_string("Aja loendur"); | |
| |
// Lõputu tsükkel | // Cleaning the screen |
while (1) { | lcd_gfx_clear(); |
// Sekundite teisendamine kellaaja kujule hh:mm:ss | |
sprintf(text, "%02d:%02d:%02d", | |
(seconds / 3600) % 24, (seconds / 60) % 60, seconds % 60); | |
| |
// Kellaaja teksti kuvamine | // Switching on the background light |
lcd_gfx_goto_char_xy(3, 3); | lcd_gfx_backlight(true); |
lcd_gfx_write_string(text); | |
| // Displaying the name of the program |
| lcd_gfx_goto_char_xy(1, 1); |
| lcd_gfx_write_string("Time counter"); |
| |
| // Endless loop |
| while (true) |
| { |
| // Converting the seconds to the form of clock |
| // hh:mm:ss |
| sprintf(text, "%02d:%02d:%02d", |
| (seconds / 3600) % 24, |
| (seconds / 60) % 60, |
| seconds % 60); |
| |
| // Displaying the clock text |
| lcd_gfx_goto_char_xy(3, 3); |
| lcd_gfx_write_string(text); |
| |
| // Adding one second |
| seconds++; |
| |
// Sekundi suurendamine 1 võrra | // Hardware delay for 1000 ms |
seconds++; | hw_delay_ms(1000); |
// Riistvaraline paus 1000 millisekundit | } |
hw_delay_ms(1000); | |
} | |
} | } |
</code> | </code> |