Demon
- 30th April 2011, 01:49
Look at what I found going through my archives:
'************************************************* ***********************
'GLIPICW.BAS Graphic application for use with a KS0108 (or compatible)
'graphic LCD controller connected to a Microchip(TM) PIC 16F877
'Written in MELabs PicBasicPro(TM) Ver 3.32
'Beta version 0.8.0
'================== NOT FOR COMMERICIAL USE =============================
'
' Author: Ranjit Diol - COMPSys LLC, March 2000
' (c) Copyright Ranjit Diol, 2001
'
' DISCLAIMER: This file is being released as non-commericial
' freeware. It is being provided "AS IS", neither the author,
' nor COMPSys LLC shall be held liable for any damages caused
' by its use.
'
' LICENSE: This application may be used in its entirety or
' in parts within some other non-commercial application as long
' as the author is given credit for those parts used.
'
' Contact:
[email protected] for more information
'
'************************************************* ***********************
' IMPORTANT, PLEASE NOTE THE FOLLOWING
'This application assumes you have a 64KBit external eeprom connected
'via I2C. Without that you will only be able to send images directly
'to the LCD display and not be able to store them -- See the readme.txt
'for the Windows GLiPIC interface.
'
'Adjust the PIN assignments as neccessary for your prototype
'This was tested using a 20MHz xtal if you use a different OSC speed
'you may have to make some adjustement in the 'strobe' subroutine.
'************************************************* ***********************
DEFINE ONINT_USED 1 'Required if using ISP
DEFINE OSC 20 'OSC speed, you may have to tweak the 'strobe'
'routine's e_pause constant for other speeds
ADCON1 = 7 'Make all pins digital, you may adjust as needed
SPBRG=0 '************ NOTE ***********
RCSTA=0 'This is required if you are using
TXSTA=2 'Shane Tolmie's bootloader (PICLoader)
'*****************************
dat VAR PORTD 'LCD bus Pins 7-14 LSB-MSB
scl VAR PORTC.3 'I2C SCL for ext eeprom
sda VAR PORTC.4 'I2C SDA for ext eeprom
in_pin VAR PORTC.7 'Serial input pin
out_pin VAR PORTC.6 'Serial output pin
e VAR PORTC.0 'Enable pin on LCD
cd VAR PORTC.1 'Data/Command Pin 4 on LCD
rw VAR PORTC.2 'Read/Write Pin 5 on LCD
cs1 VAR PORTB.1 'ChipSelect1 Pin 15 on LCD
cs2 VAR PORTB.2 'ChipSelect2 Pin 16 on LCD
rst VAR PORTC.5 'Reset Pin 17 on LCD
'Set pins for output
TRISB.0 = 0
TRISB.1 = 0
TRISB.2 = 0
TRISD = 0
TRISC.0 = 0
TRISC.1 = 0
TRISC.2 = 0
TRISC.3 = 0
TRISC.4 = 0
TRISC.5 = 0
'Constants used
ser_baud CON 32 '19200 baud serout/serin
ctl CON $A0 'EEprom control code
row CON $b8 'LCD page 0
last_row CON $bf 'LCD page 7
col CON $40 'Line byte position 0
last_col CON 63 'Last column (1-64)
first_col CON 0 'First column
max_col CON 128 'Last column (1-127)
max_line CON 8 'Line 8 (based on 1-8)
max_pos CON 64 'Column 64 positon per side (1-64)
cr CON 13 'CR for serout
lf CON 10 'LF for serout
disp_on CON $3f 'LCD Display ON
disp_off CON $3e 'LCD Display OFF
disp_ram CON $c0 'Ram Display 0 (Page 0 at top of display)
blank CON $00 'Blank character
e_pause CON 10 'Pauseus 6 for Strobe routine
'Word variables used
eepaddr VAR WORD
addr VAR WORD
'Arrays used
in_array VAR byte[32]
in_ctl VAR byte[8]
'Byte Variables used
buff_count VAR BYTE 'buffer count
hex_nibble VAR BYTE 'hex nibble from serin
in_ascii VAR BYTE 'ASCII char from serin
buf_cnt VAR BYTE 'buffer counter
byte_pos VAR BYTE 'To keep track of a byte's position
in_byte VAR BYTE 'The incoming byte
tmp VAR BYTE 'Temporary var
index VAR BYTE 'Index for arrays
j VAR BYTE 'General counter
k VAR BYTE 'General counter
line VAR BYTE 'An LCD row
delay VAR BYTE 'Execution delay, used with 'pause'
'Initialize variables
hex_nibble = 0
byte_pos = 0
delay = 10
in_byte = 0
tmp = 0
index = 0
'Reset LCD
dat = 0 ' Clear PORTD
cd = 0
rw = 0
e = 0
cs1 = 1
cs2 = 0
rst = 1
pause 100 'Let things stabilize
rst = 0
pause 10 ' Reset LCD
rst = 1
pause 500
'Jump over subroutines to main program
goto main
' **** (GO)SUB ROUTINES ****
strobe:
e = 1
pauseus e_pause
e = 0
return
clearall:
cd = 0 ' Command mode
dat = disp_off ' Display Off
gosub strobe
cs1=1
cs2=0
for index = 1 to 2
for j = row to last_row
cd = 0 'Command mode
gosub strobe ' Write the data
dat = col ' Column address = 0
gosub strobe
dat = j
gosub strobe
cd = 1 ' Write mode
for k = first_col to last_col
dat = blank
gosub strobe
next
next
swap cs1,cs2
next
cs1=0
cs2=1
cd=0
dat=row
gosub strobe
dat = disp_ram ' Ram Line 0
gosub strobe
dat=col
gosub strobe
dat = disp_on 'display on
gosub strobe
cs1=1
cs2=0
dat=row
gosub strobe
dat = disp_ram ' Ram Line 0
gosub strobe
dat=col
gosub strobe
dat = disp_on 'display on
gosub strobe
cd = 1 ' Set Data command
cs1 = 1 ' Left side active
cs2 = 0
return
init: 'Initialization
cd = 0 ' Set command mode
cs1 = 1 ' Left Side on
cs2 = 0 ' Right Side off
for index = 1 to 2
dat = disp_off ' Display Off
dat = disp_ram ' Ram Line 0
gosub strobe ' Write the data
dat = col ' Y address = 0
gosub strobe
dat = row ' Page = 0
gosub strobe
dat = disp_on ' Display On
gosub strobe
swap cs1,cs2
next
cs1=1
cs2=0
return
'****Place char on LCD Routine *****
'Place byte of data on lcd assumes in_byte, byte_pos and line (line)
'Char position on LCD byte_pos = 0-127 (Horiz), ROW 0-7 (vert)
putbyte:
dat = in_byte 'Display the byte
gosub strobe
byte_pos=byte_pos+1 'Increment position
'Now do some LCD house cleaning and adjust counters
if byte_pos=max_pos then
cs1=0
cs2=1
cd = 0
dat = col
gosub strobe
dat = disp_ram
gosub strobe
dat = row + line
gosub strobe
cd = 1
endif
if byte_pos = max_col then 'Check if
line = line + 1 'New Line
if line = max_line then
line = 0
endif
byte_pos = 0 'Reset byte_pos
cs1=1
cs2=0
cd = 0
dat=col
gosub strobe
dat = row + line
gosub strobe
dat = disp_ram
gosub strobe
cd =1
endif
return
'***** Convert incoming ascii to hex byte Routine *****
find:
Lookdown in_array[index],["0123456789abcdef"],hex_nibble
return
'===============================
' **** BEGIN MAIN PROGRAM ******
'===============================
main:
gosub init ' Initialize LCD
gosub clearall ' Clear all pages
serout2 out_pin,ser_baud,["Load image..."]
goto term
logo: gosub init ' Initialize LCD
gosub clearall ' Clear all pages
'**** DISPLAY IMAGES IN EXTERNAL 64KBit EEPROM VIA I2C *****
' Load opening screen from eeprom assuming a 64KBit eeprom
byte_pos=0
line =0
for addr = 0 to 8192
I2CREAD sda,scl,ctl,addr,[in_byte]
gosub putbyte
if (addr=1024) OR (addr=2048) OR (addr= 3072) OR (addr=4096) OR (addr=5120) OR (addr=6144) OR (addr=7168) OR (addr=8192) then
pause 4000
gosub init
gosub clearall
endif
next
pause 4000
gosub init
gosub clearall
'goto logo 'Continue looping inifitum!
'********************************************
'Terminal Subroutine
term: 'Assumes Home Position
'Setup variables
j=0
index=0
k=0
'line=0
addr=0
in_ascii = 0
buff_count = 32
delay = 10
'addr = 0
'byte_pos = 0
'Get the initial parameters
get_param:
addr = 0
byte_pos = 0
line=0
serin2 in_pin,ser_baud,[wait ("*"),STR in_ctl\9]
for index = 0 to 8
Lookdown in_ctl[index],["0123456789abcdef"],hex_nibble
in_ctl[index]=hex_nibble
next
delay = (in_ctl[7]<<4) | in_ctl[8]
buff_count = (in_ctl[1]<<4) | in_ctl[2]
addr.byte1 = (in_ctl[3] <<4) | in_ctl[4]
addr.byte0 = (in_ctl[5] <<4) | in_ctl[6]
buf_cnt = (buff_count - 1)
eepaddr = addr
j=in_ctl[0]
if j = 3 then lcd_loop 'Display directly on LCD
if j = 1 then eep_loop 'Load ext eeprom
if j = 2 then logo 'Display images loop
goto get_param
eep_loop:
serin2 in_pin,ser_baud,5000,get_param,[wait ("]"),STR in_array\buff_count] 'Wait for ] and the load in_array
for index = 0 to (buff_count - 1)
gosub find 'Get char and place in array
in_array[index]=hex_nibble
next
for index = 0 to (buff_count - 1) step 2
in_byte = (in_array[index]<<4) | (in_array[index+1]) 'Form a hex number MSB-LSB
I2CWRITE sda,scl,ctl,addr,[in_byte]
pause 5
addr=addr+1
next
goto eep_loop
lcd_loop:
serin2 in_pin,ser_baud,5000,get_param,[wait ("]"),STR in_array\buff_count] 'Wait for ] and the load in_array
for index = 0 to (buff_count - 1)
gosub find 'Get char and place in array
in_array[index]=hex_nibble
next
for index = 0 to (buff_count - 1) step 2
in_byte = (in_array[index]<<4) | (in_array[index+1]) 'Form a hex number MSB-LSB
gosub putbyte
next
goto lcd_loop
'*********** E N D ************
end
' **** END OF MAIN PROGRAM ****
pedja089
- 30th April 2011, 12:30
I first I tried so I just used a lookup instead of eeprom ....
Here's the code
trisb=0
trisd=0
portb=0
portd=0
symbol RW=portb.3
symbol RS = portb.2
symbol E = portb.4
symbol CS1 = portb.0
symbol CS2 = portb.1
symbol RST = portb.5
Symbol LCDDATA=portd
i var byte
X var byte
Y var byte
pocetak:
call init
LCDDATA=0
call clr
cs1=0
x=1
call setx
y=0
call sety
for i=0 to 63
Lookup i, [$00,$00,$FE,$FE,$FE,$FE,$1E,$1E,$1E,$1E,$1E,$1E,$1 E,$1E,$FE,$FE,$FC,$F8,$00,$FE,$FE,$FE,$FE,$0E,$0E, $0E,$0E,$0E,$0E,$0C,$00,$00,$00,$FE,$FE,$FE,$FE,$0 E,$0E,$0E,$0E,$0E,$0E,$0E,$FE,$FC,$F8,$F0,$00,0,$F E,$FE,$FE,$FE,$0E,$0E,$0E,$0E,$0E,$0E,$FE,$FE,$FC, $F8], LCDDATA
call pod
next i
x=2
y=0
call sety
call setx
for i=0 to 63
Lookup i, [$00,$00,$FF,$FF,$FF,$FF,$F0,$F0,$F0,$F0,$F0,$F0,$F 0,$F0,$FF,$FF,$7F,$3F,$00,$FF,$FF,$FF,$FF,$E0,$E0, $E0,$E0,$E0,$E0,$E0,$00,$00,$E0,$FF,$FF,$FF,$FF,$E 0,$E0,$C0,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$00,0,$F F,$FF,$FF,$FF,$80,$80,$80,$80,$80,$80,$FF,$FF,$FF, $FF], LCDDATA
call pod
next i
x=3
y=0
call sety
call setx
for i=0 to 63
Lookup i, [$00,$00,$FF,$FF,$FF,$FF,$00,$00,$00,$00,$00,$00,$0 0,$00,$00,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$01,$01, $01,$01,$01,$01,$01,$00,$00,$01,$FF,$FF,$FF,$FF,$0 1,$01,$01,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$00,0,$F F,$FF,$FF,$FF,$07,$07,$07,$07,$07,$07,$FF,$FF,$FF, $FF], LCDDATA
call pod
next i
x=4
y=0
call sety
call setx
for i=0 to 63
Lookup i, [$00,$00,$FF,$FF,$FF,$FF,$00,$00,$00,$00,$00,$00,$0 0,$00,$00,$00,$00,$00,$00,$FF,$FF,$FF,$FF,$E0,$E0, $E0,$E0,$E0,$E0,$E0,$E0,$00,$00,$FF,$FF,$FF,$FF,$E 0,$E0,$E0,$E0,$E0,$E0,$E0,$FF,$FF,$FF,$FF,$00,0,$F F,$FF,$FF,$FF,$00,$00,$00,$00,$00,$00,$FF,$FF,$FF, $FF], LCDDATA
call pod
next i
LCDDATA=0
cs1=1
cs2=0
x=1
call setx
for i=0 to 63
Lookup i, [$00,$00,$FE,$FE,$FE,$FE,$1E,$1E,$1E,$1E,$1E,$1E,$1 E,$1E,$FE,$FE,$FC,$F8,$00,$FE,$FE,$FE,$FE,$1E,$1E, $1E,$1E,$1E,$1E,$FE,$FE,$FC,$F8,$00,$FE,$FE,$FE,$F E,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$FE,$FE,$FC,$F8,$00, $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0 0,$00], LCDDATA
call pod
next i
x=2
call setx
for i=0 to 63
Lookup i, [$00,$00,$FF,$FF,$FF,$FF,$00,$00,$00,$00,$00,$00,$0 0,$00,$FF,$FF,$FF,$FF,$00,$FF,$FF,$FF,$FF,$80,$80, $80,$80,$80,$80,$FF,$FF,$FF,$FF,$00,$FF,$FF,$FF,$F F,$80,$80,$80,$80,$80,$80,$80,$FF,$FF,$FF,$FF,$00, $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0 0,$00], LCDDATA
call pod
next i
x=3
call setx
for i=0 to 63
Lookup i, [$00,$00,$FF,$FF,$FF,$FF,$00,$00,$00,$00,$00,$00,$0 0,$00,$FF,$FF,$FF,$FF,$00,$FF,$FF,$FF,$FF,$07,$07, $07,$07,$07,$07,$FF,$FF,$FF,$FF,$00,$07,$07,$07,$0 7,$07,$07,$07,$07,$07,$07,$07,$FF,$FF,$FF,$FF,$00, $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0 0,$00], LCDDATA
call pod
next i
x=4
call setx
for i=0 to 63
Lookup i, [$00,$00,$FF,$FF,$FF,$FF,$E0,$E0,$E0,$E0,$E0,$E0,$E 0,$E0,$FF,$FF,$FF,$FF,$00,$FF,$FF,$FF,$FF,$E0,$E0, $E0,$E0,$E0,$E0,$FF,$FF,$FF,$FF,$00,$00,$E0,$E0,$E 0,$E0,$E0,$E0,$E0,$E0,$E0,$E0,$FF,$FF,$FF,$FF,$00, $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0 0,$00], LCDDATA
call pod
next i
PAUSE 5000
cs1=1
cs2=1
CALL CLr
x=0
y=0
call setx
call sety
LCDDATA=0
CS2=1
cs1=0
y=10
x=1
call setx
call sety
for i=0 to 63
Lookup i, [$00,$7E,$12,$1E,$00,$00,$7E,$4A,$4A,$4A,$00,$7E,$4 2,$42,$3C,$00,$60,$40,$7E,$00,$60,$1C,$12,$1C,$60, $00,$7E,$42,$7E,$00,$7E,$4A,$7E,$00,$5E,$52,$7E,$0 0], LCDDATA
call pod
next i
y=26
x=3
call setx
call sety
for i=0 to 37
Lookup i, [$00,$3E,$40,$3C,$02,$3C,$40,$3E,$00,$00,$3E,$40,$3 C,$02,$3C,$40,$3E,$00,$00,$3E,$40,$3C,$02,$3C,$40, $3E,0,64,0,$7E,$4A,$4A,$4A,$00,$7E,$40,$40,$00], LCDDATA
call pod
next i
cs2=0
cs1=1
x=3
call setx
for i=0 to 63
Lookup i, [$7E,$4A,$4A,$4A,$00,$7E,$10,$18,$24,$42,$02,$7E,$0 2,$02,$00,$7E,$0A,$1A,$6E,$00,$3C,$42,$42,$42,$3C, $00,$7E,$0C,$30,$7E,$00,$00,$7E,$00,$7E,$10,$18,$2 4,$42,$00,$60,$1C,$12,$1C,$60,$00,$40,$00,$7E,$48, $78,$00,$60,$1C,$12,$1C,$60,0], LCDDATA
call pod
next i
cs2=1
cs1=1
pause 2000
for i=63 to 32 step -1
LCDDATA=192+i
call kom
pause 400
next i
goto pocetak
end
Init:
x=0
y=0
rw=0
cs1=0
cs2=0
e=1
LCDDATA=0
rst=0
pause 1
rst=1
cs1=1
cs2=1
call Dispon
LCDDATA=192
call kom
return
Pod:
rs=1
e=0
pauseus 1
e=1
return
Kom:
rs=0
e=0
pauseus 1
e=1
return
SetX:
LCDDATA=184+x
call Kom
return
SetY:
LCDDATA=64+y
call Kom
return
Clr:
for x=0 to 7
call setx
y=0
call sety
LCDDATA=0
for i=0 to 63
call pod
next i
next x
return
DispOff:
LCDDATA=62
call kom
return
DispOn:
LCDDATA=63
call kom
return
But then the problem was that every time I want to print something, I have to draw a picture of the entire display, or create the font, and for each letter copy 5 bytes. Then I found a forum for the LCD of Nokia 3310, and tried to correct for KS0108.
I hope to be able to finish it, but now I am busy doing other things, so...
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.