KS0108 Kontrolcülü GLCD Ekrana Özel simgeler yazma

Başlatan alfurkan1064, 26 Haziran 2021, 09:30:05

alfurkan1064

Merhabalar,

Başlıkta da belirttiğim gibi KS0108 kontrolcü içeren GLCD ekrana özel karakterler yazdırmak istiyorum Örnek:© ve @ bunun gibi simgeleri nasıl yapabilirim ? bilgi verirseniz memnunm olurum .

CCS C'nin kendi orjinal kütüphanelerini kullanıyorum


#include "HDM64GS12.c"
/////////////////////////////////////////////////////////////////////////
////                           HDM64GS12.c                           ////
////                                                                 ////
//// This file contains drivers for using a Hantronix HDM64GS12 with ////
//// a KS0108 display controller. The HDM64GS12 is 128 by 64 pixels. ////
//// The driver treats the upper left pixel as (0,0).                ////
////                                                                 ////
//// Use #define FAST_GLCD if the target chip has at least 1k of RAM ////
//// to decrease the time it takes to update the display.            ////
//// glcd_update() must then be called to update the display after   ////
//// changing the pixel information.                                 ////
//// See ex_glcd.c for suggested usage.                              ////
//// See KS0108.c for controlling a single 64 by 64 display          ////
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
//// LCD Pin connections:                                            ////
//// (These can be changed as needed in the following defines).      ////
////  * 1: VSS is connected to GND                                   ////
////  * 2: VDD is connected to +5V                                   ////
////  * 3: V0  - LCD operating voltage (Contrast adjustment)         ////
////  * 4: D/I - Data or Instruction is connected to B2              ////
////  * 5: R/W - Read or Write is connected to B4                    ////
////  * 6: Enable is connected to B5                                 ////
////  *7-14: Data Bus 0 to 7 is connected to port d                  ////
////  *15: Chip Select 1 is connected to B0                          ////
////  *16: Chip Select 2 is connected to B1                          ////
////  *17: Reset is connected to C0                                  ////
////  *18: Negative voltage is also connected to the 20k Ohm POT     ////
////  *19: Positive voltage for LED backlight is connected to +5V    ////
////  *20: Negative voltage for LED backlight is connected to GND    ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
////  glcd_init(mode)                                                ////
////     * Must be called before any other function.                 ////
////       - mode can be ON or OFF to turn the LCD on or off         ////
////                                                                 ////
////  glcd_pixel(x,y,color)                                          ////
////     * Sets the pixel to the given color.                        ////
////       - color can be ON or OFF                                  ////
////                                                                 ////
////  glcd_fillScreen(color)                                         ////
////     * Fills the entire LCD with the given color.                ////
////       - color can be ON or OFF                                  ////
////                                                                 ////
////  glcd_update()                                                  ////
////     * Write the display data stored in RAM to the LCD           ////
////     * Only available if FAST_GLCD is defined                    ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////  Version History                                                ////
////                                                                 ////
////  05/01/20 - Added defines to selecting the data bus port or     ////
////             pins used with this driver.                         ////
////                                                                 ////
////             GLCD_PORT - to assign the port to use for the GLCD  ////
////                 data bus pins, for example:                     ////
////                    #define GLCD_PORT    c                       ////
////                                                                 ////
////                 The above assigns it to use PORTC for the data  ////
////                 bus pins.  Driver defaults to PORTD if          ////
////                 GLCD_PORT and GLCD_DATA0 are not defined before ////
////                 this driver is included in project.             ////
////                                                                 ////
////             GLCD_DATA0 - to assign the data bus 0 pin.          ////
////                                                                 ////
////             GLCD_DATA1 - to assign the data bus 1 pin.          ////
////                                                                 ////
////             GLCD_DATA2 - to assign the data bus 2 pin.          ////
////                                                                 ////
////             GLCD_DATA3 - to assign the data bus 3 pin.          ////
////                                                                 ////
////             GLCD_DATA4 - to assign the data bus 4 pin.          ////
////                                                                 ////
////             GLCD_DATA5 - to assign the data bus 5 pin.          ////
////                                                                 ////
////             GLCD_DATA6 - to assign the data bus 6 pin.          ////
////                                                                 ////
////             GLCD_DATA7 - to assign the data bus 7 pin.          ////
////                                                                 ////
////     The defines GLCD_DATA0 to GLCD_DATA7 can only be used to    ////
////     assign the pins if GLCD_PORT is not defined.  All eight     ////
////     defines must be defined before this driver is included in   ////
////     project to make assignments.  No default defines are made   ////
////     for GLCD_DATA0 to GLCD_DATA7.                               ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996, 2020 Custom Computer Services        ////
//// This source code may only be used by licensed users of the CCS  ////
//// C compiler.  This source code may only be distributed to other  ////
//// licensed users of the CCS C compiler.  No other use,            ////
//// reproduction or distribution is permitted without written       ////
//// permission.  Derivative programs created using this software    ////
//// in object code form are not restricted in any way.              ////
/////////////////////////////////////////////////////////////////////////

#ifndef HDM64GS12
#define HDM64GS12

#ifndef concat
 #define concat(x,y)    x####y
#endif

#ifndef GLCD_WIDTH
 #define GLCD_WIDTH     128
#endif

#ifndef GLCD_CS1
 #define GLCD_CS1       PIN_B1   // Chip Selection 1
#endif

#ifndef GLCD_CS2
 #define GLCD_CS2       PIN_B2   // Chip Selection 2
#endif

#ifndef GLCD_DI
 #define GLCD_DI        PIN_B3   // Data or Instruction input
#endif

#ifndef GLCD_RW
 #define GLCD_RW        PIN_B4   // Read/Write
#endif

#ifndef GLCD_E
 #define GLCD_E         PIN_B5   // Enable
#endif

#ifndef GLCD_RST
 #define GLCD_RST       PIN_C0   // Reset
#endif

#if !defined(GLCD_PORT) && !defined(GLCD_DATA0)
 #define GLCD_PORT      d
#elif !defined(GLCD_PORT) && defined(GLCD_DATA0)
 #if !defined(GLCD_DATA1) || !defined(GLCD_DATA2) || !defined(GLCD_DATA3) || !defined(GLCD_DATA4) || \
     !defined(GLCD_DATA5) || !defined(GLCD_DATA6) || !defined(GLCD_DATA7)
  #error not all GLCD Data pins defined.
 #endif
#endif

#define GLCD_LEFT       0
#define GLCD_RIGHT      1

#ifndef ON
 #define ON             1
#endif

#ifndef OFF
 #define OFF            0
#endif

/////////////////////////////////////////////////////////////////////////
// Function Prototypes
/////////////////////////////////////////////////////////////////////////
void glcd_init(int1 mode);
void glcd_pixel(unsigned int8 x, unsigned int8 y, int1 color);
void glcd_fillScreen(int1 color);
void glcd_writeByte(int1 side, BYTE data);
BYTE glcd_readByte(int1 side);
void glcd_update();
/////////////////////////////////////////////////////////////////////////

#if defined(GLCD_PORT)
 #define WritePort(v)   concat(output_, GLCD_PORT(v))
 #define ReadPort()     concat(input_, GLCD_PORT())
 #define TrisPort(v)    concat(set_tris_, GLCD_PORT(v))
#else
 #define TrisPort(v)

 void WritePort(unsigned int8 value)
 {
   output_bit(GLCD_DATA0, bit_test(value, 0));
   output_bit(GLCD_DATA1, bit_test(value, 1));
   output_bit(GLCD_DATA2, bit_test(value, 2));
   output_bit(GLCD_DATA3, bit_test(value, 3));
   output_bit(GLCD_DATA4, bit_test(value, 4));
   output_bit(GLCD_DATA5, bit_test(value, 5));
   output_bit(GLCD_DATA6, bit_test(value, 6));
   output_bit(GLCD_DATA7, bit_test(value, 7));
 }
 
 unsigned int8 ReadPort(void)
 {
   union
   {
      unsigned int8 b;
      int1 bit[8];
   } Result;
   
   Result.bit[0] = input(GLCD_DATA0);
   Result.bit[1] = input(GLCD_DATA1);
   Result.bit[2] = input(GLCD_DATA2);
   Result.bit[3] = input(GLCD_DATA3);
   Result.bit[4] = input(GLCD_DATA4);
   Result.bit[5] = input(GLCD_DATA5);
   Result.bit[6] = input(GLCD_DATA6);
   Result.bit[7] = input(GLCD_DATA7);
   
   return(Result.b);
 } 
#endif

#ifdef FAST_GLCD
struct
{
   unsigned int8 left[512];
   unsigned int8 right[512];
} displayData;
#endif


// Purpose:       Initialize the LCD.
//                Call before using any other LCD function.
// Inputs:        OFF - Turns the LCD off
//                ON  - Turns the LCD on
void glcd_init(int1 mode)
{
   // Initialize some pins
   output_high(GLCD_RST);
   output_low(GLCD_E);
   output_low(GLCD_CS1);
   output_low(GLCD_CS2);

   output_low(GLCD_DI);                 // Set for instruction
   glcd_writeByte(GLCD_LEFT,  0xC0);    // Specify first RAM line at the top
   glcd_writeByte(GLCD_RIGHT, 0xC0);    //   of the screen
   glcd_writeByte(GLCD_LEFT,  0x40);    // Set the column address to 0
   glcd_writeByte(GLCD_RIGHT, 0x40);
   glcd_writeByte(GLCD_LEFT,  0xB8);    // Set the page address to 0
   glcd_writeByte(GLCD_RIGHT, 0xB8);

   if(mode == ON)
   {
      glcd_writeByte(GLCD_LEFT,  0x3F); // Turn the display on
      glcd_writeByte(GLCD_RIGHT, 0x3F);
   }
   else
   {
      glcd_writeByte(GLCD_LEFT,  0x3E); // Turn the display off
      glcd_writeByte(GLCD_RIGHT, 0x3E);
   }

   glcd_fillScreen(OFF);                // Clear the display

   #ifdef FAST_GLCD
   glcd_update();
   #endif
}


// Purpose:    Update the LCD with data from the display arrays
#ifdef FAST_GLCD
void glcd_update()
{
   unsigned int8 i, j;
   unsigned int8 *p1, *p2;

   p1 = displayData.left;
   p2 = displayData.right;

   // Loop through the vertical pages
   for(i = 0; i < 8; ++i)
   {
      output_low(GLCD_DI);                      // Set for instruction
      glcd_writeByte(GLCD_LEFT, 0x40);          // Set horizontal address to 0
      glcd_writeByte(GLCD_RIGHT, 0x40);
      glcd_writeByte(GLCD_LEFT, i | 0xB8);      // Set page address
      glcd_writeByte(GLCD_RIGHT, i | 0xB8);
      output_high(GLCD_DI);                     // Set for data

      // Loop through the horizontal sections
      for(j = 0; j < 64; ++j)
      {
         glcd_writeByte(GLCD_LEFT, *p1++);      // Turn pixels on or off
         glcd_writeByte(GLCD_RIGHT, *p2++);     // Turn pixels on or off
      }
   }
}
#endif


// Purpose:    Turn a pixel on a graphic LCD on or off
// Inputs:     1) x - the x coordinate of the pixel
//             2) y - the y coordinate of the pixel
//             3) color - ON or OFF
void glcd_pixel(unsigned int8 x, unsigned int8 y, int1 color)
#ifdef FAST_GLCD
{
   unsigned int8* p;
   unsigned int16 temp;
   temp =  y/8;
   temp *= 64;
   temp += x;

   if(x > 63)
   {
      p = displayData.right + temp - 64;
   }
   else
   {
      p = displayData.left + temp;
   }

   if(color)
   {
      bit_set(*p, y%8);
   }
   else
   {
      bit_clear(*p, y%8);
   }
}
#else
{
   BYTE data;
   int1 side = GLCD_LEFT;  // Stores which chip to use on the LCD

   if(x > 63)              // Check for first or second display area
   {
      x -= 64;
      side = GLCD_RIGHT;
   }

   output_low(GLCD_DI);                         // Set for instruction
   bit_clear(x,7);                              // Clear the MSB. Part of an instruction code
   bit_set(x,6);                                // Set bit 6. Also part of an instruction code
   glcd_writeByte(side, x);                     // Set the horizontal address
   glcd_writeByte(side, (y/8 & 0xBF) | 0xB8);   // Set the vertical page address
   output_high(GLCD_DI);                        // Set for data
   glcd_readByte(side);                         // Need two reads to get data
   data = glcd_readByte(side);                  //  at new address

   if(color == ON)
      bit_set(data, y%8);        // Turn the pixel on
   else                          // or
      bit_clear(data, y%8);      // turn the pixel off

   output_low(GLCD_DI);          // Set for instruction
   glcd_writeByte(side, x);      // Set the horizontal address
   output_high(GLCD_DI);         // Set for data
   glcd_writeByte(side, data);   // Write the pixel data
}
#endif


// Purpose:    Fill the LCD screen with the passed in color
// Inputs:     ON  - turn all the pixels on
//             OFF - turn all the pixels off
void glcd_fillScreen(int1 color)
#ifdef FAST_GLCD
{
   unsigned int8  data;
   unsigned int8  *p1, *p2;
   unsigned int16 i;

   p1 = displayData.left;
   p2 = displayData.right;
   data = 0xFF * color;

   for(i=0; i<512; ++i)
   {
      *p1++ = data;
      *p2++ = data;
   }
}
#else
{
   unsigned int8 i, j;

   // Loop through the vertical pages
   for(i = 0; i < 8; ++i)
   {
      output_low(GLCD_DI);                      // Set for instruction
      glcd_writeByte(GLCD_LEFT, 0b01000000);    // Set horizontal address to 0
      glcd_writeByte(GLCD_RIGHT, 0b01000000);
      glcd_writeByte(GLCD_LEFT, i | 0b10111000);// Set page address
      glcd_writeByte(GLCD_RIGHT, i | 0b10111000);
      output_high(GLCD_DI);                     // Set for data

      // Loop through the horizontal sections
      for(j = 0; j < 64; ++j)
      {
         glcd_writeByte(GLCD_LEFT, 0xFF*color);  // Turn pixels on or off
         glcd_writeByte(GLCD_RIGHT, 0xFF*color); // Turn pixels on or off
      }
   }
}
#endif


// Purpose:    Write a byte of data to the specified chip
// Inputs:     1) chipSelect - which chip to write the data to
//             2) data - the byte of data to write
void glcd_writeByte(int1 side, BYTE data)
{
   TrisPort(0x00);
   
   output_low(GLCD_RW);       // Set for writing

    if(side)                   // Choose which side to write to
      output_high(GLCD_CS2);
   else
      output_high(GLCD_CS1);

    delay_us(1);

   WritePort(data);           // Put the data on the port
   delay_us(1);
   output_high(GLCD_E);       // Pulse the enable pin
   delay_us(1);
   output_low(GLCD_E);

   output_low(GLCD_CS1);      // Reset the chip select lines
   output_low(GLCD_CS2);
}


// Purpose:    Reads a byte of data from the specified chip
// Outputs:     A byte of data read from the chip
BYTE glcd_readByte(int1 side)
{
   BYTE data;                 // Stores the data read from the LCD

   TrisPort(0xFF);            // Set port to input
   output_high(GLCD_RW);      // Set for reading

   if(side)                   // Choose which side to write to
      output_high(GLCD_CS2);
   else
      output_high(GLCD_CS1);

   delay_us(1);
   output_high(GLCD_E);       // Pulse the enable pin
   delay_us(1);
   data = ReadPort();        // Get the data from the display's output register
   output_low(GLCD_E);

   output_low(GLCD_CS1);      // Reset the chip select lines
   output_low(GLCD_CS2);
   return data;               // Return the read data
}

#endif

#include <graphics.c>
/////////////////////////////////////////////////////////////////////////
////                          graphics.c                             ////
////                                                                 ////
////   This file contains functions to draw lines, rectangles, bars, ////
////   circles and text to a display. A function which draws a       ////
////   single pixel must be defined before calling the functions in  ////
////   this file. Call it glcd_pixel(x, y, color) where x is the     ////
////   horizontal coordinate, y is the vertical coordinate, and      ////
////   color is 1 bit to turn the pixel on or off.                   ////
////                                                                 ////
////   * Note: (0, 0) is treated as the upper left corner            ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
////  glcd_line(x1, y1, x2, y2, color)                               ////
////     * Draws a line from the first point to the second point     ////
////       with the given color                                      ////
////       - color can be ON or OFF                                  ////
////                                                                 ////
////  glcd_rect(x1, y1, x2, y2, fill, color)                         ////
////     * Draws a rectangle with one corner at point (x1,y1) and    ////
////       the other corner at point (x2,y2)                         ////
////       - fill can be YES or NO                                   ////
////       - color can be ON or OFF                                  ////
////                                                                 ////
////  glcd_bar(x1, y1, x2, y2, width, color)                         ////
////     * Draws a bar (wide line) from the first point to the       ////
////       second point                                              ////
////       - width is the number of pixels wide                      ////
////       - color is ON or OFF                                      ////
////                                                                 ////
////  glcd_circle(x, y, radius, fill, color)                         ////
////     * Draws a circle with center at (x,y)                       ////
////       - fill can be YES or NO                                   ////
////       - color can be ON or OFF                                  ////
////                                                                 ////
////  glcd_text57(x, y, textptr, size, color)                        ////
////     * Write the null terminated text pointed to by textptr with ////
////       the upper left coordinate of the first character at (x,y) ////
////       Characters are 5 pixels wide and 7 pixels tall            ////
////       - size is an integer that scales the size of the text     ////
////       - color is ON or OFF                                      ////
////     * Note - This function wraps characters to the next line    ////
////              use #define GLCD_WIDTH to specify a display width  ////
////                                                                 ////
//// Defines:                                                        ////
////                                                                 ////
////  LARGE_LCD                                                      ////
////     Define to indicate that LCD has more then 255 pixels in     ////
////     either the X or Y axis.  Not defined by default.            ////
////                                                                 ////
////  Required Function:                                             ////
////                                                                 ////
////     glcd_pixel(x, y, color)                                     ////
////      * Function for drawing a pixel at the specified coordinate ////
////        (x,y).  This function should be provided by the GLCD     ////
////        driver.                                                  ////
////        - color can be ON or OFF                                 ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996, 2019 Custom Computer Services        ////
//// This source code may only be used by licensed users of the CCS  ////
//// C compiler.  This source code may only be distributed to other  ////
//// licensed users of the CCS C compiler.  No other use,            ////
//// reproduction or distribution is permitted without written       ////
//// permission.  Derivative programs created using this software    ////
//// in object code form are not restricted in any way.              ////
////                     http://www.ccsinfo.com                      ////
/////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////
#ifndef GRAPHICS_DRAWING_FUNCTIONS
#define GRAPHICS_DRAWING_FUNCTIONS
/////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////
#ifndef ON
#define ON  1
#endif

#ifndef OFF
#define OFF 0
#endif

#ifndef YES
#define YES 1
#endif

#ifndef NO
#define NO  0
#endif
/////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////
//// Defines a 5x7 font
/////////////////////////////////////////////////////////////////////////
const unsigned int8 FONT[51][5] ={0x00, 0x00, 0x00, 0x00, 0x00, // SPACE
                         0x00, 0x00, 0x5F, 0x00, 0x00, // !
                         0x00, 0x03, 0x00, 0x03, 0x00, // "
                         0x14, 0x3E, 0x14, 0x3E, 0x14, // #
                         0x24, 0x2A, 0x7F, 0x2A, 0x12, // $
                         0x43, 0x33, 0x08, 0x66, 0x61, // %
                         0x36, 0x49, 0x55, 0x22, 0x50, // &
                         0x00, 0x05, 0x03, 0x00, 0x00, // '
                         0x00, 0x1C, 0x22, 0x41, 0x00, // (
                         0x00, 0x41, 0x22, 0x1C, 0x00, // )
                         0x14, 0x08, 0x3E, 0x08, 0x14, // *
                         0x08, 0x08, 0x3E, 0x08, 0x08, // +
                         0x00, 0x50, 0x30, 0x00, 0x00, // ,
                         0x08, 0x08, 0x08, 0x08, 0x08, // -
                         0x00, 0x60, 0x60, 0x00, 0x00, // .
                         0x20, 0x10, 0x08, 0x04, 0x02, // /
                         0x3E, 0x51, 0x49, 0x45, 0x3E, // 0
                         0x00, 0x04, 0x02, 0x7F, 0x00, // 1
                         0x42, 0x61, 0x51, 0x49, 0x46, // 2
                         0x22, 0x41, 0x49, 0x49, 0x36, // 3
                         0x18, 0x14, 0x12, 0x7F, 0x10, // 4
                         0x27, 0x45, 0x45, 0x45, 0x39, // 5
                         0x3E, 0x49, 0x49, 0x49, 0x32, // 6
                         0x01, 0x01, 0x71, 0x09, 0x07, // 7
                         0x36, 0x49, 0x49, 0x49, 0x36, // 8
                         0x26, 0x49, 0x49, 0x49, 0x3E, // 9
                         0x00, 0x36, 0x36, 0x00, 0x00, // :
                         0x00, 0x56, 0x36, 0x00, 0x00, // ;
                         0x08, 0x14, 0x22, 0x41, 0x00, // <
                         0x14, 0x14, 0x14, 0x14, 0x14, // =
                         0x00, 0x41, 0x22, 0x14, 0x08, // >
                         0x02, 0x01, 0x51, 0x09, 0x06, // ?
                         0x3E, 0x41, 0x59, 0x55, 0x5E, // @
                         0x7E, 0x09, 0x09, 0x09, 0x7E, // A
                         0x7F, 0x49, 0x49, 0x49, 0x36, // B
                         0x3E, 0x41, 0x41, 0x41, 0x22, // C
                         0x7F, 0x41, 0x41, 0x41, 0x3E, // D
                         0x7F, 0x49, 0x49, 0x49, 0x41, // E
                         0x7F, 0x09, 0x09, 0x09, 0x01, // F
                         0x3E, 0x41, 0x41, 0x49, 0x3A, // G
                         0x7F, 0x08, 0x08, 0x08, 0x7F, // H
                         0x00, 0x41, 0x7F, 0x41, 0x00, // I
                         0x30, 0x40, 0x40, 0x40, 0x3F, // J
                         0x7F, 0x08, 0x14, 0x22, 0x41, // K
                         0x7F, 0x40, 0x40, 0x40, 0x40, // L
                         0x7F, 0x02, 0x0C, 0x02, 0x7F, // M
                         0x7F, 0x02, 0x04, 0x08, 0x7F, // N
                         0x3E, 0x41, 0x41, 0x41, 0x3E, // O
                         0x7F, 0x09, 0x09, 0x09, 0x06, // P
                         0x1E, 0x21, 0x21, 0x21, 0x5E, // Q
                         0x7F, 0x09, 0x09, 0x09, 0x76};// R

const unsigned int8 FONT2[44][5]={0x26, 0x49, 0x49, 0x49, 0x32, // S
                         0x01, 0x01, 0x7F, 0x01, 0x01, // T
                         0x3F, 0x40, 0x40, 0x40, 0x3F, // U
                         0x1F, 0x20, 0x40, 0x20, 0x1F, // V
                         0x7F, 0x20, 0x10, 0x20, 0x7F, // W
                         0x41, 0x22, 0x1C, 0x22, 0x41, // X
                         0x07, 0x08, 0x70, 0x08, 0x07, // Y
                         0x61, 0x51, 0x49, 0x45, 0x43, // Z
                         0x00, 0x7F, 0x41, 0x00, 0x00, // [
                         0x02, 0x04, 0x08, 0x10, 0x20, // \
                         0x00, 0x00, 0x41, 0x7F, 0x00, // ]
                         0x04, 0x02, 0x01, 0x02, 0x04, // ^
                         0x40, 0x40, 0x40, 0x40, 0x40, // _
                         0x00, 0x01, 0x02, 0x04, 0x00, // `
                         0x20, 0x54, 0x54, 0x54, 0x78, // a
                         0x7F, 0x44, 0x44, 0x44, 0x38, // b
                         0x38, 0x44, 0x44, 0x44, 0x44, // c
                         0x38, 0x44, 0x44, 0x44, 0x7F, // d
                         0x38, 0x54, 0x54, 0x54, 0x18, // e
                         0x04, 0x04, 0x7E, 0x05, 0x05, // f
                         0x08, 0x54, 0x54, 0x54, 0x3C, // g
                         0x7F, 0x08, 0x04, 0x04, 0x78, // h
                         0x00, 0x44, 0x7D, 0x40, 0x00, // i
                         0x20, 0x40, 0x44, 0x3D, 0x00, // j
                         0x7F, 0x10, 0x28, 0x44, 0x00, // k
                         0x00, 0x41, 0x7F, 0x40, 0x00, // l
                         0x7C, 0x04, 0x78, 0x04, 0x78, // m
                         0x7C, 0x08, 0x04, 0x04, 0x78, // n
                         0x38, 0x44, 0x44, 0x44, 0x38, // o
                         0x7C, 0x14, 0x14, 0x14, 0x08, // p
                         0x08, 0x14, 0x14, 0x14, 0x7C, // q
                         0x00, 0x7C, 0x08, 0x04, 0x04, // r
                         0x48, 0x54, 0x54, 0x54, 0x20, // s
                         0x04, 0x04, 0x3F, 0x44, 0x44, // t
                         0x3C, 0x40, 0x40, 0x20, 0x7C, // u
                         0x1C, 0x20, 0x40, 0x20, 0x1C, // v
                         0x3C, 0x40, 0x30, 0x40, 0x3C, // w
                         0x44, 0x28, 0x10, 0x28, 0x44, // x
                         0x0C, 0x50, 0x50, 0x50, 0x3C, // y
                         0x44, 0x64, 0x54, 0x4C, 0x44, // z
                         0x00, 0x08, 0x36, 0x41, 0x41, // {
                         0x00, 0x00, 0x7F, 0x00, 0x00, // |
                         0x41, 0x41, 0x36, 0x08, 0x00, // }
                         0x02, 0x01, 0x02, 0x04, 0x02};// ~
/////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////
// Purpose:       Draw a line on a graphic LCD using Bresenham's
//                line drawing algorithm
// Inputs:        (x1, y1) - the start coordinate
//                (x2, y2) - the end coordinate
//                color - ON or OFF
// Dependencies:  glcd_pixel()
/////////////////////////////////////////////////////////////////////////
#ifdef LARGE_LCD
void glcd_line(unsigned int16 x1, unsigned int16 y1, unsigned int16 x2, unsigned int16 y2, int1 color)
#else
void glcd_line(unsigned int8 x1, unsigned int8 y1, unsigned int8 x2, unsigned int8 y2, int1 color)
#endif
{
   unsigned int16        dy, dx;
   signed int8  addx=1, addy=1;
   signed int16 P, diff;

   #ifdef LARGE_LCD
   unsigned int16 i=0;
   dx = abs((signed int16)(x2 - x1));
   dy = abs((signed int16)(y2 - y1));
   #else
   unsigned int8 i=0;
   dx = abs((signed int8)(x2 - x1));
   dy = abs((signed int8)(y2 - y1));
   #endif

   if(x1 > x2)
      addx = -1;
   if(y1 > y2)
      addy = -1;

   if(dx >= dy)
   {
      dy *= 2;
      P = dy - dx;
      diff = P - dx;

      for(; i<=dx; ++i)
      {
         glcd_pixel(x1, y1, color);

         if(P < 0)
         {
            P  += dy;
            x1 += addx;
         }
         else
         {
            P  += diff;
            x1 += addx;
            y1 += addy;
         }
      }
   }
   else
   {
      dx *= 2;
      P = dx - dy;
      diff = P - dy;

      for(; i<=dy; ++i)
      {
         glcd_pixel(x1, y1, color);

         if(P < 0)
         {
            P  += dx;
            y1 += addy;
         }
         else
         {
            P  += diff;
            x1 += addx;
            y1 += addy;
         }
      }
   }
}


/////////////////////////////////////////////////////////////////////////
// Purpose:       Draw a rectangle on a graphic LCD
// Inputs:        (x1, y1) - the start coordinate
//                (x2, y2) - the end coordinate
//                fill  - YES or NO
//                color - ON or OFF
// Dependencies:  glcd_pixel(), glcd_line()
/////////////////////////////////////////////////////////////////////////
#ifdef LARGE_LCD
void glcd_rect(unsigned int16 x1, unsigned int16 y1, unsigned int16 x2, unsigned int16 y2, int1 fill, int1 color)
#else
void glcd_rect(unsigned int8 x1, unsigned int8 y1, unsigned int8 x2, unsigned int8 y2, int1 fill, int1 color)
#endif
{
   if(fill)
   {
      #ifdef LARGE_LCD
      unsigned int16 i, xmin, xmax, ymin, ymax;
      #else
      unsigned int8  i, xmin, xmax, ymin, ymax;
      #endif

      if(x1 < x2)                            //  Find x min and max
      {
         xmin = x1;
         xmax = x2;
      }
      else
      {
         xmin = x2;
         xmax = x1;
      }

      if(y1 < y2)                            // Find the y min and max
      {
         ymin = y1;
         ymax = y2;
      }
      else
      {
         ymin = y2;
         ymax = y1;
      }

      for(; xmin <= xmax; ++xmin)
      {
         for(i=ymin; i<=ymax; ++i)
         {
            glcd_pixel(xmin, i, color);
         }
      }
   }
   else
   {
      glcd_line(x1, y1, x2, y1, color);      // Draw the 4 sides
      glcd_line(x1, y2, x2, y2, color);
      glcd_line(x1, y1, x1, y2, color);
      glcd_line(x2, y1, x2, y2, color);
   }
}

/////////////////////////////////////////////////////////////////////////
// Purpose:       Draw a bar (wide line) on a graphic LCD
// Inputs:        (x1, y1) - the start coordinate
//                (x2, y2) - the end coordinate
//                width  - The number of pixels wide
//                color - ON or OFF
/////////////////////////////////////////////////////////////////////////
#ifdef LARGE_LCD
void glcd_bar(unsigned int16 x1, unsigned int16 y1, unsigned int16 x2, unsigned int16 y2, unsigned int8 width, int1 color)
#else
void glcd_bar(unsigned int8 x1, unsigned int8 y1, unsigned int8 x2, unsigned int8 y2, unsigned int8 width, int1 color)
#endif
{
   unsigned int8         half_width;
   signed int16 dy, dx;
   signed int8  addx=1, addy=1, j;
   signed int16 P, diff, c1, c2;

   #ifdef LARGE_LCD
   unsigned int16 i=0;
   dx = abs((signed int16)(x2 - x1));
   dy = abs((signed int16)(y2 - y1));
   #else
   unsigned int8 i=0;
   dx = abs((signed int8)(x2 - x1));
   dy = abs((signed int8)(y2 - y1));
   #endif

   half_width = width/2;
   c1 = -(dx*x1 + dy*y1);
   c2 = -(dx*x2 + dy*y2);

   if(x1 > x2)
   {
      signed int16 temp;
      temp = c1;
      c1 = c2;
      c2 = temp;
      addx = -1;
   }
   if(y1 > y2)
   {
      signed int16 temp;
      temp = c1;
      c1 = c2;
      c2 = temp;
      addy = -1;
   }

   if(dx >= dy)
   {
      P = 2*dy - dx;
      diff = P - dx;

      for(i=0; i<=dx; ++i)
      {
         for(j=-half_width; j<half_width+width%2; ++j)
         {
               glcd_pixel(x1, y1+j, color);
         }
         if(P < 0)
         {
            P  += 2*dy;
            x1 += addx;
         }
         else
         {
            P  += diff;
            x1 += addx;
            y1 += addy;
         }
      }
   }
   else
   {
      P = 2*dx - dy;
      diff = P - dy;

      for(i=0; i<=dy; ++i)
      {
         if(P < 0)
         {
            P  += 2*dx;
            y1 += addy;
         }
         else
         {
            P  += diff;
            x1 += addx;
            y1 += addy;
         }
         for(j=-half_width; j<half_width+width%2; ++j)
         {
               glcd_pixel(x1+j, y1, color);
         }
      }
   }
}


/////////////////////////////////////////////////////////////////////////
// Purpose:       Draw a circle on a graphic LCD
// Inputs:        (x,y) - the center of the circle
//                radius - the radius of the circle
//                fill - YES or NO
//                color - ON or OFF
/////////////////////////////////////////////////////////////////////////
#ifdef LARGE_LCD
void glcd_circle(unsigned int16 x, unsigned int16 y, unsigned int16 radius, int1 fill, int1 color)
#else
void glcd_circle(unsigned int8 x, unsigned int8 y, unsigned int8 radius, int1 fill, int1 color)
#endif
{
   #ifdef LARGE_LCD
   signed int16 a, b, P;
   #else
   signed int8  a, b, P;
   #endif

   a = 0;
   b = radius;
   P = 1 - radius;

   do
   {
      if(fill)
      {
         glcd_line(x-a, y+b, x+a, y+b, color);
         glcd_line(x-a, y-b, x+a, y-b, color);
         glcd_line(x-b, y+a, x+b, y+a, color);
         glcd_line(x-b, y-a, x+b, y-a, color);
      }
      else
      {
         glcd_pixel(a+x, b+y, color);
         glcd_pixel(b+x, a+y, color);
         glcd_pixel(x-a, b+y, color);
         glcd_pixel(x-b, a+y, color);
         glcd_pixel(b+x, y-a, color);
         glcd_pixel(a+x, y-b, color);
         glcd_pixel(x-a, y-b, color);
         glcd_pixel(x-b, y-a, color);
      }

      if(P < 0)
         P += 3 + 2 * a++;
      else
         P += 5 + 2 * (a++ - b--);
    } while(a <= b);
}


/////////////////////////////////////////////////////////////////////////
// Purpose:       Write text on a graphic LCD
// Inputs:        (x,y) - The upper left coordinate of the first letter
//                textptr - A pointer to an array of text to display
//                size - The size of the text: 1 = 5x7, 2 = 10x14, ...
//                color - ON or OFF
/////////////////////////////////////////////////////////////////////////
#ifdef LARGE_LCD
void glcd_text57(unsigned int16 x, unsigned int16 y, char* textptr, unsigned int8 size, int1 color)
#else
void glcd_text57(unsigned int8 x, unsigned int8 y, char* textptr, unsigned int8 size, int1 color)
#endif
{
   unsigned int8 j, k, l, m;                       // Loop counters
   unsigned int8 pixelData[5];                     // Stores character data

   for(; *textptr != '\0'; ++textptr, ++x)// Loop through the passed string
   {
      if(*textptr < 'S') // Checks if the letter is in the first font array
         memcpy(pixelData, FONT[*textptr - ' '], 5);
      else if(*textptr <= '~') // Check if the letter is in the second font array
         memcpy(pixelData, FONT2[*textptr - 'S'], 5);
      else
         memcpy(pixelData, FONT[0], 5);   // Default to space

      // Handles newline and carriage returns
      switch(*textptr)
      {
         case '\n':
            y += 7*size + 1;
            continue;
         case '\r':
            x = 0;
            continue;
      }

      if(x+5*size >= GLCD_WIDTH)          // Performs character wrapping
      {
         x = 0;                           // Set x at far left position
         y += 7*size + 1;                 // Set y at next position down
      }
      for(j=0; j<5; ++j, x+=size)         // Loop through character byte data
      {
         for(k=0; k < 7; ++k)             // Loop through the vertical pixels
         {
            if(bit_test(pixelData[j], k)) // Check if the pixel should be set
            {
               for(l=0; l < size; ++l)    // These two loops change the
               {                          // character's size
                  for(m=0; m < size; ++m)
                  {
                     glcd_pixel(x+m, y+k*size+l, color); // Draws the pixel
                  }
               }
            }
         }
      }
   }
}

#endif

RaMu

glcd_pixel fonksiyonunu kullanarak kendin resim çiziyormuş gibi nokta nokta ekrana istediğini basabilirsin.

Daha kolayı,
graphics.c içindeki FONT dizisini modifiye ederek yapabilirsin.
Kullanmadığın bir karakteri istediğin simgeyi yazacak şekilde düzenleyeceksin.
Mesela OR simgesi | nin bulunduğu satırı © simgesini basacak şekilde düzenle,
artık ana programında glcd ye | yaz dediğinde © simgesini yazar.

Font tablosu şöyle düzenlenmiş:
0x00, 0x00, 0x7F, 0x00, 0x00, // |

bit7 bit7 bit7 bit7 bit7
bit6
bit5
bit4
bit3
bit2
bit1
bit0 bit0 bit0 bit0 bit0

| için düşünürsek 0 olan yerler boş, 1 olan yerlere nokta koyar ve şu şekil çıkar
0x7F = 0b0111 1111
00000
00100
00100
00100
00100
00100
00100
00100

Sende © simgesi için hangi değer çıkıyor bulacaksın.

Kütüphane zaten @ simgesini yazabiliyor.
Sorularınıza hızlı cevap alın: http://www.picproje.org/index.php/topic,57135.0.html

alfurkan1064

Değerli yorumunuz için teşekkür ederim Ramu hocam,bir sualim daha olucak GLCD olarak hangi kontrolcülü ekranı önerirsiniz "KS0108" mi ? yoksa "ST7920"OLANIMI ?

RaMu

Deneyip başarıp sonucu paylaşırsan teşekkürün kabul olur :)

Güzel renkli tft vs. bir ekran öneririm.
Sorularınıza hızlı cevap alın: http://www.picproje.org/index.php/topic,57135.0.html

alfurkan1064

#4
ST7920 Kullanmak zorunda kaldım hocam "KS0108" piyasada yok gibi bişey bi kaç yerde 1 2 adet stok bulabildim,lakin ekrana bir türlü görüntü alamıyorum hocam.

proteus çizimi:

Proteus Sürümü:8.11 - 7.7 -8.6 Üç sürümdede denedim


Main
#include <18F45K50.h>
#fuses HSH,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOMCLR,NOBROWNOUT,NOPUT,NOWDT,NODEBUG,NOLVP,NOWRTD,NOPLLEN,NOCPUDIV
#use delay(clock=20Mhz)

#use FAST_IO(A)
#use FAST_IO(B)
#use FAST_IO(c)


const int8 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, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x3b, 0xb0, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0xec, 0x8e, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x03, 0xf7, 0x6b, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x07, 0xbd, 0xb1, 0x40, 0x00, 0x00,
    0x00, 0x00, 0x0f, 0xf7, 0xdd, 0xc0, 0x00, 0x00,
    0x00, 0x00, 0x1f, 0xff, 0x6a, 0xb0, 0x00, 0x00,
    0x00, 0x00, 0x1e, 0xff, 0xdb, 0x68, 0x00, 0x00,
    0x00, 0x00, 0x3f, 0xdd, 0xfe, 0xf0, 0x00, 0x00,
    0x00, 0x00, 0x37, 0xff, 0xb7, 0xa8, 0x00, 0x00,
    0x00, 0x00, 0x3e, 0xd5, 0x5a, 0xfc, 0x00, 0x00,
    0x00, 0x00, 0x7f, 0x6a, 0x4b, 0x74, 0x00, 0x00,
    0x00, 0x00, 0x36, 0x91, 0x29, 0x7c, 0x00, 0x00,
    0x00, 0x00, 0x3e, 0x44, 0x95, 0x5a, 0x00, 0x00,
    0x00, 0x00, 0x3d, 0x11, 0x24, 0xfc, 0x00, 0x00,
    0x00, 0x00, 0x3e, 0xa4, 0x4a, 0xb8, 0x00, 0x00,
    0x00, 0x00, 0x36, 0x91, 0x25, 0x5c, 0x00, 0x00,
    0x00, 0x00, 0x3e, 0xbc, 0x9f, 0xb8, 0x00, 0x00,
    0x00, 0x00, 0x1d, 0x46, 0x51, 0x58, 0x00, 0x00,
    0x00, 0x00, 0x0d, 0x79, 0x2e, 0xb4, 0x00, 0x00,
    0x00, 0x00, 0x26, 0x54, 0x95, 0x90, 0x00, 0x00,
    0x00, 0x00, 0x0a, 0x0a, 0x52, 0xb4, 0x00, 0x00,
    0x00, 0x00, 0x12, 0xa0, 0xa4, 0x94, 0x00, 0x00,
    0x00, 0x00, 0x0a, 0x4a, 0x2a, 0xa8, 0x00, 0x00,
    0x00, 0x00, 0x05, 0x01, 0x51, 0x50, 0x00, 0x00,
    0x00, 0x00, 0x05, 0x54, 0x2a, 0x20, 0x00, 0x00,
    0x00, 0x00, 0x02, 0x09, 0x55, 0x50, 0x00, 0x00,
    0x00, 0x00, 0x01, 0xa2, 0xa9, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x01, 0x10, 0x2a, 0x80, 0x00, 0x00,
    0x00, 0x00, 0x01, 0xab, 0xac, 0x80, 0x00, 0x00,
    0x00, 0x00, 0x01, 0x44, 0x15, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x01, 0x92, 0xaa, 0x80, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x24, 0xaa, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x28, 0x94, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x22, 0x4a, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x14, 0x2a, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x4a, 0xaa, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x21, 0x55, 0x40, 0x00, 0x00,
    0x00, 0x00, 0x02, 0x09, 0x55, 0x30, 0x00, 0x00,
    0x00, 0x00, 0x02, 0x10, 0x52, 0x30, 0x00, 0x00,
    0x00, 0x00, 0x0e, 0x05, 0x0a, 0x18, 0x00, 0x00,
    0x00, 0x00, 0x1f, 0x00, 0x54, 0x0d, 0x00, 0x00,
    0x00, 0x00, 0x56, 0x01, 0x24, 0x0d, 0x50, 0x00,
    0x00, 0x02, 0xff, 0x00, 0x48, 0x06, 0xd4, 0x00,
    0x00, 0x0d, 0xb5, 0x00, 0x10, 0x0b, 0x6b, 0xa0,
    0x00, 0x77, 0xff, 0x80, 0x00, 0x06, 0xbd, 0x50,
    0x03, 0x5b, 0x57, 0x00, 0x7c, 0x87, 0xee, 0xfc,
    0x1d, 0xef, 0xfd, 0x80, 0x9e, 0x06, 0xb7, 0xaf
};


#define FAST_GLCD
#include "st7920.h"
#include <graphics.c>


void main()
{
set_tris_a(0x01);set_tris_b(0x00);set_tris_c(0x00);set_tris_d(0x00);set_tris_e(0x01);
output_a(0x00); output_b(0x00); output_c(0x00); output_d(0x00);
setup_comparator(NC_NC_NC_NC);
setup_dac(DAC_OFF);
//setup_uart(FALSE);
setup_spi(spi_disabled);

setup_ccp1(CCP_OFF);setup_ccp2(CCP_OFF);

glcd_init_GRAPH();


while(true)
{

  
      glcd_fillscreen(ON);
      glcd_update();
      delay_ms(1000);
    
      glcd_fillscreen(OFF);
      glcd_update();
      delay_ms(1000);
    
      glcd_plot_image(60,50,0,0,0);
      glcd_update();
      delay_ms(1000);


}
}


alfurkan1064

st7920
// change the pin assignment depending on your circuit

#define  rs  PIN_C0                    //COMMNAD/DATA SELECT
#define  rw  PIN_C1                    //READ/WRITE SELECT             
#define  e   PIN_C2                    //ENABLE SIGNAL                 
#define  rst PIN_C6                    //RESET SIGNAL   

#define ON   1
#define OFF   0
#define XVAL 16  // 16 X 16 or 256 for there is 8 word values for the upper and lower
#define YVAL 32

// PSB is tied to Vcc for this driver because this driver uses Parallel
// operation.
// data is sent using port B so change output_b() to other ports you
//want to use. Dont for get to change the Busy pin @ lcd_check_busy

#define GLCD_WIDTH   128



//////////////////////////////////////////////////////////////////////////////////
//The following are the functions included in this driver file
// glcd_readbyte();
// glcd_instruction( instruction );
// glcd_data( data ); - data can be an array of characters!
// glcd_check_busy();
// glcd_update(); -must be called always after writing a pixel or using functions
//                 from GRAPHICS.C .. Only applicaticable in Graphing mode
// glcd_fillscreen( ON or OFF);
// glcd_init_graph(); initialize for graphing mode
// glcd_init_basic(); initilize for accessing the stored Characters
//                     you can use glcd_data() for writing text
// glcd_pixel(x coordinate, y coordinate, ON or OFF); 
//            -WORKS WITH GRAPHIC.C  from CCS Drivers
// glcd_plot_image(width,height,X coor, Y coor, inverse);
//            -plots the image[] array. Declare it first before this driver.
//             or modify this driver
//
//////////////////////////////////////////////////////////////////////////////////



typedef union
{
  int16 word;
  int8 nbyte[2];
} Dots;

typedef struct
{
  int1 refresh;
  Dots pix[YVAL][XVAL];   // Max dimensions for display (x,y) = (128,32)
  } GD_RAM;             //  (0,0) corresponds to upper lefthand corner.

GD_RAM gdram;


unsigned int8 glcd_readByte (unsigned int1 address)
{
  unsigned int8 data;   // Stores the data read from the LCD
  if(address==1){
     output_high(rs);
  }
  if(address==0){
     output_low(rs);
  }
  output_high(rw);//GLCD_RW = RW_READ;      // Set for reading
  output_high(e);//GLCD_E = 1;      // Pulse the enable pin
  delay_us(1);
  data=input_b();      // Get the data from the display's output register
  output_low(e);//GLCD_E = 0;
  return (data);
}

 
void glcd_check_busy(){
   int1 busy=1;
   output_low(rs);      // LOW RS and High RW will put the lcd to
   output_high(rw);      // read busy flag and address counter
   while(busy){         // will cycle until busy flag is 0
      output_high(e);
      if(!input(PIN_B7)){
         busy=0;
      }
      output_low(e);
   }
}
 
void glcd_instruction(unsigned char x){
   glcd_check_busy();      //must be satisfied before sending instruction
   output_low(rs);      // LOW RS and LOW RW will put the lcd to
   output_low(rw);      // Write instruction mode
   output_b(x);         // 8bit data to bus
   output_high(e);      // enable
   delay_us(1);       
   output_low(e);      // disable
}
void glcd_data(unsigned char x){
   glcd_check_busy();
   output_high(rs);      // HIGH RS and LOW RW will put the lcd to
   output_low(rw);      // Write data register mode
   output_b(x);
   output_high(e);
   delay_us(1);
   output_low(e);
}
 

void glcd_fillScreen (unsigned int1 color)
{
  int8 v, h;
  int16 d;


  d = (color == ON ? 0xFFFFL : 0x0000L);

  for (v=0; v < YVAL; v++)
  {
    for (h=0; h < XVAL; h++)
    {
      gdram.pix[v][h].word = d;
    }
  }
  gdram.refresh = TRUE;
}


void glcd_update ()
{
  int8 v, h;


  if (gdram.refresh)
  {
    for (v=0; v <YVAL; v++)
    {
      glcd_instruction( 0x80 | v);   // Set Vertical Address.
      glcd_instruction( 0x80 | 0);   // Set Horizontal Address.

      for (h=0; h <XVAL; h++)
      {
        glcd_data( gdram.pix[v][h].nbyte[1]);   // Write High Byte.
        glcd_data(  gdram.pix[v][h].nbyte[0]);   // Write Low Byte.
      }
    }
    gdram.refresh = FALSE;
  }
}

void glcd_init_graph(){
   delay_ms(40);
   output_low(rst);         //reset LCD
   delay_us(1);                     
   output_high(rst);        //LCD normal operation
   glcd_instruction(0x30);   //set 8 bit operation and basic instruction set
   delay_us(144);
   glcd_instruction(0x0C);   //display on cursor off and char blink off
   delay_us(100);
   glcd_instruction(0x01);   //display clear
   delay_ms(10);
   glcd_instruction(0x06);   //entry mode set
   delay_us(72);                 
  glcd_instruction(0x34);    // Select extended instruction set.
  delay_ms (10);
  glcd_instruction(0x36);    // Graphic display ON.
  delay_ms (10);

  glcd_fillScreen (OFF);
  glcd_update ();

}

void glcd_init_basic(){
   delay_ms(40);
   output_low(rst);         //reset LCD
   delay_us(1);                     
   output_high(rst);        //LCD normal operation
   glcd_instruction(0x30);   //set 8 bit operation and basic instruction set
   delay_us(144);
   glcd_instruction(0x0C);   //display on cursor off and char blink off
   delay_us(100);
   glcd_instruction(0x01);   //display clear
   delay_ms(10);
   glcd_instruction(0x06);   //entry mode set
   delay_us(72);                 
}

void glcd_pixel(int8 x, int8 y, int1 color)
{
  int8 v, h, b;
  if(y>31){x += 128; y-= 32;};
  v = y;
  h = x/16;
  b = 15 - (x%16);
 
  if (color == ON) bit_set (gdram.pix[v][h].word, b);
  else bit_clear (gdram.pix[v][h].word, b);

  gdram.refresh = TRUE;
}

void glcd_plot_image(int width,int height,int x,int y,int inverse)
{
   unsigned int i=0, j=0, k=0;
   unsigned int16 count=0;
   //glcd_fillScreen(OFF);                        //Clears the screen (opt.)
   for(j=0;j<height;j++)
      {   
         for(;i<width;)
         {
            for(k=8;k>0;k--){
               if(inverse)glcd_pixel(i+x,j+y,~bit_test(image[count],(k-1)));
               else glcd_pixel(i+x,j+y,bit_test(image[count],(k-1)));
               
               i++;
            }
            count++;
         }
      i=0;
      }
}
//credits to http://www.ccsinfo.com/forum/viewtopic.php?t=32819&highlight=st7920//
///////////////////////////////////////////////////////////////////////////////////