Uživatel:Borskmic

Z MAM wiki

Přejít na: navigace, hledání

Obsah

[editovat] Samostatná práca

Trieda funkcí pre ovládanie grafického LCD displeja. Spolupracujem s Martinem Zoubkem

[editovat] Zadanie

Vytvorte triedu funkcí pre ovládanie grafického LCD dipleja. Môžete vymyslieť funkcie pre kreslenie čiar, oblúkov a následne pekných okienok s textom, výpisom znakov rôzných veľkostí fontov, rezov atď....

[editovat] Hardware

Táto samostatná práca vznikla ako podklad pre ovládanie grafického displeja bez nejakej náväznosti na konkrétny HW. Preto sú aj všetky grafické funckie na HW nezávislé a je možné ich použiť aj pre iný displej. Jediným obmedzením je počet pixelov displeja a veľkosť RAM mikropočítača, keď zhruba platí, že veľkosť RAM v bytoch sa rovná počtu pixelov/4.

[editovat] Spôsob vykreslenia

Soubor:LCD_BZ.png


Pri navrhnovní fcí sa vychádzalo z nasledujúceho predpokladu. LCD diplej má rozmery (w x h), a je ďalej rozdelený do "z" stránok. Jedna stránka preto predstavuje časť z celého displeja o rozmeroch (w x h/z), kde "w" predstavuje počet vektorov na stránku a h/z = 8. Každý vektor má potom rozmery 1x8, z toho vyplýva, že 1 vektor = 1B. Obrázok je teda definovaný ako postupnosť vektorov s jednotkami na odpovedajúcich bitových miestach, ktoré sa majú vykresliť. Počet vektorov v postupnosti určuje velkosť obrázku. Pri zapisovaní nieje nutné vždy začínať od začiatku, ale pri je možné si vybrať počiatočný bod.

[editovat] Program

[editovat] Zoznam použitých funkcí

Celý program je vytvorený použitím niekoľkých funkcí, ktoré sa všeoboecne dajú rozdeliť do troch kategórii

  1. funkcie pre ovládanie displeja
  2. funkcie pre zápis do pamäti MPC
  3. funkcie pre zápis z pamäti MPC na displej
void LCDInit(void);                  - inicializácia displeja a jeho nastavení
void LCDClearScreen(void);           - vymazanie displeja
void LCDClearBuf(void);              - vymazanie bufferu displeja

void Delay10TCYx(unsigned int temp); - delay pri zápise na displej
void LCDWriteALL(void);              - prepis z RAM mikropočítača na dispej
void LCDWriteCMD(unsigned int);      - mapovanie bitovej postupnosti na porty MPC pre paralelný zápis
void LCDWriteDAT(unsigned int);      - mapovanie bitovej postupnosti na porty MPC pre paralelný zápis

void printImage(unsigned int startRow, unsigned int startCol, unsigned int width, unsigned int height, unsigned char* buffer); - umiestnenie obrázku na diplej
void printLine(unsigned int y1, unsigned int x1, unsigned int y2, unsigned int x2, unsigned int widthImage)                    - vytvorenie úsečky
void printText(unsigned int startRow, unsigned int startCol, unsigned char numChar, unsigned char font);                       - vytvorenie súvislého textu
void printRect(unsigned int startRow, unsigned int startCol, unsigned int width, unsigned int height, unsigned int widthLine); - vytvorenie obdĺžnika s rozmermi (width x height) a širkou čiar (widthLine)
void printFullRect(unsigned int startRow, unsigned int startCol, unsigned int width, unsigned int height);                     - vytvorenie vyplneného obdĺžnika s rozmermi (width x height)

[editovat] Základné grafické objekty

Pre prácu s displejom boli vyvorené objekty, ktoré reprezentujú základné grafické elementy. Sú to logá firmy Microchip a Mikromarz, 2 sady alfanumerických a špeciálnych znakov a úsečka. Až na úsečku sú všetky vložené do pamäti MPC ako konštanty. Pomenovanie základné dostali preto, lebo slúžia ako podklad pre vyvorenie žložitejšich objektov ako text alebo obdĺžnik.

logo Microchip

const unsigned char image2[]={                            
0x00,0x00,0x00,0x80,0xE0,0xF0,0xF0,0xF8,0xFC,0xFC,0x7E,0x7E,0x7E,0xFE,0xFF,0xFF,
0xFF,0xFF,0xFE,0xFE,0x7E,0x7E,0x7C,0xF0,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0xE0,0xFC,0xFF,0xFF,0x7F,0x3F,0x7F,0xE7,0x83,0x00,0x00,0x00,0x00,0x01,0x03,0x0F,
0x3F,0x7F,0xE3,0x81,0x00,0x00,0x00,0x00,0x01,0x07,0x1F,0x3C,0xF8,0xE0,0xC0,0x00,
0x07,0x07,0x03,0x00,0x00,0x00,0x00,0x81,0xC3,0xEF,0xFC,0xF8,0xF0,0xC0,0x00,0x00,
0x00,0x00,0x81,0xE7,0xFF,0xFC,0xF0,0xE0,0x80,0x00,0x00,0x00,0x00,0x01,0x07,0x07,
0x00,0x00,0x00,0x00,0x04,0x0C,0x0E,0x1F,0x3F,0x3F,0x7F,0x7F,0x7F,0x7F,0xFF,0xFE,
0xFE,0xFF,0x7F,0x7F,0x7F,0x7F,0x3F,0x3F,0x1F,0x0F,0x0C,0x04,0x00,0x00,0x00,0x00};


logo Mikromarz

	
const unsigned char image[]={                            
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xC0,0xE0,
0xE0,0xF0,0xF0,0xF8,0xF8,0xFC,0xFC,0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,0xFE,0xFC,0xF8,0xF8,0xF0,0xF0,0xF0,0xE0,0xE0,0xC0,
0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,
0x60,0xF0,0xF0,0xF8,0xF8,0xFC,0xFC,0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x0F,0x00,0xC0,0x03,0x1F,0x07,0xC0,0x00,0x07,0xFF,0xFF,0x04,0x04,0xFF,0xFF,0x00,
0x00,0x9F,0x0F,0x67,0xF7,0x0F,0x07,0xC7,0xE7,0xC7,0xC7,0x1F,0x0F,0xC7,0xE7,0x47,
0x0F,0x9F,0x0F,0x07,0xC7,0xE7,0x07,0x07,0xE7,0x87,0x07,0x7F,0x1F,0x0F,0xC7,0xE7,
0x07,0x07,0xFF,0x0F,0x07,0xC7,0xE7,0xC7,0xC7,0xFF,0xE7,0x67,0x27,0x87,0xC7,0xF7,
0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,0xFC,0xFC,0xF8,0xF8,0xF8,0xF0,0xE0,0xE0,0xC0,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xD0,0xF8,0x18,0xCC,0xFF,0x01,
0x00,0x00,0x01,0x01,0x03,0x03,0x07,0x07,0x0F,0x0F,0x1F,0x1F,0x3F,0x3F,0x7F,0x7C,
0xFC,0xFF,0xFF,0xFC,0xFC,0xFE,0xFF,0xFF,0xFC,0xFC,0xFF,0xFC,0xFC,0xFF,0xFF,0xFC,
0xFE,0xFF,0xFE,0xFC,0xFC,0xFC,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFC,0xFC,0xFC,
0xFE,0xFF,0xFE,0xFC,0xFF,0xFF,0xFC,0xFC,0xFF,0xFF,0xFC,0xFC,0xFF,0xFC,0xFC,0xFC,
0xFC,0xFC,0xFC,0xFC,0xFC,0xFF,0xFF,0xFF,0xFF,0xFD,0xFC,0xFC,0xFC,0xFC,0xFC,0x7F,
0x7F,0x3F,0x3F,0x1F,0x1F,0x0F,0x0F,0x07,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0xFF,
0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x02,0x0F,0x1B,0x16,0x34,0x2C,0x27,0x30,0x3F,0xFF,0x0D,
0x0B,0x1A,0x16,0x34,0x2C,0x68,0x58,0xD0,0xB0,0xA0,0x60,0x40,0xC0,0x80,0x80,0x00,
0x00,0x00,0x01,0x01,0x03,0x03,0x07,0x07,0x0F,0x0F,0x1F,0x1F,0x3F,0x3F,0x7F,0x7F,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x9F,0x1F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x1F,0x1F,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,
0x7F,0x3F,0x3F,0x1F,0x1F,0x0F,0x0F,0x07,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0x00,
0x80,0x80,0xC0,0x40,0x60,0xA0,0xB0,0xF0,0xF8,0xB8,0xAC,0x64,0xC6,0x8E,0x0B,0x1D,
0x3F,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x07,
0x0C,0x08,0x18,0x30,0x30,0x20,0x60,0x40,0xC0,0x81,0x81,0x03,0x02,0x06,0x05,0x0D,
0x0B,0x1A,0x16,0x34,0x2C,0x68,0x58,0xD0,0xB0,0xA0,0x60,0x40,0xC0,0x80,0x80,0x00,
0x00,0x00,0x01,0x01,0x03,0x03,0x07,0x07,0x0F,0x0F,0x1F,0x1F,0x3F,0x3E,0x7E,0xFE,
0x7E,0x3E,0x3F,0x1F,0x1F,0x0F,0x0F,0x07,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0x00,
0x80,0x80,0xC0,0x40,0x60,0xE0,0xB0,0xD0,0x58,0x68,0x2C,0x3C,0x36,0x2E,0x6B,0xD9,
0xB1,0x63,0xC2,0x07,0x0D,0x19,0xF0,0xC0,0x60,0x20,0x31,0x13,0xFE,0x03,0xFE,0xC0,
0x00,0x00,0x7F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x02,0x06,0x04,
0x0C,0x08,0x18,0x30,0x30,0x20,0x60,0x40,0xC0,0x81,0x81,0x03,0x02,0x06,0x05,0x0D,
0x0B,0x1A,0x16,0x34,0x2C,0x68,0x58,0xD0,0xB0,0xA0,0x60,0x40,0xC0,0x80,0x80,0xFF,
0x80,0x80,0xC0,0xC0,0xE0,0xE0,0xB0,0x90,0x18,0x38,0x2C,0x74,0x56,0x9A,0x0B,0x0F,
0x0F,0x0B,0x1A,0x36,0xEC,0x18,0xF0,0x01,0x01,0x06,0xFC,0xF0,0x18,0x08,0x0C,0x04,
0x7F,0xE0,0x7F,0xF8,0x80,0x00,0x1F,0x3F,0x60,0x40,0x80,0x80,0x01,0x07,0x0D,0x13,
0x36,0x2C,0x6C,0x78,0x79,0x69,0x26,0x3E,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x06,0x06,0x0C,
0x0C,0x18,0x18,0x30,0x30,0x20,0x60,0xC0,0xC0,0x81,0x81,0x03,0x02,0x06,0x05,0xFF,
0x05,0x06,0x02,0x03,0x83,0x82,0xC6,0x45,0xFB,0x86,0xFC,0xE0,0x00,0x01,0x7F,0xFC,
0x06,0x02,0x03,0x01,0x0F,0x7E,0xCF,0xBF,0x60,0x40,0x83,0x8F,0x98,0x90,0xF0,0x60,
0xC0,0x01,0x03,0x06,0x0D,0x09,0x1A,0x1E,0x1E,0x1A,0x09,0x0F,0x07,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x02,0x02,0x06,0x07,
0x06,0x02,0x03,0x03,0x01,0x00,0x00,0x00,0x03,0x1F,0x32,0x6F,0x58,0xD0,0xB0,0xE3,
0xE6,0xA4,0xBC,0xD8,0x78,0x00,0x00,0x01,0x03,0x02,0x06,0x07,0x07,0x06,0x02,0x03,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};	

Znaková sada "0" s rozmermi 5x8 (Písmená, čísla, interpunkcia, matematické operátory a mnoho ďaľšieho)

const unsigned char charSet0[]={
0x00,0x00,0x00,0x00,0x00,			//blank char 
0x00,0x00,0x3F,0x00,0x00,			//!
0x00,0x07,0x00,0x07,0x00,			//"
0x14,0x7F,0x14,0x7F,0x14,			//#
0x24,0x2A,0x3F,0x2A,0x12,			//$
0x23,0x13,0x08,0x64,0x62,			//%
0x36,0x49,0x55,0x22,0x50,			//&
0x00,0x04,0x03,0x00,0x00,			//'
0x00,0x1C,0x22,0x71,0x00,			//(
0x00,0x71,0x22,0x1C,0x00,			//)
0x0A,0x04,0x1F,0x04,0x0A,			//*
0x08,0x08,0x3E,0x08,0x08,			//+
0x00,0x40,0x03,0x00,0x00,			//,
0x08,0x08,0x08,0x08,0x08,			//-
0x00,0x00,0x40,0x00,0x00,			//.
0x20,0x10,0x08,0x04,0x02,			///
0x3E,0x51,0x49,0x45,0x3E,		  	//0			 
0x00,0x42,0x7F,0x40,0x00,		  	//1			 
0x42,0x61,0x51,0x49,0x46,		  	//2			 
0x21,0x41,0x45,0x4B,0x31,		 	//3			 
0x18,0x14,0x12,0x7F,0x10,			//4			 
0x27,0x45,0x45,0x45,0x39,			//5			 
0x3C,0x4A,0x49,0x49,0x30,			//6			 
0x01,0x71,0x09,0x05,0x03,			//7			 
0x36,0x49,0x49,0x49,0x36,			//8			 
0x06,0x49,0x49,0x29,0x1E,			//9
0x00,0x00,0x24,0x00,0x00,			//:
0x00,0x40,0x34,0x00,0x00,			//;
0x08,0x14,0x22,0x41,0x00,			//<
0x14,0x14,0x14,0x14,0x14,			//=
0x00,0x41,0x22,0x14,0x08,			//>
0x02,0x01,0x51,0x09,0x06,			//?
0x32,0x49,0x79,0x41,0x3E,			//@						 
0x7E,0x11,0x11,0x11,0x7E,			//A			 
0x7F,0x49,0x49,0x49,0x36,			//B			 
0x3E,0x41,0x41,0x41,0x22,			//C			 
0x7F,0x41,0x41,0x22,0x1C,			//D			 
0x7F,0x49,0x49,0x49,0x41,			//E			 
0x7F,0x09,0x09,0x09,0x01,			//F			 
0x3E,0x41,0x49,0x49,0x7A,			//G			 
0x7F,0x08,0x08,0x08,0x7F,			//H			 
0x00,0x41,0x7F,0x41,0x00,			//I			 
0x20,0x40,0x41,0x3F,0x01,			//J			 
0x7F,0x08,0x14,0x22,0x41,			//K			 
0x7F,0x40,0x40,0x40,0x40,			//L			 
0x7F,0x02,0x0C,0x02,0x7F,			//M			 
0x7F,0x04,0x08,0x10,0x7F,			//N			 
0x3E,0x41,0x41,0x41,0x3E,			//O			 
0x7F,0x09,0x09,0x09,0x06,			//P			 
0x3E,0x41,0x51,0x21,0x5E,			//Q			 
0x7F,0x09,0x19,0x29,0x46,			//R			 
0x46,0x49,0x49,0x49,0x31,			//S			 
0x01,0x01,0x7F,0x01,0x01,			//T			 
0x3F,0x40,0x40,0x40,0x3F,			//U			 
0x1F,0x20,0x40,0x20,0x1F,			//V			 
0x3F,0x40,0x38,0x40,0x3F,			//W			 
0x63,0x14,0x08,0x14,0x63,			//X			 
0x07,0x08,0x70,0x08,0x07,			//Y			 
0x61,0x51,0x49,0x45,0x43,			//Z			 
0x00,0x7F,0x41,0x41,0x00,			//[	
0x02,0x04,0x08,0x10,0x20,			//backslash	
0x00,0x41,0x41,0x7F,0x00,			//]	
0x04,0x02,0x01,0x02,0x04,			//^	
0x04,0x00,0x04,0x00,0x04,			//...	
0x00,0x01,0x02,0x04,0x00};			//zpetna carka nahore				 		

Znaková sada "1" s rozmermi 10x16 (Písmená, čísla, interpunkcia, matematické operátory a mnoho ďaľšieho)

	
const unsigned char charSet1[]={
0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,			//blank char
0x00,0x00,0x00,0x00,0xFF, 0xFF,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x30, 0x30,0x00,0x00,0x00,0x00,			//!
0x00,0x00,0x3F,0x3F,0x00, 0x00,0x3F,0x3F,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,			//"
0x30,0x30,0xFF,0xFF,0x30, 0x30,0xFF,0xFF,0x30,0x30, 0x03,0x03,0x3F,0x3F,0x03, 0x03,0x3F,0x3F,0x03,0x03,			//#
0x30,0x78,0xFC,0xCC,0xFF, 0xFF,0xCC,0xCC,0xCC,0x00, 0x00,0x0C,0x0C,0x0C,0x3F, 0x3F,0xC0,0x0F,0x07,0x03,			//$
0x0E,0x1F,0x1B,0x9F,0xCE, 0xE0,0x70,0x38,0x1C,0x0C, 0x0C,0x0E,0x07,0x03,0x01, 0x1C,0x3E,0x36,0x3E,0x1C,			//%
0x3C,0xFE,0xE7,0xE3,0xF3, 0x3F,0x1E,0x0C,0x00,0x00, 0x0F,0x1F,0x39,0x31,0x33, 0x3F,0x1E,0x1F,0x3B,0x31,			//&
0x00,0x00,0x30,0x31,0x1F, 0x0F,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,			//'
0x00,0x00,0xE0,0xF8,0x3C, 0x0E,0x07,0x03,0x00,0x00, 0x00,0x00,0x01,0x07,0x0F, 0x1C,0x38,0x30,0x00,0x00,			//(
0x00,0x00,0x03,0x07,0x0E, 0x3C,0xF8,0xE0,0x00,0x00, 0x00,0x00,0x30,0x38,0x1C, 0x0F,0x07,0x01,0x00,0x00,			//)
0x84,0xCC,0x48,0x30,0xFF, 0xFF,0x30,0x48,0xCC,0x84, 0x00,0x00,0x00,0x00,0x03, 0x03,0x00,0x00,0x00,0x00,			//*
0xC0,0xC0,0xC0,0xC0,0xFC, 0xFC,0xC0,0xC0,0xC0,0xC0, 0x00,0x00,0x00,0x00,0x0F, 0x0F,0x00,0x00,0x00,0x00,			//+
0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x30,0x38,0x1F, 0x0F,0x00,0x00,0x00,0x00,			//,
0xC0,0xC0,0xC0,0xC0,0xC0, 0xC0,0xC0,0xC0,0xC0,0xC0, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,			//-
0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x30, 0x30,0x00,0x00,0x00,0x00,			//.
0x00,0x00,0x00,0x80,0xC0, 0xE0,0x70,0x38,0x1C,0x0C, 0x0C,0x0E,0x07,0x03,0x01, 0x00,0x00,0x00,0x00,0x00,			///
0xF8,0xFE,0x07,0x83,0xC3, 0xE3,0x73,0x3F,0xFE,0xF8, 0x07,0x1F,0x3F,0x33,0x31, 0x30,0x30,0x38,0x1F,0x07,		  	//0			 
0x00,0x00,0x0C,0x0E,0xFF, 0xFF,0x00,0x00,0x00,0x00, 0x00,0x00,0x30,0x30,0x3F, 0x3F,0x30,0x30,0x00,0x00,	  		//1			 
0x0C,0x0E,0x07,0x03,0x03, 0x83,0xC3,0xE7,0x7E,0x3C, 0x30,0x38,0x3C,0x3E,0x37, 0x33,0x31,0x30,0x30,0x30,			//2			 
0x00,0x03,0x03,0x63,0x73, 0xFB,0xDF,0xCF,0x87,0x03, 0x0C,0x1C,0x38,0x30,0x30, 0x30,0x30,0x39,0x1F,0x0F,			//3			 
0xC0,0xE0,0x70,0x38,0x1C, 0x0E,0xFF,0xFF,0x00,0x00, 0x03,0x03,0x03,0x03,0x03, 0x03,0x3F,0x3F,0x03,0x00,			//4			
0x7F,0x7F,0x63,0x63,0x63, 0x63,0x63,0xE3,0xC3,0x80, 0x0C,0x1C,0x38,0x30,0x30, 0x30,0x30,0x38,0x1F,0x1F,			//5			
0xF0,0xFC,0x8E,0xC7,0xC3, 0xC3,0xC3,0xC6,0x86,0x00, 0x0F,0x1F,0x39,0x30,0x30, 0x30,0x30,0x39,0x1F,0x0F,			//6			 
0x03,0x03,0x03,0x03,0xC3, 0xE3,0x73,0x3B,0x1F,0x0F, 0x00,0x00,0x3C,0x3F,0x07, 0x01,0x00,0x00,0x00,0x00,			//7			 
0x3C,0xFE,0xE7,0xC3,0xC3, 0xC3,0xC3,0xE7,0xFE,0x3C, 0x0F,0x1F,0x39,0x30,0x30, 0x30,0x30,0x39,0x1F,0x0F,			//8			
0x3C,0x7E,0xE7,0xC3,0xC3, 0xC3,0xC3,0xE7,0xFE,0xFC, 0x00,0x18,0x18,0x30,0x30, 0x30,0x38,0x1C,0x0F,0x03,			//9			 
0x00,0x00,0x00,0x00,0x30, 0x30,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x0C, 0x0C,0x00,0x00,0x00,0x00,			//:		
0x00,0x00,0x00,0x00,0x60, 0x60,0x00,0x00,0x00,0x00, 0x00,0x08,0x60,0x70,0x3E, 0x1E,0x00,0x00,0x00,0x00,			//;
0xC0,0xE0,0xF0,0x38,0x1C, 0x0E,0x07,0x03,0x00,0x00, 0x00,0x01,0x03,0x07,0xE0, 0x1C,0x38,0x30,0x00,0x00,			//<
0x30,0x30,0x30,0x30,0x30, 0x30,0x30,0x30,0x30,0x30, 0x03,0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03,0x03,			//=
0x00,0x00,0x03,0x07,0x0E, 0x1C,0x38,0xF0,0xE0,0xC0, 0x00,0x00,0x30,0x38,0x1C, 0x0E,0x07,0x03,0x01,0x00,			//>
0x0C,0x0E,0x07,0x03,0x03, 0x83,0xC3,0xE7,0x7E,0x3C, 0x00,0x00,0x00,0x00,0x33, 0x33,0x01,0x00,0x00,0x00,			//?
0xC0,0xF8,0x1C,0xCC,0xE6, 0x26,0x66,0xCC,0xF1,0xF0, 0x01,0x07,0x0E,0x08,0x19, 0x1B,0x1B,0x09,0x0D,0x05,			//@
0xF0,0xFC,0x1E,0x07,0x03, 0x03,0x07,0x1E,0xFC,0xF0, 0x3F,0x3F,0x03,0x03,0x03, 0x03,0x03,0x03,0x3F,0x3F,			//A
0xFF,0xFF,0xC3,0xC3,0xC3, 0xC3,0xC3,0xE7,0xFE,0x3C, 0x3F,0x3F,0x30,0x30,0x30, 0x30,0x30,0x39,0x1F,0x0F,			//B
0xF8,0xFE,0x07,0x03,0x03, 0x03,0x03,0x07,0x0E,0x0C, 0x07,0x1F,0x38,0x30,0x30, 0x30,0x30,0x38,0x1C,0x0C,			//C
0xFF,0xFF,0x03,0x03,0x03, 0x07,0x0E,0x1C,0xF8,0xE0, 0xFF,0xFF,0x30,0x30,0x30, 0x38,0x1C,0x0E,0x07,0x01,			//D
0xFF,0xFF,0xC3,0xC3,0xC3, 0xC3,0xC3,0xC3,0x03,0x03, 0x3F,0x3F,0x30,0x30,0x30, 0x30,0x30,0x30,0x30,0x30,			//E
0xFF,0xFF,0xC3,0xC3,0xC3, 0xC3,0xC3,0xC3,0x03,0x03, 0x3F,0x3F,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,			//F
0xFC,0xFE,0x07,0x03,0xC3, 0xC3,0xC3,0xC7,0xCE,0xCC, 0x0F,0x1F,0x38,0x30,0x30, 0x30,0x30,0x38,0x1F,0x1F,			//G
0xFF,0xFF,0xC0,0xC0,0xC0, 0xC0,0xC0,0xC0,0xFF,0xFF, 0x3F,0x3F,0x00,0x00,0x00, 0x00,0x00,0x00,0x3F,0x3F,			//H
0x00,0x00,0x03,0x03,0xFF, 0xFF,0x03,0x03,0x00,0x00, 0x00,0x00,0x30,0x30,0x3F, 0x3F,0x30,0x30,0x00,0x00,			//I
0x00,0x00,0x00,0x00,0x03, 0x03,0xFF,0xFF,0x03,0x03, 0x0C,0x1C,0x38,0x30,0x30, 0x38,0x1F,0x0F,0x00,0x00,			//J
0xFF,0xFF,0xC0,0xE0,0xB0, 0x38,0x1C,0x0E,0x07,0x03, 0xFF,0xFF,0x00,0x01,0x03, 0x07,0x0E,0x1C,0x38,0x30,			//K
0xFF,0xFF,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0xFF,0xFF,0x30,0x30,0x30, 0x30,0x30,0x30,0x30,0x30,			//L
0xFF,0xFF,0x1E,0x3C,0xF8, 0xF8,0x3C,0x1E,0xFF,0xFF, 0xFF,0xFF,0x00,0x00,0x00, 0x00,0x00,0x00,0xFF,0xFF,			//M
0xFF,0xFF,0x3C,0x70,0xE0, 0xC0,0x80,0x00,0xFF,0xFF, 0xFF,0xFF,0x00,0x00,0x00, 0x01,0x03,0x0F,0x3F,0x3F,			//N
0xF8,0xFE,0x07,0x03,0x03, 0x03,0x03,0x07,0xFE,0xF8, 0x07,0x1F,0x38,0x30,0x30, 0x30,0x30,0x38,0x1F,0x07,			//O
0xFF,0xFF,0xC3,0xC3,0xC3, 0xC3,0xC3,0xE7,0x7E,0x3C, 0xFF,0xFF,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,			//P
0xF8,0xFE,0x07,0x03,0x03, 0x03,0x03,0x07,0xFE,0xF8, 0x07,0x1F,0x38,0x30,0x33, 0x37,0x1E,0x1C,0x3F,0x33,			//Q
0xFF,0xFF,0xC3,0xC3,0xC3, 0xC3,0xC3,0xE7,0x7E,0x3C, 0xFF,0xFF,0x00,0x01,0x03, 0x07,0x0E,0x1C,0x38,0x30,			//R
0x3C,0x7E,0xC7,0xC3,0xC3, 0xC3,0xC3,0xC7,0x86,0x00, 0x18,0x38,0x30,0x30,0x30, 0x30,0x30,0x38,0x1F,0x0F,			//S
0x03,0x03,0x03,0x03,0xFF, 0xFF,0x03,0x03,0x03,0x03, 0x00,0x00,0x00,0x00,0xFF, 0xFF,0x00,0x00,0x00,0x00,			//T
0xFF,0xFF,0x00,0x00,0x00, 0x00,0x00,0x00,0xFF,0xFF, 0x07,0x1F,0x38,0x30,0x30, 0x30,0x30,0x38,0x1F,0x07,			//U
0x3F,0xFF,0xE0,0x00,0x00, 0x00,0x00,0xE0,0xFF,0x3F, 0x00,0x01,0x07,0x1F,0x38, 0x38,0x1F,0x07,0x01,0x00,			//V
0xFF,0xFF,0x00,0x00,0xC0, 0xC0,0x00,0x00,0xFF,0xFF, 0x07,0x1F,0x3E,0x38,0x1F, 0x1F,0x38,0x3E,0x1F,0x07,			//W
0x07,0x1F,0x3C,0xF0,0xE0, 0xE0,0xF0,0x3C,0x1F,0x07, 0x38,0x3E,0x0F,0x03,0x01, 0x01,0x03,0x0F,0x3E,0x38,			//X
0x07,0x1F,0x7C,0xF0,0xC0, 0xC0,0xF0,0x7C,0x1F,0x07, 0x00,0x00,0x00,0x00,0x3F, 0x3F,0x00,0x00,0x00,0x00,			//Y
0x03,0x03,0x03,0x83,0xC3, 0xE3,0x73,0x3B,0x1F,0x0F, 0x3C,0x3E,0x37,0x33,0x31, 0x30,0x30,0x30,0x30,0x30,			//Z
0x00,0x00,0xFF,0xFF,0x03, 0x03,0x03,0x03,0x00,0x00, 0x00,0x00,0xFF,0xFF,0x30, 0x30,0x30,0x30,0x00,0x00,			//[
0x0C,0x1C,0x38,0x70,0xE0, 0xC0,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x01,0x03,0x07,0x0E,0x0C,			//backslash	
0x30,0x38,0x1C,0x0E,0x07, 0x07,0x0E,0x1C,0x38,0x30, 0x00,0x08,0x60,0x70,0x3E, 0x1E,0x00,0x00,0x00,0x00,			//^
0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x30,0x30,0x00,0x00,0x30, 0x30,0x00,0x00,0x30,0x30,			//...
0x00,0x00,0x03,0x07,0x0E, 0x1C,0x38,0x30,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00};		//zpetna carka nahore

Úsečka

/********************************************************************
 * Function:		void printLine(unsigned int y1, unsigned int x1, unsigned int y2, unsigned int x2, unsigned int widthImage)
 * PreCondition:   
 * Input:          
 * Output:        
 * Side Effects:   
 * Overview:       
 * Note:           
 *******************************************************************/
void printLine(unsigned int y1, unsigned int x1, unsigned int y2, unsigned int x2, unsigned int widthImage)
{

unsigned int g;
unsigned int h;
unsigned int i;
unsigned int j;


unsigned int dy;
unsigned int dx;

unsigned long x;
unsigned long y;


unsigned int temp;

unsigned long dxy;

unsigned char numBit;
unsigned char numPage;


dx=x2-x1;
dy=y2-y1;


	//kdyz se tiskne bod
	if((dx==dy)&&(dx==0))
	{
		y=y1;
		x=x1;
		numPage=y>>3;
		numBit=0x01<<(y&0x07);
		LCDObject[numPage*128+x]|=numBit;
	}
	//kdyz se tiskne usecka
	else
	{
		//kdyz je vetsi prumet do osy x
		if(dx>=dy) 
		{ 
			dxy=(dy*1000)/dx;

			for(i=0;i<=dx;i++)
			{

				y=(i*dxy)/1000+y1;
				x=i+x1;
				numPage=y>>3;
				numBit=0x01<<(y&0x07);

				LCDObject[numPage*widthImage+x]|=numBit;
		
			}

		}
		//kdyz je vetsi prumet do osy y
		else 
		{
			dxy=(dx*1000)/dy;
			for(i=0;i<=dy;i++)
			{

				x=(i*dxy)/1000+x1;
				y=i+y1;
				numPage=y>>3;
				numBit=0x01<<(y&0x07);

				LCDObject[numPage*widthImage+x]|=numBit;
		
			}


		}
	}

}

[editovat] Zložitejšie grafické objekty

Zložitejšie grafické objekty vzniknú rozšírením niektorého zo základných grafických objektov. Súvislý text je vytvorený ako konkatenácia základných alfanumerických a špeciálnych znakov definovaných v charSet0 alebo charSet1 pomocou funkcie printText. Veľba veľkosti fontu pr eužívateľa znamená výber medzi týmito dvoma sadami.

/********************************************************************
 * Function:		void printText(unsigned int startRow, unsigned int startCol, unsigned char numChar, unsigned char font)
 * PreCondition:   
 * Input:          
 * Output:        
 * Side Effects:   
 * Overview:       
 * Note:           
 *******************************************************************/
void printText(unsigned int startRow, unsigned int startCol, unsigned char numChar, unsigned char font)
{

unsigned int g;
unsigned int h;
unsigned int i;
unsigned int j;


#define offsetChar	0x20

	for(j=0;j<numChar;j++) LCDText[j]-=offsetChar;	//konverze jednotlivych pismen


	if(font==0)
	{

		for(j=0;j<numChar;j++)		//tisk jednotlivych pismen
		{
			printImage(startRow,startCol+6*j,5,8, &charSet0[LCDText[j]*5]);
		}

	}
	else if(font==1)
	{

		for(j=0;j<numChar;j++)		//tisk jednotlivych pismen
		{
			printImage(startRow,startCol+12*j,10,16, &charSet1[LCDText[j]*20]);
		}

	}


}

Keďže je čiaru možné vykresliť vo vodorovnom, horizontálnom a šikmom smere, môžeme ju použiť ako základ pre nakreslenie zložitejších objektov. V tomto prípade sme ju použili pre vytvorenie obdĺžnika, pomocou fce printRect

	
/********************************************************************
 * Function:		void printRect(unsigned int startRow, unsigned int startCol, unsigned int width, unsigned int height, unsigned int widthLine);
 * PreCondition:   
 * Input:          
 * Output:        
 * Side Effects:   
 * Overview:       
 * Note:           
 *******************************************************************/
void printRect(unsigned int startRow, unsigned int startCol, unsigned int width, unsigned int height, unsigned int widthLine)
{

unsigned int g;
unsigned int h;
unsigned int i;
unsigned int j;


	for(i=0; i<2048; i++)
	{
		LCDObject[i]=0;
	}


	for(i=0; i<widthLine; i++)
	{
		printLine(i,0,i,width-1,width);				//horni horizontalni cara
		printLine(height-1-i,0,height-1-i,width-1,width);	//dolni horizontalni cara
		printLine(0,i,height-1,i,width);			//leva vertikalni cara
		printLine(0,width-1-i,height-1,width-1-i,width);	//prava vertikalni cara
	}

printImage(startRow,startCol,width,height,LCDObject);

}


a vyplneného obdĺžnika, pomocou fce printFullRect

	
/********************************************************************
 * Function:		void printFullRect(unsigned int startRow, unsigned int startCol, unsigned int width, unsigned int height)
 * PreCondition:   
 * Input:          
 * Output:        
 * Side Effects:   
 * Overview:       
 * Note:           
 *******************************************************************/

void printFullRect(unsigned int startRow, unsigned int startCol, unsigned int width, unsigned int height)
{

unsigned int g;
unsigned int h;
unsigned int i;
unsigned int j;

	for(i=0; i<2048; i++)
	{
		LCDObject[i]=0;
	}


	for(i=0; i<height; i++)
	{
		printLine(i,0,i,width-1,width);				//horni horizontalni cara
	}


printImage(startRow,startCol,width,height,LCDObject);

}

Všetky vytvorené grafické objekty sú uložené ako bitová postupnosť v RAMke MPC, z kadiaľ ich nesledujúcou funkciou zapíšeme na displej.


[editovat] Umiestnenie objektu na displej

Funkcia printImage má za úlohu umiestneniť vytvorený grafický objekt na požadované miesto na displeji.

/********************************************************************
 * Function:		void printImage(unsigned int startRow, unsigned int startCol, unsigned int width, unsigned int height, unsigned char* buffer)
 * PreCondition:   
 * Input:          
 * Output:        
 * Side Effects:   
 * Overview:       
 * Note:           
 *******************************************************************/
void printImage(unsigned int startRow, unsigned int startCol, unsigned int width, unsigned int height, unsigned char* buffer)
{

unsigned int g;
unsigned int h;
unsigned int i;
unsigned int j;


unsigned int temp;

unsigned int firstPage;
unsigned int firstRow;


unsigned char firstRowMask;

unsigned int lastPage;
unsigned int lastRow;

unsigned int lastPageImage;

unsigned char lastRowMask;

unsigned char lastRowImage;
unsigned char lastRowShift;

/*
		startRow=20;
		startCol=32;
		width=32;
		height=32;	
*/		
		



firstPage=startRow>>3;			//vydelim 8, ziskam prvni stranku 	
firstRow=startRow&0x07;			//posledni 3 bity jsou cislem radku v prvni strance
firstRowMask=0;
lastPage=(startRow+height-1)>>3;	//posledni stranka
lastRow=(startRow+height-1)&0x07;	//pocet bitu v posledni strance
lastPageImage=(height-1)>>3;

lastRowImage=(height-1)&0x07;

//if(lastRow==0) lastRow=7;
lastRowMask=0;

		//printImage(0,0,128,64, image);



		//********************tisk do prvni stranky****************

		//tvorba masky pro prvni stranku
		for(j=0;j<(firstRow);j++)
		{
			firstRowMask<<=1;
			firstRowMask|=1;
		}


		//tvorba masky pro posledni stranku
		for(j=0;j<(7-lastRow);j++)
		{
			lastRowMask>>=1;
			lastRowMask|=0x80;
		}


		g=0;
		for(j=startCol;j<(width+startCol);j++)
		{
			if(j==LCDWidth) break;
			if(firstPage==lastPage)
			{
				temp=((*(buffer+g))<<firstRow);
				temp&=~(firstRowMask|lastRowMask);
				//LCDBuffer[firstPage*LCDWidth+j]=temp;
				//LCDBuffer[firstPage*LCDWidth+j]=(LCDBuffer[firstPage*LCDWidth+j]&(firstRowMask|lastRowMask))|((*(buffer+g))<<firstRow);
				LCDBuffer[firstPage*LCDWidth+j]=(LCDBuffer[firstPage*LCDWidth+j]&(firstRowMask|lastRowMask))|temp;
			}
			else
			{
				LCDBuffer[firstPage*LCDWidth+j]=(LCDBuffer[firstPage*LCDWidth+j]&firstRowMask)|((*(buffer+g))<<firstRow);
			}
			g++;
		}		

		//********************tisk do ostatnich stranek mimo posledni****************
		if((lastPage-firstPage)>1)	//pokud je mezi strankami vetsi vzdalenost nez 1
		{
			h=0;
			for(i=(firstPage+1);i<(lastPage);i++)
			{
				if(i==LCDPage) break;
				g=0;
				for(j=startCol;j<(width+startCol);j++)		//tisk jednotlivych pismen
				{
					if(j==LCDWidth) break;
					LCDBuffer[i*LCDWidth+j]=((*(buffer+h*width+g))>>(8-firstRow))|((*(buffer+(h+1)*width+g))<<firstRow);
					g++;
				}

				h++;

			}
		}

		//********************tisk do posledni stranky****************

		if(((lastPage-firstPage)>0)&&(lastPage<LCDPage))	//pokud je mezi strankami vetsi vzdalenost nez 0 a stranka je jeste na displeji
		{
			g=0;
			for(j=startCol;j<(width+startCol);j++)
			{
				if(j==LCDWidth) break;
				if(lastRow>lastRowImage)
				{
					temp=*(buffer+lastPageImage*width+g)<<(lastRow-lastRowImage);
					temp|=*(buffer+(lastPageImage-1)*width+g)>>(8-(lastRow-lastRowImage));

				}
				else
				{
					temp=*(buffer+lastPageImage*width+g)>>(lastRowImage-lastRow);
				}
				temp&=(~lastRowMask);
				LCDBuffer[lastPage*LCDWidth+j]=(LCDBuffer[lastPage*LCDWidth+j]&lastRowMask)|temp;

				g++;
			}
		}



}

[editovat] Schéma celého programu

Soubor:schema_GLCD.jpg

Za predpokladu, že schéma práce programu nieje jasná, sme poskytli tento obrázok, ktorý ako dúfame prípadné nejasnosti ozrejmí.

[editovat] Ukážka

Nasleduje ukážka funckie pre displej o rozmeroch 128x64.

Pohyb obrázku s odrazem na hraně displeje: ZDE

Osobní nástroje