Revision: 1797
Author: wattymage
Date: Mon Mar 15 10:55:42 2010
Log: initial alpha sample
http://code.google.com/p/jallib/source/detail?r=1797
Added:
/trunk/catpad/glcd_ks0108mw.jal
=======================================
--- /dev/null
+++ /trunk/catpad/glcd_ks0108mw.jal Mon Mar 15 10:55:42 2010
@@ -0,0 +1,291 @@
+-- Title: lcd_ks0108 - Library for KS0108 compatible LCD
+-- Author: Serkan Ayyýldýz Copyright (c) 2006..2009, all rights reserved.
+-- Adapted-by: Joep Suijs
+-- some small changes: Michael Watterson (c)2010
+-- Compiler: >=2.2
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the ZLIB license
(http://www.opensource.org/licenses/zlib-license.html)
+--
+-- Sources:
+--
+-- Description: Library for KS0108 compatible graphic lcd with 128x64
resolution.
+--
+--
+-- Notes:
+--
+const KS0108_LEFT = 0
+const KS0108_RIGHT = 1
+const KS0108_CMD_ON = 0x3F
+const KS0108_CMD_OFF = 0x3E
+const KS0108_CMD_PAGE = 0xB8
+const KS0108_CMD_COLUMN = 0x40
+const KS0108_CMD_TOP_RAM = 0xC0
+
+-- 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
+procedure _ks0108_write(byte in side, byte in data) is
+ if side == 1 then -- Choose which side to write to
+ GLCD_CS2 = high
+ else
+ GLCD_CS1 = high
+ end if
+ GLCD_RW = low -- Set for writing
+ GLCD_DATAPRT = data -- Put the data on the port
+ GLCD_DATAPRT_DIR = all_output
+ _usec_delay (1)
+ GLCD_E = high -- Pulse the enable pin
+ _usec_delay (2)
+ --delay2_us
+ GLCD_E = low
+ GLCD_CS1 = low -- Reset the chip select lines
+ GLCD_CS2 = low
+ --delay_2us()
+ _usec_delay (2)
+end procedure
+
+-- Purpose: Reads a byte of data from the specified chip
+-- Ouputs: A byte of data read from the chip
+function _ks0108_read(byte in side) return byte is
+var byte data -- Stores the data read from the LCD
+ GLCD_DATAPRT_DIR = all_input -- Set port d to input
+ if side == 1 then -- Choose which side to write to
+ GLCD_CS2 = high
+ else
+ GLCD_CS1 = high
+ end if
+ GLCD_RW = high -- Set for reading
+ _usec_delay (1) -- delay_cycles(1)
+ GLCD_E = high -- Pulse the enable pin
+ _usec_delay (2)
+ data = GLCD_DATAPRT -- Get the data from the display's output register
+ GLCD_E = low
+ GLCD_CS1 = low -- Reset the chip select lines
+ GLCD_CS2 = low
+ _usec_delay (2)
+
+ return data -- Return the read data
+end function
+
+-- Purpose: Turn the display on
+procedure lcd_on() is
+ _ks0108_write(KS0108_LEFT, KS0108_CMD_ON)
+ _ks0108_write(KS0108_RIGHT, KS0108_CMD_ON)
+end procedure
+
+-- Purpose: Turn the display off
+procedure lcd_off() is
+ _ks0108_write(KS0108_LEFT, KS0108_CMD_OFF)
+ _ks0108_write(KS0108_RIGHT, KS0108_CMD_OFF)
+end procedure
+
+-- Purpose: Set the page number
+-- Inputs: A page number (0 - 7)
+procedure _ks0108_page(byte in side , byte in page) is
+ _ks0108_write(side, KS0108_CMD_PAGE | page)
+end procedure
+
+-- Purpose: Set the column address
+-- Inputs: The column address (0 - 63)
+procedure _ks0108_column(byte in side, byte in column) is
+ _ks0108_write(side, KS0108_CMD_COLUMN | column)
+end procedure
+
+-- Purpose: Specify reads and writes are instructions
+procedure _ks0108_inst() is
+ GLCD_DI = low
+end procedure
+
+-- Purpose: Specify reads and writes are data
+procedure _ks0108_data() is
+ GLCD_DI = high
+end procedure
+
+-- 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
+procedure PlotPixel(byte in x, byte in y, bit in onoff) is
+var byte data , yy
+var byte side = KS0108_LEFT -- Stores which chip to use on the LCD
+ if x > 127 then
+ x = x -128
+ end if
+ if x > 63 then -- Check for first or second display area
+ x = x - 64
+ side = KS0108_RIGHT
+ end if
+ if y > 191 then
+ y = y -192
+ elsif y > 127 then
+ y = y - 128
+ elsif y > 63 then
+ y = y -64
+ end if
+ _ks0108_inst() -- Set for instruction
+ _ks0108_column(side,x) -- Set the horizontal address
+ _ks0108_page(side,(y / 8)) -- Set the page address
+ _ks0108_data() -- Set for data
+ data = _ks0108_read(side) -- Need two reads to get data at new address
+ data = _ks0108_read(side) -- DO NOT REMOVE 2nd Read!
+ -- add XOR code
+ if onoff == 1 then
+ -- bit_set(data, y%8) -- Turn the pixel on
+ yy = y % 8
+ data = data | ( 1 << yy )
+ else -- or
+ -- bit_clear(data, y%8) -- turn the pixel off
+ yy = y % 8
+ data = data & !( 1 << yy )
+ end if
+ _ks0108_inst() -- Set for instruction
+ _ks0108_column(side,x) -- Set the horizontal address
+ _ks0108_data() -- Set for data
+ _ks0108_write(side, data) -- Write the pixel data
+end procedure
+
+procedure _ks0108_write_byte(byte in x, byte in y, byte in veri) is
+var byte side = KS0108_LEFT -- Stores which chip to use on the LCD
+ if x > 127 then
+ x = x -128
+ end if
+ if (x > 63)then -- Check for first or second display area
+ x = x - 64
+ side = KS0108_RIGHT
+ end if
+ if y > 191 then
+ y = y -192
+ elsif y > 127 then
+ y = y - 128
+ elsif y > 63 then
+ y = y -64
+ end if
+ _ks0108_inst() -- Set for instruction
+ _ks0108_column(side,x) -- Set the horizontal address
+ _ks0108_page(side,(y / 8)) -- Set the page address
+ _ks0108_data() -- Set for data
+ _ks0108_write(side, ! veri) -- Write the pixel data
+end procedure
+
+-- Purpose: Fill the LCD screen with the passed in color
+-- Inputs: ON - turn all the pixels on
+-- OFF - turn all the pixels off
+procedure lcd_fill(byte in data) is
+var byte i, j
+ i = 0 -- Loop through the vertical pages
+ for 8 loop
+ _ks0108_inst() -- Set for instruction
+ _ks0108_page(KS0108_LEFT,i) -- Set page address
+ _ks0108_page(KS0108_RIGHT,i)
+ _ks0108_column(KS0108_LEFT,0) -- Set horizontal address to 0
+ _ks0108_column(KS0108_RIGHT,0)
+ _ks0108_data() -- Set for data
+ -- Loop through the horizontal sections
+ for 64 loop
+ _ks0108_write(KS0108_LEFT ,data) -- Write the byte of data
+ _ks0108_write(KS0108_RIGHT,data)
+ end loop
+ i = i + 1
+ end loop
+end procedure
+
+-- Purpose: Initialize the LCD.
+-- Call before using any other LCD function.
+procedure lcd_init() is
+ -- Initialze some pins
+ GLCD_DATAPRT = 0x00
+ GLCD_DATAPRT_DIR = all_output
+ GLCD_RW_DIRECTION = output
+ GLCD_CS1_DIRECTION = output
+ GLCD_E_DIRECTION = output
+ GLCD_DI_DIRECTION = output
+ --GLCD_RST_DIRECTION = output
+ GLCD_CS2_DIRECTION = output
+ --GLCD_RST = high
+ GLCD_E = low
+ GLCD_CS1 = low
+ _ks0108_inst() -- Set for instruction
+ _ks0108_write(KS0108_LEFT, KS0108_CMD_TOP_RAM | 0) -- First RAM line
at the top of the screen
+ _ks0108_write(KS0108_RIGHT, KS0108_CMD_TOP_RAM | 0) -- First RAM line
at the top of the screen
+ _ks0108_page (KS0108_LEFT ,0) -- Set the page address to 0
+ _ks0108_page (KS0108_RIGHT,0)
+ _ks0108_column(KS0108_LEFT ,0) -- Set the column address to 0
+ _ks0108_column(KS0108_RIGHT,0)
+ lcd_on() -- Turn the display on
+ lcd_fill(0) -- Clear the display
+end procedure
+
+-- use for sprites or fonts that are multiple of 8 high
+procedure BlitColumn (byte in x, byte in y, byte in column ) is
+ _ks0108_inst() -- Set for instruction
+ if (x > 128) then
+ x = x -128
+ end if
+ if y > 191 then
+ y = y -192
+ elsif y > 127 then
+ y = y - 128
+ elsif y > 63 then
+ y = y -64
+ end if
+ if (x < 64) then
+ _ks0108_column(KS0108_LEFT,x) -- Set the horizontal address
+ _ks0108_page(KS0108_LEFT, (y / 8)) -- Set the page address
+ _ks0108_data() -- Set for data
+ _ks0108_write(KS0108_LEFT, column) -- Write the pixel data
+ else
+ _ks0108_column(KS0108_RIGHT, x-64) -- Set the horizontal address
+ _ks0108_page(KS0108_RIGHT, (y / 8)) -- Set the page address
+ _ks0108_data() -- Set for data
+ _ks0108_write(KS0108_RIGHT, column) -- Write the pixel data
+ end if
+end procedure
+
+procedure PlotColumn(byte in x, byte in y, byte in column, bit in ink, bit
in replace) is
+-- if ink is false, invert column data
+-- if replace is true, plot 0 and 1 ink, else plot only only ink value ink
+var byte data
+var byte side = KS0108_LEFT -- Stores which chip to use on the LCD
+ if x > 127 then
+ x = x -128
+ end if
+ if x > 63 then -- Check for first or second display area
+ x = x - 64
+ side = KS0108_RIGHT
+ end if
+ if y > 191 then
+ y = y -192
+ elsif y > 127 then
+ y = y - 128
+ elsif y > 63 then
+ y = y -64
+ end if
+ if replace then
+ if ink then
+ data = column
+ else
+ data = ! column
+ end if
+ else
+ _ks0108_inst() -- Set for instruction
+ _ks0108_column(side,x) -- Set the horizontal address
+ _ks0108_page(side,(y / 8)) -- Set the page address
+ _ks0108_data() -- Set for data
+ data = _ks0108_read(side) -- Need two reads to get data at new
address
+ data = _ks0108_read(side) -- DO NOT REMOVE 2nd Read!
+ if ink then
+ data = data | column
+ else
+ data = data & (! column)
+ end if
+ end if
+ _ks0108_inst() -- Set for instruction
+ _ks0108_column(side,x) -- Set the horizontal address
+ _ks0108_page(side,(y / 8)) -- Set the page address
+ _ks0108_data() -- Set for data
+ _ks0108_write(side, data) -- Write the pixel data
+end procedure
+
+
+
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en.