Selasa, 28 Agustus 2012

KS0108 GLCD with ATmega16


In this tutorial we are going to explain how to interface the graphical LCD with ATmega16 microcontroller and the compiler used is codevision avr. The GLCD used is 128x64 pixel with KS0108 driver.
Since old compilers of codevision doesn't include library for GLCD. Then you have to download the KS0108 GLCD library and you can download it HERE
This library supports English and Arabic and we are going to explain how to use this library in the following steps.

1-Adding The Library to your codevision compiler :

After downloading the files extract them and go to the folder of your installed codevision avr and default it will be in drive c with folder named cvavr2 >> open it copy the files downloaded in the folder named (inc).

2-including the library in your project and configuring connections :

Make a new project and include the GLCD library by writing #include <glcd.h> and the press build all project so that the library is included to modify the connections as shown :


Now you will find that the library is included in the code navigator tab at your left ( see the arrow ) now press on glcd.h to define the PORTS to be connected with LCD as shown in the next figure :


In line1 : Define the PORT for data ( in example we use PORTA , but it can be replaced by any PORT )
In line2 : As PORTA is selected then write DDRA (direction of dataport)
In line3 : As PORTA is selected then write PINA
Line 4 to 8 define the pins of the control signals of the GLCD, you can choose any pin ( in example we used the 1st 5 pins of PORTB )
The last line #define CS_ACTIVE_LOW is used if the control signals cs1 and cs2 are active low, if they are active high this line is commented.

The last thing is to set the used PORTS in connection as OUTPUT pins :
DATADDR = 0xff;              // define data port as output
DDRB = 0x3f;                     // define control pins as output

The connection of the GLCD is shown in the following figure :


3- How to use the library (functions):

In this step we will explain how to use the library and it's functions :

Method
Description
Parameters
glcd_on()
Turn on the GLCD
No
glcd_off()
Turn off the GLCD
No
set_start_line(unsigned char line)
Changes the top line on the display
line: line number to be set at the top (Range: 0 - 63)
goto_col(unsigned int x)
Go to the specified column
x: Column number
(Range: 0 - 127)
goto_row(unsigned int y)
Go to the specified
row 
y: Row address
(Range: 0 - 7)
goto_xy(unsigned int x, unsigned ,int y)
Go to the specified column and row
x: Column number
y: Row address
glcd_write(unsigned char b)
Writes 1 byte data at the
current location
b: 1 – byte data to be written at the current
location
glcd_clrln(unsigned char ln)
Clears the specified row 
ln: the number of the row to be cleared (Range: 0 - 7)
glcd_clear()
Clears the display
No
glcd_read(unsigned char column)
Reads the byte at the current position
column: Current column number 
point_at(
unsigned int x,
unsigned int y,
byte color)
Adds a point at the specified location
x: column number
y: row number
color: 0 : Light spot
         1 : Dark spot
h_line(
unsigned int x,unsigned int y, byte l,byte s,byte c)
Draws a horizontal line
x: The column number at which the line starts
y: The row number at which the line starts
l: Line length
s: The space between line points:
    0 = solid line
    1 = dotted line
  >1 = dashed line
c:  0 = Light spots
     1= Dark spots
v_line(
unsigned int x,unsigned int y, signed int l,byte s,byte c)
Draws a vertical line
x: The column number at which the line starts
y: The row number at which the line starts
l: Line length
s: The space between line points:
    0 = solid line
    1 = dotted line
  >1 = dashed line
c:  0 = Light spots
     1 = Dark spots
line(unsigned int x1,unsigned int y1, unsigned int x2,unsigned int y2, byte s,byte c)
Draws a general (inclined) line
x1: The column number at which the line starts
y1: The row number at which the line starts
x2: The column number at which the line ends
y2: The row number at which the line ends
s: The space between line points:
    0 = solid line
    1 = dotted line
  >1 = dashed line
c:  0 = Light spots
     1 = Dark spots
rectangle(
unsigned int x1,unsigned int y1, unsigned int x2,unsigned int y2,
               byte s,byte c)
Draws a rectangle
x1: The x of the upper left point
y1: The y of the upper left point
x2: The x of the lower right point
y2: The y of the lower right point
s: The space between each line points:
    0 = solid line
    1 = dotted line
  >1 = dashed line
c:  0 = Light spots
     1 = Dark spots
cuboid(
unsigned int x11,unsigned int y11, unsigned int x12,unsigned int y12,
unsigned int x21,unsigned int y21,
unsigned int x22,unsigned int y22,
        byte s,byte c)
Draws a cuboid by defining two surfaces
x11: The x of the upper left point of the first surface
y11: The y of the upper left point of the first surface
x12: The x of the lower right point of the first surface
y12: The y of the lower right point of the first surface
X21: The x of the upper left point of the second surface
Y21: The y of the upper left point of the second surface
x22: The x of the lower right point of the second surface
y22: The y of the lower right point of the second surface
s: The space between each line points:
    0 = solid line
    1 = dotted line
  >1 = dashed line
c:  0 = Light spots
     1 = Dark spots
h_parallelogram(
unsigned int x1,unsigned int y1,
unsigned int x2,unsigned int y2,
byte l,byte s,byte c)
Draws a parallelogram its upper and lower sides are horizontal
x1: The x of the upper left point
y1: The y of the upper left point
x2: The x of the lower right point
y2: The y of the lower right point
l: The length of the horizontal side (upper or lower)
s: The space between each line points:
    0 = solid line
    1 = dotted line
  >1 = dashed line
c:  0 = Light spots
     1 = Dark spots
v_parallelogram(
unsigned int x1,unsigned int y1,
unsigned int x2,unsigned int y2,
 byte l,byte s,byte c)
Draws a parallelogram its right and left sides are vertical
x1: The x of the upper left point
y1: The y of the upper left point
x2: The x of the lower right point
y2: The y of the lower right point
l: The length of the vertical side (right or left)
s: The space between each line points:
    0 = solid line
    1 = dotted line
  >1 = dashed line
c:  0 = Light spots
     1 = Dark spots
h_parallelepiped(
unsigned int x11,unsigned int y11,
unsigned int x12,unsigned int y12,
byte l1,
unsigned int x21,unsigned int y21, unsigned int x22,unsigned int y22,
byte l2,
byte s,byte c)
Draws a parallelepiped its bases are two horizontal parallelograms
(Seeh_parallelogram)
x11: The x of the upper left point of the first surface
y11: The y of the upper left point of the first surface
x12: The x of the lower right point of the first surface
y12: The y of the lower right point of the first surface
X21: The x of the upper left point of the second surface
Y21: The y of the upper left point of the second surface
x22: The x of the lower right point of the second surface
y22: The y of the lower right point of the second surface
s: The space between each line points:
    0 = solid line
    1 = dotted line
  >1 = dashed line
c:  0 = Light spots
     1 = Dark spots
l1: The length of the horizontal side of the first surface
l2: The length of the horizontal side of the second surface
v_parallelepiped(
unsigned int x11,unsigned int y11,
unsigned int x12,unsigned int y12, byte l1,
unsigned int x21,unsigned int y21,
unsigned int x22,unsigned int y22, byte l2,
byte s,byte c)
Draws a parallelepiped its bases are two vertical parallelograms
(Seev_parallelogram)
x11: The x of the upper left point of the first surface
y11: The y of the upper left point of the first surface
x12: The x of the lower right point of the first surface
y12: The y of the lower right point of the first surface
X21: The x of the upper left point of the second surface
Y21: The y of the upper left point of the second surface
x22: The x of the lower right point of the second surface
y22: The y of the lower right point of the second surface
s: The space between each line points:
    0 = solid line
    1 = dotted line
  >1 = dashed line
c:  0 = Light spots
     1 = Dark spots
l1: The length of the vertical side of the first surface
l2: The length of the vertical side of the second surface
circle(
unsigned int x0,unsigned int y0,
unsigned int r,byte s,byte c)
Draws a circle
x0: The x point of the center of the circle
y0: The y point of the center of the circle
r: Circle’s radius
s: The space between perimeter points:
    0 = solid line
    1 = dotted line
  >1 = dashed line
c:  0 = Light spots
     1 = Dark spots
glcd_putchar(byte c,int x,int y,byte l, byte sz)
Writes a character at the specified position, with size sz
c: The character to be typed
x: The column number to start typing the character at (One character occupies 8 columns)
y: The row number to type the character at
l: The language of the character
   0 = English
   1 = Arabic
sz: Font size (from 1 to 7)
glcd_puts(
byte *c,int x,int y,unsigned char l, byte sz,signed char space)
Writes a string ,stored in the flash memory ,on the display
c: A pointer to the string to be written on the display
x: The column number to start typing the character at (One character occupies 8 columns)
y: The row number to type the character at
l: The language of the character
   0 = English
   1 = Arabic
sz: Font size (from 1 to 7)
space:
English: Character spacing
Arabic and Farsi:Word spacing
bmp_disp(flash byte *bmp,
unsigned int x1,unsigned int y1,
unsigned int x2,unsigned int y2)
Displays a bmp image array stored in the flash memory
bmp: A pointer to the array where the bmp image is stored
x1: The x of the upper left point of the image on the glcd
y1: The y of the upper left point of the image on the glcd
x2: The x of the lower right point of the image on the glcd
y2: The y of the lower right point of the image on the glcd

Examples :

h_line(1,1,20,0,0) à Draws bright horizontal line
h_line(1,1,20,0,1) à Draws dark horizontal line

Writing Arabic and English texts :

#pragma used+
char ar_string[] = "بسم الله الرحمن الرحيم";   
char en_string[] = "Hello";
#pragma used-
glcd_clear();
glcd_puts(ar_string,127,0,1,1,0);//Writes an Arabic string
glcd_puts(en_string,5,5,0,1,0);  //Writes an English(Latin) string

/* note : codevision avr don't support Arabic so when you write Arabic it will appear like this in the editor :"ÈÓã Çááå ÇáÑÍãä ÇáÑÍíã" don't change it */


Special Thanks To Osama's Lab for this great library.
For More details : Osama's Lab : GLCD library

Download the project and it's simulation HERE
Download this tutorial in PDF HERE

1 komentar:

  1. Ks0108 Glcd With Atmega16 ~ Software Movie And Information >>>>> Download Now

    >>>>> Download Full

    Ks0108 Glcd With Atmega16 ~ Software Movie And Information >>>>> Download LINK

    >>>>> Download Now

    Ks0108 Glcd With Atmega16 ~ Software Movie And Information >>>>> Download Full

    >>>>> Download LINK Dg

    BalasHapus