In this webpage, we describe how a display using the popular KS0108B controller can be driven by an 8051 or compatible microcontroller. Here we have used 128x64 pixels graphic display module with KS0108B display driver. It has the internal display RAM for storing the display data transferred from a 8 bit micro controller and generates the dot matrix Liquid crystal driving signals corresponding to stored data
PIN Diagram
Symbol | Level | Function |
Vss | 0V | Ground |
Vdd | +5V | Power supply for logic |
Vo | - | Operating voltage for LCD (contrast adjusting) |
RS | H/L | Register selection H:Display data L:Instruction code |
R/W | H/L | Read/Write selection H:Read operation L:Write Operation |
E | H,H à L | Enable Signal.Read data when E is high,Write data at the falling Edge of E |
DB0 | H/L | Data bit 0 |
DB1 | H/L | Data bit 1 |
DB2 | H/L | Data bit 2 |
DB3 | H/L | Data bit 3 |
DB4 | H/L | Data bit 4 |
DB5 | H/L | Data bit 5 |
DB6 | H/L | Data bit 6 |
DB7 | H/L | Data bit 7 |
CS1 | H | select the right half of display the CS1 bit is set |
CS2 | H | select the left half of display the CS2 bit is set |
/RST | L | Reset signal, active low |
Vout | -10V | Output voltage for LCD driving |
LEDA | +5V | Power supply for LED back light |
LEDK | 0V |
Memory map
The 128x64 graphic lcd is divided into two 64X64 pixel display area.Each driver KS0108B controls a 64 column by 64 row pixel array.
The 64 pixel row arrays are further grouped into 8 pages.Each page is 8 bits or 1 Byte tall. When you write a 8-bit data this "8 bit tall" area is filled up according to coloumn address. The LSB bit of the data byte is at the top and the MSB bit is at the bottom.
LCD Addressing
The first top most Page address is 0x0b8 and the lowermost page is 0x0c0. Likewise the left most column has an address of 0x040 and the rightmost column is at 0x080.
Whenever you write data into the display RAM, the column address alone is incremented automatically by one. And when the increment happens after the last column (0x080) it rolls over and overwrites on the first column in the current page.
To change the page use X address set instruction.
Circuit diagram
At89C51 (8051) microcontroller is used to drive KS0108B 128x64 graphic LCD.Port 0 is connected to the data bus of graphic lcd.Port 1 is used as control bus.Reset pin of graphic LCD is connected to Vcc.CS1 and CS2 pins are used to control display half select.
Power supply
LCD Initialization
1.Send the display off command 3eh
2. Send the display on command 3fh
3.If required you can use 11xx xxxx instruction to set the display line start
4. Set the Y-adddress to first coloumn 40h
5.Set the X-address to first page 0B8h
6.Blank the Display( clear all 128x64 pixels)
Program Code
org 00h
ajmp
ORG 30H
mov sp, #60h ; Define stack start point
mov p0, #00h ; clear port0
mov p1, #00h ; clear port1
CALL CLEAR_DISPLAY ;CLEAR DISPLAY AND INITIALISE DISPLAY
call lcd_left ;SELECT LEFT HALF OF DISPLAY
mov dptr,#message1
call lcd_string ;DISPLAY STRING ON LCD
CALL LCD_RIGHT ;SELECT RIGHT HALF OF DISPLAY
MOV DPTR,#MESSAGE2
CALL LCD_STRING
stop: ajmp stop
;===============================================================================
;KS0108B 128X64 PIXEL GRAPHIC LCD INITIALIZATION
;===============================================================================
LCD_Init:
mov a, #3eh ; Display off
call COMMAND
mov a,#3fh ; Display on
CALL COMMAND
mov a,#40h ; Y address counter at First column (40h to 80h)
CALL COMMAND
mov a,#0b8h ; X address counter at Starting point (0b8 to 0c0h)
CALL COMMAND
ret
;===============================================================================
;SET RS PIN HIGH AND WRITE DATA
;===============================================================================
LCD_DATA:
MOV P0,A
SETB P1.0 ;RS DATA
CALL ENABLE
RET
;===============================================================================
;RS PIN LOW SEND INSTRUCTION CODE
;===============================================================================
COMMAND:
MOV P0,A
CLR P1.0 ;RS COMMAND
CALL ENABLE
CALL DELAYS
RET
;===============================================================================
;GIVE HIGH TO LOW ENABLE PULSE AT ENABLE PIN
;===============================================================================
ENABLE:
SETB P1.2
nop
CLR P1.2
nop
RET
;===============================================================================
;SELECT RIGHT SIDE 64X64 PIXELS
;===============================================================================
lcd_RIGHT:
clr p1.4
setb p1.3 ;Chip select cs1 enabled
RET
;===============================================================================
;SELECT LEFT SIDE 64X64 PIXELS
;===============================================================================
LCD_LEFT:
clr p1.3
setb p1.4 ;Chip select cs2 enabled
RET
;===============================================================================
;General purpose delay routine
;===============================================================================
DelayS:
mov r7, #20h ; General purpose delay routine
DV:
mov r0, #0ffh
djnz r0, $
djnz r0, $
djnz r7, DV ; Delay = r7 value x 1536 micros
ret
;===============================================================================
;CLEAR ALL PIXELS OF 128X64 GRAPHIC LCD MODULE
;===============================================================================
Clear_display:
call lcd_LEFT
call lcd_init ; Initialise cs1
call BLANK ; clears all pages of cs1
call lcd_RIGHT
call lcd_init ; Initialise cs2
call BLANK ; clears all pages of cs2
ret
BLANK:
mov r5, #0b8h ; X address counter at First Page
pageS:
mov a, r5
call COMMAND
mov a, #40h ; Y address counter at First Column
call COMMAND
mov a, #00h ; To be cleared
mov r1, #64
nextS:
call LCD_DATA
dJNZ r1,NEXTS ; Clear all columns in one page
inc r5
cjne r5,#0c0h,paGES ; Loop for clearing all pages
ret
;===============================================================================
;BRING XY POINTER TO STARTING POSITION OF GRAPHIC LCD
;===============================================================================
HOME:
mov a,#0B8H ;x ADDRESS FIRST PAGE
call COMMAND
mov a,#40h ; Y address counter at First Column
call COMMAND
RET
;===============================================================================
;SUBROUTINE TO SEND THE HEX VALUES OF 5X8 FONTS FROM THE FONT TABLE
;===============================================================================
LCD_STRING:
MOV A,#0H
MOV 50H,#0H
NEXT:
INC 50H
MOVC A,@A+DPTR
CJNE A,#2FH,NEXT1
RET
NEXT1:
CALL TABLE_PTR
MOV A,#00H
CALL LCD_DATA
MOV A,50H
AJMP NEXT
TABLE_PTR:
PUSH DPL
PUSH DPH
MOV DPTR,#TABLE
MOV B,#05H
MUL AB
SUBB A,#0A0H
JNC HERE2
DEC B
HERE2:
MOV R4,A
CJNE R4,#00H,L1
AJMP L3
L1: INC DPTR
DJNZ R4,L1
L3:
CLR C
MOV R4,B
CJNE R4,#00H,L2
AJMP L4
L2:
INC DPH
DJNZ R4,L2
L4:
MOV R6,#00H
MOV A,#00H
NEXT2:
INC R6
MOVC A,@A+DPTR
CALL LCD_DATA
MOV A,R6
CJNE R6,#05H,NEXT2
POP DPH
POP DPL
RET
MESSAGE1: DB "128x64 lcd/"
MESSAGE2: DB "KS0108B/"
;===============================================================================
;5X8 CHARACTER TABLE USED IN MOST OF THE GRAPHIC LCD
;===============================================================================
Table:
DB 000H,000H,000H,000H,000H, ; 20 space
DB 000H,000H,05fH,000H,000H, ; 21 !
DB 000H,007H,000H,007H,000H, ; 22 "
DB 014H,07fH,014H,07fH,014H, ; 23 #
DB 024H,02aH,07fH,02aH,012H, ; 24 $
DB 023H,013H,008H,064H,062H, ; 25 %
DB 036H,049H,055H,022H,050H, ; 26 &
DB 000H,005H,003H,000H,000H, ; 27 '
DB 000H,01cH,022H,041H,000H, ; 28 (
DB 000H,041H,022H,01cH,000H, ; 29 )
DB 014H,008H,03eH,008H,014H, ; 2a *
DB 008H,008H,03eH,008H,008H, ; 2b +
DB 000H,050H,030H,000H,000H, ; 2c ,
DB 008H,008H,008H,008H,008H, ; 2d -
DB 000H,060H,060H,000H,000H, ; 2e .
DB 020H,010H,008H,004H,002H, ; 2f /
DB 03eH,051H,049H,045H,03eH, ; 30 0
DB 000H,042H,07fH,040H,000H, ; 31 1
DB 042H,061H,051H,049H,046H, ; 32 2
DB 021H,041H,045H,04bH,031H, ; 33 3
DB 018H,014H,012H,07fH,010H, ; 34 4
DB 027H,045H,045H,045H,039H, ; 35 5
DB 03cH,04aH,049H,049H,030H, ; 36 6
DB 001H,071H,009H,005H,003H, ; 37 7
DB 036H,049H,049H,049H,036H, ; 38 8
DB 006H,049H,049H,029H,01eH, ; 39 9
DB 000H,036H,036H,000H,000H, ; 3a :
DB 000H,056H,036H,000H,000H, ; 3b ;
DB 008H,014H,022H,041H,000H, ; 3c <
DB 014H,014H,014H,014H,014H, ; 3d =
DB 000H,041H,022H,014H,008H, ; 3e >
DB 002H,001H,051H,009H,006H, ; 3f ?
DB 032H,049H,079H,041H,03eH, ; 40 @
DB 07eH,011H,011H,011H,07eH, ; 41 A
DB 07fH,049H,049H,049H,036H, ; 42 B
DB 03eH,041H,041H,041H,022H, ; 43 C
DB 07fH,041H,041H,022H,01cH, ; 44 D
DB 07fH,049H,049H,049H,041H, ; 45 E
DB 07fH,009H,009H,009H,001H, ; 46 F
DB 03eH,041H,049H,049H,07aH, ; 47 G
DB 07fH,008H,008H,008H,07fH, ; 48 H
DB 000H,041H,07fH,041H,000H, ; 49 I
DB 020H,040H,041H,03fH,001H, ; 4a J
DB 07fH,008H,014H,022H,041H, ; 4b K
DB 07fH,040H,040H,040H,040H, ; 4c L
DB 07fH,002H,00cH,002H,07fH, ; 4d M
DB 07fH,004H,008H,010H,07fH, ; 4e N
DB 03eH,041H,041H,041H,03eH, ; 4f O
DB 07fH,009H,009H,009H,006H, ; 50 P
DB 03eH,041H,051H,021H,05eH, ; 51 Q
DB 07fH,009H,019H,029H,046H, ; 52 R
DB 046H,049H,049H,049H,031H, ; 53 S
DB 001H,001H,07fH,001H,001H, ; 54 T
DB 03fH,040H,040H,040H,03fH, ; 55 U
DB 01fH,020H,040H,020H,01fH, ; 56 V
DB 03fH,040H,038H,040H,03fH, ; 57 W
DB 063H,014H,008H,014H,063H, ; 58 X
DB 007H,008H,070H,008H,007H, ; 59 Y
DB 061H,051H,049H,045H,043H, ; 5a Z
DB 000H,07fH,041H,041H,000H, ; 5b [
DB 002H,004H,008H,010H,020H, ; 5c Yen Currency Sign
DB 000H,041H,041H,07fH,000H, ; 5d ]
DB 004H,002H,001H,002H,004H, ; 5e ^
DB 040H,040H,040H,040H,040H, ; 5f _
DB 000H,001H,002H,004H,000H, ; 60 `
DB 020H,054H,054H,054H,078H, ; 61 a
DB 07fH,048H,044H,044H,038H, ; 62 b
DB 038H,044H,044H,044H,020H, ; 63 c
DB 038H,044H,044H,048H,07fH, ; 64 d
DB 038H,054H,054H,054H,018H, ; 65 e
DB 008H,07eH,009H,001H,002H, ; 66 f
DB 00cH,052H,052H,052H,03eH, ; 67 g
DB 07fH,008H,004H,004H,078H, ; 68 h
DB 000H,044H,07dH,040H,000H, ; 69 i
DB 020H,040H,044H,03dH,000H, ; 6a j
DB 07fH,010H,028H,044H,000H, ; 6b k
DB 000H,041H,07fH,040H,000H, ; 6c l
DB 07cH,004H,018H,004H,078H, ; 6d m
DB 07cH,008H,004H,004H,078H, ; 6e n
DB 038H,044H,044H,044H,038H, ; 6f o
DB 07cH,014H,014H,014H,008H, ; 70 p
DB 008H,014H,014H,018H,07cH, ; 71 q
DB 07cH,008H,004H,004H,008H, ; 72 r
DB 048H,054H,054H,054H,020H, ; 73 s
DB 004H,03fH,044H,040H,020H, ; 74 t
DB 03cH,040H,040H,020H,07cH, ; 75 u
DB 01cH,020H,040H,020H,01cH, ; 76 v
DB 03cH,040H,030H,040H,03cH, ; 77 w
DB 044H,028H,010H,028H,044H, ; 78 x
DB 00cH,050H,050H,050H,03cH, ; 79 y
DB 044H,064H,054H,04cH,044H, ; 7a z
DB 000H,008H,036H,041H,000H, ; 7b <
DB 000H,000H,07fH,000H,000H, ; 7c |
DB 000H,041H,036H,008H,000H, ; 7d >
DB 010H,008H,008H,010H,008H, ; 7e Right Arrow ->
DB 078H,046H,041H,046H,078H ; 7f Left Arrow <-
END
Output
You can see the output is generated on the graphic LCD having driver KS0108 using 8051 microcontroller.