13. Grafik LCD Kütüphanesi MikroC Pro for AVR, 128x64 Grafik LCD (genellikle Samsung KS108/KS107 denetleyicili) kullanımına yönelik bir kütüphaneye sahiptir. Mikrodenetleyici ile Grafik LCD arasındaki örnek bir bağlantı şeması aşağıda görülmektedir. Şekil. Mikrodenetleyici ile Grafik LCD (Glcd) arasındaki örnek bir bağlantı şeması -73-
13.1. Grafik LCD Kütüphanesi Harici Bağlantıları 13.2. Grafik LCD Kütüphane Rutinleri -74-
GLcd_Init -75-
-76-
-77-
-78-
-79-
-80-
-81-
-82-
-83-
-84-
Örnek 1: // ser_glcd_01.c : Grafik LCD Uygulaması - ATmega16-8 Mhz ve GLCD 128x64, KS108/107) // Glcd Modül Bağlantıları ------------------------------------- char GLCD_DataPort at PORTC; char GLCD_DataPort_Direction at DDRC; sbit GLCD_CS1 at PORTD.B3; sbit GLCD_CS2 at PORTD.B2; sbit GLCD_RS at PORTD.B4; sbit GLCD_RW at PORTD.B5; sbit GLCD_EN at PORTD.B6; sbit GLCD_RST at PORTD.B7; // B2 ile B3 degisti sbit GLCD_CS1_Direction at DDRD.B3; // B2 ile B3 degisti sbit GLCD_CS2_Direction at DDRD.B2; sbit GLCD_RS_Direction at DDRD.B4; sbit GLCD_RW_Direction at DDRD.B5; sbit GLCD_EN_Direction at DDRD.B6; sbit GLCD_RST_Direction at DDRD.B7; // -------------------------------------------------------------- void main() { // GLCD Hazırlanır ---------- Glcd_Init(); // -------------------------- //Renk Doldurma : Glcd_Fill(unsigned short pattern); Glcd_Fill(0); // Clear Glcd pattern : desen // Nokta Basar : Glcd_Dor(x_pos, y_pos, renk); renk :0..2 Glcd_Dot(2, 5, 2); // 0: Beyaz, 1: Siyah, 2 : Tersi-Invert // Cizgi Cizme : Glcd_Line(x1, y1, x2, y2, renk); renk :0..2 Glcd_Line(10, 5, 50, 10, 2); // Yatay Cizgi Cizme : Glcd_H_Line(x1, x2, y, renk); renk :0..2 Glcd_H_Line(60, 90, 5, 2); // Dikey Cizgi Cizme : Glcd_V_Line(y1, y2, x, renk); renk :0..2 Glcd_V_Line(5, 30, 110, 2); // Kutu Cizme : Glcd_Box(x1, y1, x2, y2, renk); renk :0..2 (dolgu rengi) Glcd_Box (5,20,50,40,2); Glcd_Box (15,25,40,35,0); // Dortgen Cizme : Glcd_Rectangle(x1, y1, x2, y2, renk); renk :0..2 (cizgi rengi) Glcd_Rectangle (60,20,100,40,2); // Daire Cizme : Glcd_Circle(x, y, r, renk); renk :0..2 (dolgu rengi) Glcd_Circle (20,52,10,2); -85-
Örnek 2: // ser_glcd_02.c : Grafik LCD Uygulaması - ATmega16-8 Mhz ve GLCD 128x64, KS108/107) // Glcd Modül Bağlantısı ----------------------------------- char GLCD_DataPort at PORTC; char GLCD_DataPort_Direction at DDRC; sbit GLCD_CS1 at PORTD.B3; sbit GLCD_CS2 at PORTD.B2; sbit GLCD_RS at PORTD.B4; sbit GLCD_RW at PORTD.B5; sbit GLCD_EN at PORTD.B6; sbit GLCD_RST at PORTD.B7; // B2 ile B3 degisti sbit GLCD_CS1_Direction at DDRD.B3; // B2 ile B3 degisti sbit GLCD_CS2_Direction at DDRD.B2; sbit GLCD_RS_Direction at DDRD.B4; sbit GLCD_RW_Direction at DDRD.B5; sbit GLCD_EN_Direction at DDRD.B6; sbit GLCD_RST_Direction at DDRD.B7; // --------------------------------------------------------- void main() { // GLCD Hazırla -------------- Glcd_Init(); // -------------------------- // Clear GLCD Glcd_Fill(0); // Font Ayari : Glcd_Set_Font(activefont, FontWidth,FontHeight,FontOffs); // Glcd_Set_Font(Font5x7, 5, 7, 32); Glcd_Set_Font(Character8x7, 8, 7, 32); // Glcd_Set_Font(System3x5, 3, 5, 32); // Text Yazdırma Glcd_Write_Text("Hitit - MYO", 15, 0, 2); // Karakter Yazdırma Glcd_Write_Char('A', 15, 5, 2); -86-
Örnek 3: // GLCD_Animasyon_1.c: Grafik LCD Uygulaması - ATmega16-8Mhz ve GLCD 128x64, KS108/107) // Glcd Modül Bağlantısı ----------------------------------- char GLCD_DataPort at PORTC; char GLCD_DataPort_Direction at DDRC; sbit GLCD_CS1 at PORTD.B3; sbit GLCD_CS2 at PORTD.B2; sbit GLCD_RS at PORTD.B4; sbit GLCD_RW at PORTD.B5; sbit GLCD_EN at PORTD.B6; sbit GLCD_RST at PORTD.B7; // B2 ile B3 degisti sbit GLCD_CS1_Direction at DDRD.B3; // B2 ile B3 degisti sbit GLCD_CS2_Direction at DDRD.B2; sbit GLCD_RS_Direction at DDRD.B4; sbit GLCD_RW_Direction at DDRD.B5; sbit GLCD_EN_Direction at DDRD.B6; sbit GLCD_RST_Direction at DDRD.B7; // ------------------------------------------------------------- //Sag_Ok Cizimi ---------------------- void Sag_Ok(int x, int y, int c) { Glcd_Line(x, y, x+10, y, c); Glcd_Line(x+5, y-2, x+10, y, c); Glcd_Line(x+5, y+2, x+10, y, c); // ------------------------------------- void main() { // Local Değişken Tanımı unsigned short i; // GLCD Hazırla Glcd_Init(); // Clear GLCD Glcd_Fill(0); // Grafik Animasyon for ( i=0 ; ; ++i) { Sag_Ok( (i%3)*20 + 40, 30, 2); Delay_ms(100); -87-
Örnek 4: // ser_image_ani_01.c Grafik LCD Uygulaması - ATmega16-8Mhz ve GLCD 128x64, KS108/107) unsigned char const Damper_Kapali[1024] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255, 0,254, ; unsigned char const Damper_Yari_Acik[1024] = { 0, 0, 0,192,240,252, 7,247,245,245, 21,245,245,245,245, 21, ; unsigned char const Damper_Tam_Acik[1024] = { 88, 88, 88, 88, 88, 88, 88, 88, 88,120,248,248,192, 0, 0, 0, ; // Glcd Modül Bağlantıları ----------------------------------- char GLCD_DataPort at PORTC; char GLCD_DataPort_Direction at DDRC; sbit GLCD_CS1 at PORTD.B3; sbit GLCD_CS2 at PORTD.B2; sbit GLCD_RS at PORTD.B4; sbit GLCD_RW at PORTD.B5; sbit GLCD_EN at PORTD.B6; sbit GLCD_RST at PORTD.B7; // B2 ile B3 degisti sbit GLCD_CS1_Direction at DDRD.B3; // B2 ile B3 degisti sbit GLCD_CS2_Direction at DDRD.B2; sbit GLCD_RS_Direction at DDRD.B4; sbit GLCD_RW_Direction at DDRD.B5; sbit GLCD_EN_Direction at DDRD.B6; sbit GLCD_RST_Direction at DDRD.B7; // ----------------------------------------------------------- void main() { Glcd_Init(); // GLCD Hazırla Glcd_Fill(0); // Clear GLCD for(;;) // Sonsuz Çevrim { // Image - I (Kapalı) Glcd_Image(Damper_Kapali); Delay_ms(1000); // Image - II (Yarı Açık) Glcd_Image(Damper_Yari_Acik); Delay_ms(1000); // Image - III (Tam Açık) Glcd_Image(Damper_Tam_Acik); Delay_ms(1000); Image - I (Kapalı) Image - II (Yarı Açık) Image - III (Tam Açık -88-
Örnek 5: // ser_image_ani_02.c Grafik LCD Uygulaması - ATmega16-8Mhz ve GLCD 128x64, KS108/107) // Glcd Modül Bağlantısı ----------------------------------- char GLCD_DataPort at PORTC; char GLCD_DataPort_Direction at DDRC; sbit GLCD_CS1 at PORTD.B3; sbit GLCD_CS2 at PORTD.B2; sbit GLCD_RS at PORTD.B4; sbit GLCD_RW at PORTD.B5; sbit GLCD_EN at PORTD.B6; sbit GLCD_RST at PORTD.B7; // B2 ile B3 degisti sbit GLCD_CS1_Direction at DDRD.B3; // B2 ile B3 degisti sbit GLCD_CS2_Direction at DDRD.B2; sbit GLCD_RS_Direction at DDRD.B4; sbit GLCD_RW_Direction at DDRD.B5; sbit GLCD_EN_Direction at DDRD.B6; sbit GLCD_RST_Direction at DDRD.B7; // ------------------------------------------------------------- void main() { // Degisken Tanımları char i; // GLCD Hazırla Glcd_Init(); // Sonsuz Çevrim while(1) { // Animasyon - 1 ----------------------------------- for(i=1 ; i<33 ; ++i ) { Glcd_Fill(0x00); // Clear GLCD Glcd_Circle(40, 32, i, 2); // Daire Cizimi Delay_ms(50); // -------------------------------------------------- // Text Yazdır -------------------------------------- Glcd_Set_Font(Character8x7, 5,7, 32); Glcd_Write_Text("HiTiT", -14, 3,2); Glcd_Write_Text(" MYO ", -14, 4, 2); Delay_ms(500); // -------------------------------------------------- // Animasyon - 2 ------------------------------------ for(i=32 ; i>0 ; --i) { Glcd_Fill(0x00); // Clear GLCD Glcd_Circle(40, 32, i, 2); // Daire Cizimi Delay_ms(50); // --------------------------------------------------- -89-