{"id":2398,"date":"2011-12-20T22:48:38","date_gmt":"2011-12-21T03:48:38","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=2398"},"modified":"2013-05-03T23:05:11","modified_gmt":"2013-05-04T03:05:11","slug":"lab-20-interfacing-a-ks0108-based-graphics-lcd-part-1","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/lab-20-interfacing-a-ks0108-based-graphics-lcd-part-1\/","title":{"rendered":"Lab 20: Interfacing a KS0108 based Graphics LCD (Part 1)"},"content":{"rendered":"<p>The use of a graphical LCD (GLCD) drastically changes the look of your project. It provides more freedom for presenting data than the HD44870 based character LCDs. Today we will see how to interface a KS0108 (name of the display controller chip) based GLCD to a PIC microcontroller. This experimental tutorial is divided into two parts. In the first part, we will see how to write a firmware for the PIC microcontroller to initialize the GLCD and send data to plot points and lines on the screen. The <a href=\"http:\/\/embedded-lab.com\/blog\/?p=4256\" target=\"_blank\"><strong>second part<\/strong><\/a> will focus more on exploring the built-in GLCD Library of mikroC Pro for PIC compiler to display more complex texts and objects. Since GLCDs are real resource hungry devices (in terms of required I\/O pins and memory), a bigger size PIC microcontroller (PIC16F887, which has 36 I\/O pins and 14KB flash memory) is selected for this experiment. I am using MikroElektronika&#8217;s UNI-DS6 development board to demonstrate this project, but the circuit setup can also be made on a breadboard.<\/p>\n<div id=\"attachment_4210\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Title.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4210\" class=\"size-full wp-image-4210\" title=\"GLCD_Title\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Title.jpg\" alt=\"\" width=\"560\" height=\"360\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Title.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Title-550x353.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4210\" class=\"wp-caption-text\">Interfacing a 128x64 pixels GLCD<\/p><\/div>\n<p><!--more--><\/p>\n<p><strong>Theory<\/strong><\/p>\n<p>The graphical LCD used in this experiment is Winstar&#8217;s WDG0151-TMI module, which is a 128&#215;64 pixel monochromatic display. It uses two Neotic display controller chips: NT7108C and NT7107C, which are compatible with Samsung KS0108B and KS0107B controllers. The KS0108B (or NT7108C) \u00a0is a dot matrix LCD segment driver with 64 channel output, and therefore, the WDG0151 module contains two sets of it to drive 128 segments. On the other hand, the KS0107B (or NT7107C) is a 64-channel common driver which generates the timing signal to control the two KS0108B segment drivers. The KS0108B and KS0107B are a very popular controllers and have made their way into many graphical LCDs. The internal block diagram of the WDG0151 GLCD module is shown below.<\/p>\n<div id=\"attachment_4222\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_InternalBlock1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4222\" class=\"size-medium wp-image-4222\" title=\"GLCD_InternalBlock1\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_InternalBlock1-550x351.jpg\" alt=\"\" width=\"550\" height=\"351\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_InternalBlock1-550x351.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_InternalBlock1.jpg 857w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-4222\" class=\"wp-caption-text\">Internal block diagram of a KS0108B (NT7108C) based 128x64 pixel GLCD module<\/p><\/div>\n<p>The NT1707C drives the 64 display lines, COM1 &#8211; COM64. The first NT7108C drives the left half segments (SEG1 to SEG64) and the second one drives the right half segments (SEG65 to SEG128) of the display. The two halves of the display can be individually accessed through the chip select pins (CS1 and CS2) of the two NT7108C drivers.\u00a0Each half consists of 8 horizontal pages (0-7) which are 8 bits (1 byte) high. This is illustrated in the drawing below.<\/p>\n<div id=\"attachment_4225\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Pages.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4225\" class=\"size-full wp-image-4225\" title=\"GLCD_Pages\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Pages.jpg\" alt=\"\" width=\"570\" height=\"365\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Pages.jpg 570w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Pages-550x352.jpg 550w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><p id=\"caption-attachment-4225\" class=\"wp-caption-text\">GLCD pages<\/p><\/div>\n<p>Starting from page 0 on the left half (\/CS1 = 0) if you transmit one data byte, it will appear on the first column of page 0. If you repeat this 64 times, then switch to the second half, and repeat until 128th position is reached, the first 8 display lines will be plotted. The next 8 lines can be plotted similarly by switching to page address 1. The total amount of bytes needed for a complete display frame (128&#215;64 pixels) is, therefore, \u00a02 * 64 pixels * 8 bits = 1024 bytes.<\/p>\n<p>The\u00a0Winstar WDG0151-TMI module does have an internal negative voltage generator circuit which provides a negative voltage at V<sub>EE<\/sub> external pin. An external potentiometer (usually 10 K) is connected between Vcc and V<sub>EE<\/sub>\u00a0pins to set the LCD working voltage (contrast) at Vo pin.\u00a0The pin diagrams of KS0108 based GLCDs is not standardized and it is therefore, important to read the manufacturer&#8217;s datasheet for correct wiring of a GLCD module. The following table shows the pin descriptions of \u00a0Winstar WDG0151-TMI module. It has altogether 20 pins. The first two pins (1 and 2) are the chip select pins for the left and right display controller. They are active low in a WDG0151-TMI module, but they could be active high in some other models. That&#8217;s why I said reading manufacturer&#8217;s datasheet is very important.\u00a0The WDG0151-TMI module\u00a0operates at 5.0 V power supply. Pin number 6 is Data\/Instruction (also called Register Select, RS) select pin. The 8-bit data fed to D0-D7 pins of the GLCD is received by the LCD controller chip as an instruction if D\/I = 0, and as data if D\/I is 1. The R\/W and E pins have similar functions as in a HD44780 based character LCD module. \u00a0A\u00a0fixed resistor value must be connected in series with the back-light LED (pins 19 and 20) to limit the current.<\/p>\n<div id=\"attachment_4231\" style=\"width: 572px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/PinDescription.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4231\" class=\"size-full wp-image-4231\" title=\"PinDescription\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/PinDescription.jpg\" alt=\"\" width=\"562\" height=\"463\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/PinDescription.jpg 562w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/PinDescription-550x453.jpg 550w\" sizes=\"auto, (max-width: 562px) 100vw, 562px\" \/><\/a><p id=\"caption-attachment-4231\" class=\"wp-caption-text\">Pin description of Winstar WDG01510 GLCD module<\/p><\/div>\n<p>The KS0107\/KS0108 does not have a character generator so this\u00a0must be implemented in the microcontroller firmware. The LCD controller supports a handful of instructions which are summarized in the table shown below. Note that the RS (D\/I) pin is high only during data read and data write operations, and stays low when a transmitted byte is an instruction.<\/p>\n<div id=\"attachment_4227\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/DisplayControlInstructions.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4227\" class=\"size-medium wp-image-4227\" title=\"DisplayControlInstructions\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/DisplayControlInstructions-550x377.jpg\" alt=\"\" width=\"550\" height=\"377\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/DisplayControlInstructions-550x377.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/DisplayControlInstructions.jpg 717w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-4227\" class=\"wp-caption-text\">Display control instructions (click on image to enlarge)<\/p><\/div>\n<p><strong>Circuit diagram<\/strong><\/p>\n<p>The circuit diagram for this experiment is shown below. The PIC16F887 microcontroller is used to drive a\u00a0Winstar WDG0151-TMI GLCD. The data pins are connected to PORTD and other control signals are driven through PORTB pins. I am trying this circuit on MikroElektronika&#8217;s <a href=\"http:\/\/www.mikroe.com\/eng\/products\/view\/669\/uni-ds6-development-system\/\" target=\"_blank\">UNI-DS6 development board.<\/a><\/p>\n<p>&nbsp;<\/p>\n<div id=\"attachment_4319\" style=\"width: 568px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Ckt.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4319\" class=\"size-full wp-image-4319\" title=\"GLCD_Ckt\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Ckt.jpg\" alt=\"\" width=\"558\" height=\"504\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Ckt.jpg 558w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/GLCD_Ckt-550x496.jpg 550w\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" \/><\/a><p id=\"caption-attachment-4319\" class=\"wp-caption-text\">Circuit diagram for GLCD interfacing<\/p><\/div>\n<p>&nbsp;<\/p>\n<p><strong>Software<\/strong><\/p>\n<p>We will be writing our test program in C using MikroElektronika&#8217;s\u00a0mikroC Pro for PIC compiler. Although, the compiler does provide built-in library routines for GLCD operations, we will first try to write our own test code for transferring display data from the PIC16F887 to the GLCD. Later, we will explore the MikroElektronika&#8217;s GLCD library for more complex operations. The code provided below generates 11 dotted horizontal lines on the GLCD screen with a six-line spacing between two. I took most portion of it from <a href=\"https:\/\/sites.google.com\/site\/osamaslab\/Home\" target=\"_blank\">Osama&#8217;s Lab GLCD library<\/a>\u00a0and modified it to suit with mikroC Pro for PIC and WDG0151-TMI GLCD. Here&#8217;s a brief description of various user-defined function subroutines used in the code.<\/p>\n<p><em>GLCD_ON()<\/em> : This function turns the display on. This can be done by sending the command 3Fh to both the controllers. So, while sending this command, both CS1 and CS2 must be pulled low. Similarly the RS pin should be low too as the byte sent is an instruction.<\/p>\n<p><em>Set_Start_Line()<\/em> : \u00a0This function changes the line number to be displayed at the top of the screen. You can set it to be any number between 0 to 63. It does not affect the data in the display RAM, it just scrolls the display up and down.<\/p>\n<p><em>GOTO_COL()<\/em> : Moves the cursor to specified column (0-127).<\/p>\n<p><em>GOTO_ROW()<\/em> : Moves the cursor to specified row or page number (0-7).<\/p>\n<p><em>GOTO_XY()<\/em> : Moves the cursor to specified row and column.<\/p>\n<p><em>GLCD_Write()<\/em> : Writes a byte of data to the current location.<\/p>\n<p><em>GLCD_Read()<\/em> : Returns a byte read from the current display location. If you see the code for this subroutine, you will see there are two read operations involved. The first one is a dummy read during which the data is fetched from the display RAM is latched in to the output register of KS0108B. In the second read, the microcontroller can get the actual data.<\/p>\n<p><em>GLCD_Clrln()<\/em> : Clears a specified row (0-7).<\/p>\n<p><em>GLCD_CLR()<\/em> : Clears the whole screen (all 8 pages).<\/p>\n<p><em>Draw_Point()<\/em> : Plots a dark or light color point at a specified position.<\/p>\n<p>At the end, the dotted lines are created by plotting too many points in horizontal directions.<\/p>\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 * Copyright:\n     (c) Embedded-Lab.com, 2011.\n&nbsp;\n * Description:\n     This routine demonstrates how to initialize a KS0108 based GLCD and \n     activate the pixels on display. A sub-routine is written to draw a point on\n     the GLCD at a given coordinates.\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: #339933;\">#define GLCD_Data   PORTD<\/span>\n<span style=\"color: #339933;\">#define GLCD_Dir    TRISD<\/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> Enable_Pulse<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n   GLCD_EN <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #666666; font-style: italic;\">\/\/EN high<\/span>\n   delay_us<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">5<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n   GLCD_EN <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #666666; font-style: italic;\">\/\/EN low<\/span>\n   delay_us<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">5<\/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> GLCD_ON<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n    <span style=\"color: #666666; font-style: italic;\">\/\/Activate both chips<\/span>\n    GLCD_CS1 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n    GLCD_CS2 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n    GLCD_RS <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>          <span style=\"color: #666666; font-style: italic;\">\/\/RS low --&gt; command<\/span>\n    GLCD_RW <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>          <span style=\"color: #666666; font-style: italic;\">\/\/RW low --&gt; write<\/span>\n    GLCD_Data <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x3F<\/span><span style=\"color: #339933;\">;<\/span>         <span style=\"color: #666666; font-style: italic;\">\/\/ON command<\/span>\n    Enable_Pulse<span style=\"color: #009900;\">&#40;<\/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> Set_Start_Line<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> line<span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n    GLCD_RS <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/RS low --&gt; command<\/span>\n    GLCD_RW <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/RW low --&gt; write<\/span>\n    <span style=\"color: #666666; font-style: italic;\">\/\/Activate both chips<\/span>\n    GLCD_CS1 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n    GLCD_CS2 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n    GLCD_Data <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0xC0<\/span> <span style=\"color: #339933;\">|<\/span> line<span style=\"color: #339933;\">;<\/span>     <span style=\"color: #666666; font-style: italic;\">\/\/Set Start Line command<\/span>\n    Enable_Pulse<span style=\"color: #009900;\">&#40;<\/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> GOTO_COL<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">int<\/span> x<span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n   <span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> Col_Data<span style=\"color: #339933;\">;<\/span>\n   GLCD_RS <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/RS low --&gt; command<\/span>\n   GLCD_RW <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/RW low --&gt; write<\/span>\n   <span style=\"color: #b1b100;\">if<\/span><span style=\"color: #009900;\">&#40;<\/span>x<span style=\"color: #339933;\">&lt;<\/span><span style=\"color: #0000dd;\">64<\/span><span style=\"color: #009900;\">&#41;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/left section<\/span>\n   <span style=\"color: #009900;\">&#123;<\/span>\n      GLCD_CS1 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>          <span style=\"color: #666666; font-style: italic;\">\/\/select chip 1<\/span>\n      GLCD_CS2 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>          <span style=\"color: #666666; font-style: italic;\">\/\/deselect chip 2<\/span>\n      Col_Data <span style=\"color: #339933;\">=<\/span> x<span style=\"color: #339933;\">;<\/span>              <span style=\"color: #666666; font-style: italic;\">\/\/put column address on data port<\/span>\n   <span style=\"color: #009900;\">&#125;<\/span>\n   <span style=\"color: #b1b100;\">else<\/span>                 <span style=\"color: #666666; font-style: italic;\">\/\/right section<\/span>\n   <span style=\"color: #009900;\">&#123;<\/span>\n&nbsp;\n      GLCD_CS2 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n      GLCD_CS1 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>\n      Col_Data <span style=\"color: #339933;\">=<\/span> x<span style=\"color: #339933;\">-<\/span><span style=\"color: #0000dd;\">64<\/span><span style=\"color: #339933;\">;<\/span>   <span style=\"color: #666666; font-style: italic;\">\/\/put column address on data port<\/span>\n   <span style=\"color: #009900;\">&#125;<\/span>\n   Col_Data <span style=\"color: #339933;\">=<\/span> <span style=\"color: #009900;\">&#40;<\/span>Col_Data <span style=\"color: #339933;\">|<\/span> <span style=\"color: #208080;\">0x40<\/span> <span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #339933;\">&amp;<\/span> <span style=\"color: #208080;\">0x7F<\/span><span style=\"color: #339933;\">;<\/span>  <span style=\"color: #666666; font-style: italic;\">\/\/Command format<\/span>\n   GLCD_Data <span style=\"color: #339933;\">=<\/span> Col_Data<span style=\"color: #339933;\">;<\/span>\n   Enable_Pulse<span style=\"color: #009900;\">&#40;<\/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> GOTO_ROW<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">int<\/span> y<span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n   <span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> Col_Data<span style=\"color: #339933;\">;<\/span>\n   GLCD_RS <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>                  <span style=\"color: #666666; font-style: italic;\">\/\/RS low --&gt; command<\/span>\n   GLCD_RW <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>                  <span style=\"color: #666666; font-style: italic;\">\/\/RW low --&gt; write<\/span>\n   Col_Data <span style=\"color: #339933;\">=<\/span> <span style=\"color: #009900;\">&#40;<\/span>y <span style=\"color: #339933;\">|<\/span> <span style=\"color: #208080;\">0xB8<\/span> <span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #339933;\">&amp;<\/span> <span style=\"color: #208080;\">0xBF<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #666666; font-style: italic;\">\/\/put row address on data port set command<\/span>\n   GLCD_Data <span style=\"color: #339933;\">=<\/span> Col_Data<span style=\"color: #339933;\">;<\/span>\n   Enable_Pulse<span style=\"color: #009900;\">&#40;<\/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> GOTO_XY<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">int<\/span> x<span style=\"color: #339933;\">,<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">int<\/span> y<span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n    GOTO_COL<span style=\"color: #009900;\">&#40;<\/span>x<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n    GOTO_ROW<span style=\"color: #009900;\">&#40;<\/span>y<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> GLCD_Write<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> b<span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n   GLCD_RS <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>          <span style=\"color: #666666; font-style: italic;\">\/\/RS high --&gt; data<\/span>\n   GLCD_RW <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>          <span style=\"color: #666666; font-style: italic;\">\/\/RW low --&gt; write<\/span>\n   GLCD_Data <span style=\"color: #339933;\">=<\/span> b<span style=\"color: #339933;\">;<\/span>            <span style=\"color: #666666; font-style: italic;\">\/\/put data on data port<\/span>\n   delay_us<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n   Enable_Pulse<span style=\"color: #009900;\">&#40;<\/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;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> GLCD_Read<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> column<span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n    <span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> read_data <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #666666; font-style: italic;\">\/\/Read data here<\/span>\n    GLCD_Dir <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0xFF<\/span><span style=\"color: #339933;\">;<\/span>     <span style=\"color: #666666; font-style: italic;\">\/\/PORTD as Input<\/span>\n    GLCD_RW <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/Read<\/span>\n    GLCD_RS <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/Data<\/span>\n    GLCD_CS1 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #009900;\">&#40;<\/span>column<span style=\"color: #339933;\">&gt;<\/span><span style=\"color: #0000dd;\">63<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n    GLCD_CS2 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #339933;\">!<\/span>GLCD_CS1<span style=\"color: #339933;\">;<\/span>         <span style=\"color: #666666; font-style: italic;\">\/\/Disable\/Enable CS2<\/span>\n    delay_us<span style=\"color: #009900;\">&#40;<\/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;\">\/\/tasu<\/span>\n    GLCD_EN <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/Latch RAM data into ouput register<\/span>\n    delay_us<span style=\"color: #009900;\">&#40;<\/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;\">\/\/twl + tf<\/span>\n&nbsp;\n    <span style=\"color: #666666; font-style: italic;\">\/\/Dummy read<\/span>\n    GLCD_EN <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/Low Enable<\/span>\n    delay_us<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">5<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n    GLCD_EN <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/latch data from output register to data bus<\/span>\n    delay_us<span style=\"color: #009900;\">&#40;<\/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;\">\/\/tr + td(twh)<\/span>\n&nbsp;\n    read_data <span style=\"color: #339933;\">=<\/span> GLCD_Data<span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/Input data<\/span>\n    GLCD_EN <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>             <span style=\"color: #666666; font-style: italic;\">\/\/Low Enable to remove data from the bus<\/span>\n    delay_us<span style=\"color: #009900;\">&#40;<\/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;\">\/\/tdhr<\/span>\n    GLCD_Dir <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x00<\/span><span style=\"color: #339933;\">;<\/span>     <span style=\"color: #666666; font-style: italic;\">\/\/Output again<\/span>\n    <span style=\"color: #b1b100;\">return<\/span> read_data<span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n <span style=\"color: #993333;\">void<\/span> GLCD_Clrln<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> ln<span style=\"color: #009900;\">&#41;<\/span>\n <span style=\"color: #009900;\">&#123;<\/span>\n    <span style=\"color: #993333;\">int<\/span> i<span style=\"color: #339933;\">;<\/span>\n    GOTO_XY<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">,<\/span>ln<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>      <span style=\"color: #666666; font-style: italic;\">\/\/At start of line of left side<\/span>\n    GOTO_XY<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">64<\/span><span style=\"color: #339933;\">,<\/span>ln<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>     <span style=\"color: #666666; font-style: italic;\">\/\/At start of line of right side (Problem)<\/span>\n    GLCD_CS1 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n    <span style=\"color: #b1b100;\">for<\/span><span style=\"color: #009900;\">&#40;<\/span>i<span style=\"color: #339933;\">=<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>i<span style=\"color: #339933;\">&lt;<\/span><span style=\"color: #0000dd;\">65<\/span><span style=\"color: #339933;\">;<\/span>i<span style=\"color: #339933;\">++<\/span><span style=\"color: #009900;\">&#41;<\/span>\n    GLCD_Write<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">0<\/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: #666666; font-style: italic;\">\/\/-- -----------------------<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> GLCD_CLR<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n   <span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> m<span style=\"color: #339933;\">;<\/span>\n   <span style=\"color: #b1b100;\">for<\/span><span style=\"color: #009900;\">&#40;<\/span>m<span style=\"color: #339933;\">=<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>m<span style=\"color: #339933;\">&lt;<\/span><span style=\"color: #0000dd;\">8<\/span><span style=\"color: #339933;\">;<\/span>m<span style=\"color: #339933;\">++<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>\n    GLCD_Clrln<span style=\"color: #009900;\">&#40;<\/span>m<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n   <span style=\"color: #009900;\">&#125;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> Draw_Point<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> x<span style=\"color: #339933;\">,<\/span><span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> y<span style=\"color: #339933;\">,<\/span> <span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> color<span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n    <span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> Col_Data<span style=\"color: #339933;\">;;<\/span>\n    GOTO_XY<span style=\"color: #009900;\">&#40;<\/span>x<span style=\"color: #339933;\">,<\/span><span style=\"color: #009900;\">&#40;<\/span>y<span style=\"color: #339933;\">\/<\/span><span style=\"color: #0000dd;\">8<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n    <span style=\"color: #b1b100;\">switch<\/span> <span style=\"color: #009900;\">&#40;<\/span>color<span style=\"color: #009900;\">&#41;<\/span>\n    <span style=\"color: #009900;\">&#123;<\/span>\n        <span style=\"color: #b1b100;\">case<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">:<\/span>         <span style=\"color: #666666; font-style: italic;\">\/\/Light spot<\/span>\n            Col_Data <span style=\"color: #339933;\">=<\/span> ~<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">&lt;&lt;<\/span><span style=\"color: #009900;\">&#40;<\/span>y<span style=\"color: #339933;\">%<\/span><span style=\"color:#800080;\">8<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #339933;\">&amp;<\/span> GLCD_Read<span style=\"color: #009900;\">&#40;<\/span>x<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n        <span style=\"color: #000000; font-weight: bold;\">break<\/span><span style=\"color: #339933;\">;<\/span>\n        <span style=\"color: #b1b100;\">case<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">:<\/span>         <span style=\"color: #666666; font-style: italic;\">\/\/Dark spot<\/span>\n            Col_Data <span style=\"color: #339933;\">=<\/span> <span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">&lt;&lt;<\/span><span style=\"color: #009900;\">&#40;<\/span>y<span style=\"color: #339933;\">%<\/span><span style=\"color:#800080;\">8<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #339933;\">|<\/span> GLCD_Read<span style=\"color: #009900;\">&#40;<\/span>x<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n        <span style=\"color: #000000; font-weight: bold;\">break<\/span><span style=\"color: #339933;\">;<\/span>\n    <span style=\"color: #009900;\">&#125;<\/span>\n    GOTO_XY<span style=\"color: #009900;\">&#40;<\/span>x<span style=\"color: #339933;\">,<\/span><span style=\"color: #009900;\">&#40;<\/span>y<span style=\"color: #339933;\">\/<\/span><span style=\"color: #0000dd;\">8<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n    GLCD_Write<span style=\"color: #009900;\">&#40;<\/span>Col_Data<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  <span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> u<span style=\"color: #339933;\">,<\/span> v<span style=\"color: #339933;\">;<\/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  PORTB <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x00<\/span><span style=\"color: #339933;\">;<\/span>\n  PORTD <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x00<\/span><span style=\"color: #339933;\">;<\/span>\n  GLCD_CS1 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>                <span style=\"color: #666666; font-style: italic;\">\/\/ De-Activate both chips<\/span>\n  GLCD_CS2 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>\n  GLCD_RST <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #339933;\">;<\/span>\n  GLCD_ON<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  GLCD_CLR<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  Set_Start_Line<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  <span style=\"color: #b1b100;\">do<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n&nbsp;\n     <span style=\"color: #b1b100;\">for<\/span><span style=\"color: #009900;\">&#40;<\/span>u<span style=\"color: #339933;\">=<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span> u<span style=\"color: #339933;\">&lt;<\/span><span style=\"color: #0000dd;\">64<\/span><span style=\"color: #339933;\">;<\/span> u<span style=\"color: #339933;\">+=<\/span><span style=\"color: #0000dd;\">6<\/span><span style=\"color: #009900;\">&#41;<\/span>\n      <span style=\"color: #b1b100;\">for<\/span> <span style=\"color: #009900;\">&#40;<\/span>v<span style=\"color: #339933;\">=<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span> v<span style=\"color: #339933;\">&lt;<\/span><span style=\"color: #0000dd;\">128<\/span><span style=\"color: #339933;\">;<\/span> v<span style=\"color: #339933;\">+=<\/span><span style=\"color: #0000dd;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span>\n      Draw_Point<span style=\"color: #009900;\">&#40;<\/span>v<span style=\"color: #339933;\">,<\/span> u<span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      delay_ms<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1000<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      GLCD_CLR<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n      delay_ms<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1000<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n&nbsp;\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<p><a href=\"http:\/\/embedded-lab.com\/uploads\/HexFiles\/PIC16F887\/TestGLCD.zip\" target=\"_blank\">Download the Source code and HEX file<\/a><\/p>\n<p>When the microcontroller runs the program, you will see 11 dotted horizontal lines displayed on the screen as shown below.<\/p>\n<div id=\"attachment_4247\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/DottedLine.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4247\" class=\"size-full wp-image-4247\" title=\"DottedLine\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/DottedLine.jpg\" alt=\"\" width=\"560\" height=\"407\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/DottedLine.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/12\/DottedLine-550x399.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4247\" class=\"wp-caption-text\">Dotted horizontal lines<\/p><\/div>\n<p><strong>Summary<\/strong><\/p>\n<p>In this experimental tutorial, the internal block diagram of a KS0108 based 128&#215;64 pixel GLCD, its pin configurations, and instruction set were discussed briefly. The GLCD operation was demonstrated with a Winstar WDG0151 GLCD module interfaced to the PIC16F887 microcontroller. A very basic firmware was written in mikroC Pro for PIC to demonstrate how to activate selected pixels on the screen to draw a line. In the second part of this tutorial (will be posted soon) we will learn to use the built-in GLCD library of mikroC Pro for PIC compiler to draw more complex objects and texts on the screen.<\/p>\n<p>Second part of this tutorial is here:<\/p>\n<h3><a title=\"Permanent Link to Lab 20: Interfacing a KS0108 based Graphics LCD (Part 2)\" href=\"http:\/\/embedded-lab.com\/blog\/?p=4256\" rel=\"bookmark\">Lab 20: Interfacing a KS0108 based Graphics LCD (Part 2)<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>The use of a graphical LCD (GLCD) drastically changes the look of your project. It provides more freedom for presenting data than the HD44870 based character LCDs. Today we will see how to interface a KS0108 (name of the display controller chip) based GLCD to a PIC microcontroller. This experimental tutorial is divided into two parts. In the first part, we will see how to write a firmware for the PIC microcontroller to initialize the GLCD and send data to plot points and lines on the screen. The second part will focus more on exploring the built-in GLCD Library of<\/p>\n","protected":false},"author":1,"featured_media":2399,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,105,227,183],"tags":[158,252,365,9,316,388,387],"class_list":["post-2398","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pic-tutorials","category-pic18f","category-news","category-tips-and-tricks","tag-glcd","tag-glcd-library","tag-ks0108","tag-mikroc","tag-pic16f887","tag-wdg0151","tag-winstar"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/2398","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=2398"}],"version-history":[{"count":36,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/2398\/revisions"}],"predecessor-version":[{"id":4257,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/2398\/revisions\/4257"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/2399"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=2398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=2398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=2398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}