{"id":4256,"date":"2012-01-05T18:04:14","date_gmt":"2012-01-05T23:04:14","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=4256"},"modified":"2012-11-06T13:52:44","modified_gmt":"2012-11-06T18:52:44","slug":"lab-20-interfacing-a-ks0108-based-graphics-lcd-part-2","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/lab-20-interfacing-a-ks0108-based-graphics-lcd-part-2\/","title":{"rendered":"Lab 20: Interfacing a KS0108 based Graphics LCD (Part 2)"},"content":{"rendered":"<p>In the <a href=\"http:\/\/embedded-lab.com\/blog\/?p=2398\" target=\"_blank\"><strong>first part<\/strong><\/a> of this tutorial, we discussed about Winstar\u2019s WDG0151-TMI GLCD module, which is a 128\u00d764 pixel monochromatic display built with KS0108B and KS0107B compatible display controllers. The module was interfaced to a PIC16F887 microcontroller and a test program was written in C to demonstrate how to implement the KS0108 instruction set in the firmware of PIC to activate display pixels on the screen. We wrote our subroutine programs that would turn the GLCD on, move the display location to a specified row and column, and draw a pixel at a given coordinates. You might have realized it by now that how much of effort is required to write the firmware for just plotting a point on a GLCD screen. Today&#8217;s discussion will focus more on using the built-in GLCD library routines of mikroC Pro for PIC compiler, which will make your life a lot easier if you are using a graphical LCD in your project.<\/p>\n<div id=\"attachment_4314\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/GLCDTitle.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4314\" class=\"size-full wp-image-4314\" title=\"GLCDTitle\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/GLCDTitle.jpg\" alt=\"\" width=\"560\" height=\"420\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/GLCDTitle.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/GLCDTitle-550x412.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4314\" class=\"wp-caption-text\">Using MikroC Pro for PIC GLCD library<\/p><\/div>\n<p><!--more--><strong>GLCD Library of mikroC Pro for PIC<\/strong><\/p>\n<p>The mikroC Pro for PIC provides GLCD library for a 128&#215;64 pixel graphical LCD with Samsung KS0108\/KS0107 controller chips. The library routines are categorized into two types: <strong>basic<\/strong> and <strong>advanced<\/strong>. Before using any library routine, following pin definitions is required. For our case (see the circuit diagram in the\u00a0 <a href=\"http:\/\/embedded-lab.com\/blog\/?p=2398\" target=\"_blank\"><strong>first part<\/strong><\/a>) where PORTD is used for data and PORTB pins for control signals, the GLCD pin settings should be defined as follows. Remember that the data lines must be on a single port.<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"c\" style=\"font-family:monospace;\"><span style=\"color: #666666; font-style: italic;\">\/\/ glcd pinout settings<\/span>\n <span style=\"color: #993333;\">char<\/span> GLCD_DataPort at PORTD<span style=\"color: #339933;\">;<\/span>\n sbit GLCD_CS1 at RB0_bit<span style=\"color: #339933;\">;<\/span>\n sbit GLCD_CS2 at RB1_bit<span style=\"color: #339933;\">;<\/span>\n sbit GLCD_RS at RB2_bit<span style=\"color: #339933;\">;<\/span>\n sbit GLCD_RW at RB3_bit<span style=\"color: #339933;\">;&lt;<\/span>strong<span style=\"color: #339933;\">&gt;&lt;\/<\/span>strong<span style=\"color: #339933;\">&gt;<\/span>\n sbit GLCD_EN at RB5_bit<span style=\"color: #339933;\">;<\/span>\n sbit GLCD_RST at RB4_bit<span style=\"color: #339933;\">;<\/span>\n sbit GLCD_CS1_Direction at TRISB0_bit<span style=\"color: #339933;\">;<\/span>\n sbit GLCD_CS2_Direction at TRISB1_bit<span style=\"color: #339933;\">;<\/span>\n sbit GLCD_RS_Direction at TRISB2_bit<span style=\"color: #339933;\">;<\/span>\n sbit GLCD_RW_Direction at TRISB3_bit<span style=\"color: #339933;\">;<\/span>\n sbit GLCD_EN_Direction at TRISB5_bit<span style=\"color: #339933;\">;<\/span>\n sbit GLCD_RST_Direction at TRISB4_bit<span style=\"color: #339933;\">;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<p><strong>Basic routines:<\/strong><\/p>\n<ul>\n<li><em><strong>Glcd_Init<\/strong><\/em> : Initializes the Glcd module<\/li>\n<li><strong><em>Glcd_Set_Side<\/em><\/strong>: Selects the Glcd side. Example, <em>Glcd_Set_Side(0)<\/em> and <em>Glcd_Set_Side(62)<\/em> both select the left side of the GLCD. Values from 64-127, such as <em>Glcd_Set_Side(67)<\/em>, selects the right side of the GLCD.<\/li>\n<li><em><strong>Glcd_Set_X<\/strong><\/em> : Sets x-axis position from the left border of Glcd within the selected side. Example, <em>Glcd_Set_X(25)<\/em>.<\/li>\n<li><em><strong>Glcd_Set_Page<\/strong><\/em> : Selects page (0-7) of the Glcd.<\/li>\n<li><em><strong>Glcd_Read_Data<\/strong><\/em> : Reads one byte of data from the current location of Glcd memory and moves to the next location.<\/li>\n<li><em><strong>Glcd_Write_Data<\/strong><\/em> : Writes one byte of data from the current location of Glcd memory and moves to the next location.<\/li>\n<\/ul>\n<p><strong>Advanced routines:<\/strong><\/p>\n<ul>\n<li><em><strong>Glcd_Fill<\/strong><\/em> : Fills GLCD display RAM with a byte pattern. If the byte is 0, it will clear the display. If it is 0xFF, then it will fill the entire display with 1.<\/li>\n<li><strong><em>Glcd_Dot<\/em><\/strong> : Draws a dot on Glcd at given coordinates with a specified color. It is used as <em>Glcd_Dot(x, y, <code>color<\/code>),<\/em> where x = 0-127, and y=0-63, and <code>color<\/code> = 0-2. The parameter <code>color<\/code> determines a dot state: 0 clears dot, 1 puts a dot, and 2 inverts the dot state.<\/li>\n<li><em><strong>Glcd_Line<\/strong><\/em> : Draws a line joining two specified point coordinates and a given color value (0-2).<\/li>\n<li><em><strong>Glcd_V_Line<\/strong><\/em> : Draws a vertical line passing through two points with the same x-coordinate. It also accepts color parameter.<\/li>\n<li><em><strong>Glcd_H_Line<\/strong><\/em> : Draws a horizontal line passing through two points with the same y-coordinate.\u00a0It also accepts color parameter.<\/li>\n<li><em><strong>Glcd_Rectangle<\/strong><\/em> : Draws a rectangle with specified top left and bottom right corner coordinates.\u00a0It also accepts color parameter.<\/li>\n<li><em><strong>Glcd_Box<\/strong><\/em> :\u00a0Draws a box with specified top left and bottom right corner coordinates. Unlike in Glcd_Rectangle, the color parameter here is the fill color of the box.<\/li>\n<li><em><strong>Glcd_Circle<\/strong><\/em> : Draws a circle with specified center coordinates and radius. It also accepts color parameter.<\/li>\n<li><em><strong>Glcd_Set_Font<\/strong><\/em>: As it was mentioned earlier in <a href=\"http:\/\/embedded-lab.com\/blog\/?p=2398\" target=\"_blank\"><strong>Part1<\/strong><\/a>, KS0108 controller does not have a built-in character generator and therefore fonts must be written in the firmware of the external microcontroller. This is a time consuming task as you need to determine data values for each letter to display. For simplicity, mikroElektronika provides the following demo fonts with mikroC Pro for PIC compiler.\n<ul>\n<li><code>Font_Glcd_System3x5<\/code><\/li>\n<li><code>Font_Glcd_System5x7<\/code><\/li>\n<li><code>Font_Glcd_5x7<\/code><\/li>\n<li><code>Font_Glcd_Character8x7<\/code><\/li>\n<\/ul>\n<p>These fonts are used by Glcd_Write_Char and Glcd_Write_Text functions (defined below) to display character and text. The syntax for defining font is,<\/li>\n<\/ul>\n<p><strong>Glcd_Set_Font<\/strong> (const char *<em>activeFont<\/em>, unsigned short <em>aFontWidth<\/em>, unsigned\u00a0 short <em>aFontHeight<\/em>, unsigned int <em>aFontOffs<\/em>);<\/p>\n<p>where parameters are:<\/p>\n<ul>\n<li><code>activeFont:<\/code> font to be set. Needs to be formatted as an array of char<\/li>\n<li><code>aFontWidth:<\/code> width of the font characters in dots.<\/li>\n<li><code>aFontHeight:<\/code> height of the font characters in dots.<\/li>\n<li><code>aFontOffs:<\/code> number that represents difference between the mikroC PRO for PIC character set and regular ASCII set. Demo fonts supplied with the library have an offset of 32.<\/li>\n<\/ul>\n<p>So, if you want to use the\u00a0<code>Font_Glcd_5x7<\/code>, you can define the font as,<\/p>\n<pre>                Glcd_Set_Font(Font_Glcd_5x7, 5, 7, 32);<\/pre>\n<ul>\n<li><em><strong>Glcd_Write_Char<\/strong><\/em> : Writes a character at a defined x-position (0-127) and page number (0-7) on GLCD.<\/li>\n<li><em><strong>Glcd_Write_Text<\/strong><\/em> : For printing a text\u00a0at a given x-position (0-127) and page number (0-7) on GLCD<\/li>\n<li><em><strong>Glcd_Image<\/strong><\/em>:\u00a0Displays bitmap image on Glcd. The bitmap array of the image must be provided in the firmware. I have described this part in more detail in this post:<br \/>\n<h3><a title=\"Permanent Link to How to use mikroElektronika\u2019s GLCD bitmap editor tool to convert a BMP image in to a data array\" href=\"http:\/\/embedded-lab.com\/blog\/?p=3934\" rel=\"bookmark\">How to use mikroElektronika\u2019s GLCD bitmap editor tool to convert a BMP image in to a data array<\/a><\/h3>\n<\/li>\n<\/ul>\n<p><strong>Circuit diagram<\/strong><\/p>\n<div>It is the same as described in <a href=\"http:\/\/embedded-lab.com\/blog\/?p=2398\" target=\"_blank\"><strong>Part 1<\/strong><\/a> of this tutorial and I am using UNI-DS6 development board for demonstration.<\/div>\n<p><strong>Software<\/strong><\/p>\n<div>The following program is written in mikroC Pro for PIC compiler for demonstrating the GLCD library routines described above. The first part of the program draws horizontal and vertical lines, rectangle, circle, and a filled box on the GLCD. The second part writes texts in all eight pages (0-7) using <em>Font_Glcd_5x7<\/em>. At the end, bigger font size (<em>Font_Glcd_Characters_8x7<\/em>) is used to write &#8220;<em>Embedded Lab<\/em>&#8221; at the center of the screen.<\/div>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"c\" style=\"font-family:monospace;\"><span style=\"color: #808080; font-style: italic;\">\/*\n * Project name: Testing GLCD with PIC16F887\n   Embedded-Lab.com, Jan 02, 2012.\n&nbsp;\n * Description:\n     This routine demonstrates how to use MikroC Pro for PIC GLCD library\n     routines for displaying shapes and texts of various font size.\n      * Test configuration:\n     MCU:             PIC16F887\n     Dev.Board:       UNI-DS6\n     Oscillator:      HS, 10.0000 MHz\n     Ext. Modules:    GLCD 128x64, KS108\/107 controller\n&nbsp;\n*\/<\/span>\n&nbsp;\n<span style=\"color: #666666; font-style: italic;\">\/\/ Glcd module connections<\/span>\n<span style=\"color: #993333;\">char<\/span> GLCD_DataPort at PORTD<span style=\"color: #339933;\">;<\/span>\n&nbsp;\nsbit GLCD_CS1 at RB0_bit<span style=\"color: #339933;\">;<\/span>\nsbit GLCD_CS2 at RB1_bit<span style=\"color: #339933;\">;<\/span>\nsbit GLCD_RS  at RB2_bit<span style=\"color: #339933;\">;<\/span>\nsbit GLCD_RW  at RB3_bit<span style=\"color: #339933;\">;<\/span>\nsbit GLCD_RST  at RB4_bit<span style=\"color: #339933;\">;<\/span>\nsbit GLCD_EN at RB5_bit<span style=\"color: #339933;\">;<\/span>\n&nbsp;\nsbit GLCD_CS1_Direction at TRISB0_bit<span style=\"color: #339933;\">;<\/span>\nsbit GLCD_CS2_Direction at TRISB1_bit<span style=\"color: #339933;\">;<\/span>\nsbit GLCD_RS_Direction  at TRISB2_bit<span style=\"color: #339933;\">;<\/span>\nsbit GLCD_RW_Direction  at TRISB3_bit<span style=\"color: #339933;\">;<\/span>\nsbit GLCD_RST_Direction  at TRISB4_bit<span style=\"color: #339933;\">;<\/span>\nsbit GLCD_EN_Direction at TRISB5_bit<span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #666666; font-style: italic;\">\/\/ End Glcd module connections<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> Delay2S<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/ 2 seconds delay function<\/span>\n  Delay_ms<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">2000<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> main<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n  ANSEL  <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>                                      <span style=\"color: #666666; font-style: italic;\">\/\/ Configure AN pins as digital<\/span>\n  ANSELH <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n  C1ON_bit <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>                                    <span style=\"color: #666666; font-style: italic;\">\/\/ Disable comparators<\/span>\n  C2ON_bit <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n  TRISD <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x00<\/span><span style=\"color: #339933;\">;<\/span>\n  TRISB <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x00<\/span><span style=\"color: #339933;\">;<\/span>\n  Glcd_Init<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/ Initialize GLCD<\/span>\n  Glcd_Fill<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x00<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>         <span style=\"color: #666666; font-style: italic;\">\/\/ Clear GLCD<\/span>\n&nbsp;\n  <span style=\"color: #b1b100;\">do<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n      Glcd_V_Line<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">63<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">64<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_H_Line<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">127<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">32<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Rectangle<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">10<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">5<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">117<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">57<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>     <span style=\"color: #666666; font-style: italic;\">\/\/ Draw rectangle, color is 1<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Circle<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">64<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">32<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">15<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Fill<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0xFF<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>                  <span style=\"color: #666666; font-style: italic;\">\/\/ Fill Glcd with all 1s<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_V_Line<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">63<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">64<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_H_Line<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">127<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">32<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Rectangle<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">10<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">5<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">117<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">57<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>     <span style=\"color: #666666; font-style: italic;\">\/\/ Draw rectangle, color is 0 now<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Circle<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">64<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">32<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">15<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Fill<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x00<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>                  <span style=\"color: #666666; font-style: italic;\">\/\/ Clear GLCD<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Box<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">10<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">5<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">117<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">57<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Fill<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x00<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>                  <span style=\"color: #666666; font-style: italic;\">\/\/ Clear GLCD<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n&nbsp;\n      Glcd_Set_Font<span style=\"color: #009900;\">&#40;<\/span>Font_Glcd_5x7<span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">5<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">7<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">32<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Write_Text<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;This is Page 0&quot;<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">10<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Write_Text<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;This is Page 1&quot;<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">10<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Write_Text<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;This is Page 2&quot;<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">10<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">2<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Write_Text<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;This is Page 3&quot;<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">10<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">3<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Write_Text<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;This is Page 4&quot;<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">10<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">4<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Write_Text<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;This is Page 5&quot;<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">10<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">5<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Write_Text<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;This is Page 6&quot;<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">10<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">6<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Write_Text<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;This is Page 7&quot;<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">10<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">7<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Fill<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x00<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>         <span style=\"color: #666666; font-style: italic;\">\/\/ Clear GLCD<\/span>\n      Glcd_Set_Font<span style=\"color: #009900;\">&#40;<\/span>Font_Glcd_Character8x7<span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">8<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">7<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">32<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Write_Text<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;Embedded Lab&quot;<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">8<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">3<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>   <span style=\"color: #666666; font-style: italic;\">\/\/ Write string<\/span>\n      Delay2s<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      Glcd_Fill<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #208080;\">0x00<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>         <span style=\"color: #666666; font-style: italic;\">\/\/ Clear GLCD<\/span>\n  <span style=\"color: #009900;\">&#125;<\/span> <span style=\"color: #b1b100;\">while<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<div><a href=\"http:\/\/embedded-lab.com\/uploads\/HexFiles\/PIC16F887\/GLCD_Text.zip\" target=\"_blank\"><strong>Download source and HEX files<\/strong><\/a><\/div>\n<div>The pictures below show some of the outputs of this program. This has been tested on UNI-DS6 development board with PIC16F887 microcontroller.<\/div>\n<div id=\"attachment_4305\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/DrawGeometry.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4305\" class=\"size-full wp-image-4305\" title=\"DrawGeometry\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/DrawGeometry.jpg\" alt=\"\" width=\"560\" height=\"446\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/DrawGeometry.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/DrawGeometry-550x438.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4305\" class=\"wp-caption-text\">Drawing lines, rectangle, and circle using GLCD library<\/p><\/div>\n<div id=\"attachment_4307\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/InvertColor.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4307\" class=\"size-full wp-image-4307\" title=\"InvertColor\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/InvertColor.jpg\" alt=\"\" width=\"560\" height=\"429\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/InvertColor.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/InvertColor-550x421.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4307\" class=\"wp-caption-text\">Same thing with inverted color<\/p><\/div>\n<div id=\"attachment_4304\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/Box.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4304\" class=\"size-full wp-image-4304\" title=\"Box\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/Box.jpg\" alt=\"\" width=\"560\" height=\"407\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/Box.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/Box-550x399.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4304\" class=\"wp-caption-text\">Filled box<\/p><\/div>\n<div id=\"attachment_4308\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/PagesDemo.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4308\" class=\"size-full wp-image-4308\" title=\"PagesDemo\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/PagesDemo.jpg\" alt=\"\" width=\"560\" height=\"427\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/PagesDemo.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/PagesDemo-550x419.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4308\" class=\"wp-caption-text\">Displaying GLCD page numbers with 5x7 font size<\/p><\/div>\n<div id=\"attachment_4306\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/FontDemo.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4306\" class=\"size-full wp-image-4306\" title=\"FontDemo\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/FontDemo.jpg\" alt=\"\" width=\"560\" height=\"435\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/FontDemo.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/01\/FontDemo-550x427.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4306\" class=\"wp-caption-text\">Text display with 8x7 font<\/p><\/div>\n<p>You can also display a 128&#215;64 pixels\u00a0monochromatic bitmap image on the GLCD. For this you need to first convert the bitmap image file into a data array. The following link takes you to a tutorial page which describes how to do that.<\/p>\n<h3><a title=\"Permanent Link to How to use mikroElektronika\u2019s GLCD bitmap editor tool to convert a BMP image in to a data array\" href=\"http:\/\/embedded-lab.com\/blog\/?p=3934\" rel=\"bookmark\">How to use mikroElektronika\u2019s GLCD bitmap editor tool to convert a BMP image in to a data array<\/a><\/h3>\n<div id=\"attachment_3943\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/10\/GLCD_Output.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3943\" class=\"size-full wp-image-3943\" title=\"GLCD_Output\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/10\/GLCD_Output.jpg\" alt=\"\" width=\"560\" height=\"400\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/10\/GLCD_Output.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/10\/GLCD_Output-550x392.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-3943\" class=\"wp-caption-text\">Displaying Microchip logo using GLCD bitmap editor tool<\/p><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the first part of this tutorial, we discussed about Winstar\u2019s WDG0151-TMI GLCD module, which is a 128\u00d764 pixel monochromatic display built with KS0108B and KS0107B compatible display controllers. The module was interfaced to a PIC16F887 microcontroller and a test program was written in C to demonstrate how to implement the KS0108 instruction set in the firmware of PIC to activate display pixels on the screen. We wrote our subroutine programs that would turn the GLCD on, move the display location to a specified row and column, and draw a pixel at a given coordinates. You might have realized it<\/p>\n","protected":false},"author":1,"featured_media":4304,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,29,38],"tags":[158,365,390,316],"class_list":["post-4256","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded-labs","category-embedded-lessons","category-pic-tutorials","tag-glcd","tag-ks0108","tag-mikroc-pro-for-pic","tag-pic16f887"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=4256"}],"version-history":[{"count":21,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4256\/revisions"}],"predecessor-version":[{"id":4328,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4256\/revisions\/4328"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/4304"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=4256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=4256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=4256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}