PDA

View Full Version : color LCD workshop



cncmachineguy
- 11th May 2011, 15:06
Just a post to see if there is any intrest for this. Several of us jumped on the LCD presented here (http://www.picbasic.co.uk/forum/showthread.php?t=13725). Dave has done a great job sharing information and showing some of the power available with this unit.

I must admit I have done nothing with mine, as I am still looking for the starting point.

I propose we attack this as a group and work through it. If anyone is intrested, jump on. Lets first see how many have 1 and want to join the fun.

Goals:
Be able to utilize any of the built in functions. Maybe learn them 1 at a time.
Everyone contributing so we all understand what has happened in any step. (of course anyone is welcome to copy and paste any code available here, but your understanding may be less that way)
Maybe even generate some includes for furture use of this beast

We will all have a different reason in mind for what to use it for, but if we are in command of the entire device, we will be able to use it however we want.

First to decide on a uP to use. I would suggest we use whatever Dave used in his thread, but that too is open at this point.

If there is no intrest here, thats OK too.

DaveC3
- 11th May 2011, 15:22
I made a analog clock face on the display using a RTC, "trig.inc" to preform the math to position the hands, touch pad to set the clock via menus, set RTC time via USB.

There is a lot of room for improvement so if anyone is interested in using this project I will post it.

Dave

cncmachineguy
- 11th May 2011, 15:33
Hi Dave, That is AWESOME!. Can we count you in as the mentor for this? Personally I would love to look at the code for this. But can you post it in a new thread? That seems to me like a far jump from can I draw a line first or even detect the screen tap.

DaveC3
- 11th May 2011, 16:25
Sure, I don't mind helping out. The hardest part of this project was the math. I had an older version that used a look-up table for hand drawing.

I will post a zip of the project in a new thread.

Dave

cncmachineguy
- 11th May 2011, 17:01
Ok, in a moving forward fashion, I will start with the display

Seems we have 4 things of intrest hardware wise;
SD card slot - pretty self evident
JP1
JP2
PS0-PS3

JP1 and JP2 seem to be parallel connectors so this is now just JP1
This is our connection to the uP and other stuff.

PS0-PS3 are setup fuses. per suggestion from Daves thread, we want to set this as this:
PS0 not soldered
PS1 not soldered
PS2 soldered
PS3 soldered

This should give us 8 bit data and 4 wire SPI I think. But do we want 4 wire or 3?

Connection to the uP through JP1 is another post.
If this is wrong, please correct me someone :eek:

Where is the chip select for the touch screen controller? Pin 31 of JP1?

DaveC3
- 12th May 2011, 00:47
As Bert pointed out, the solder pads PS2 and PS3 are soldered and PS1, PS0 are open. This tells the controller that we will use 8 Bit parallel. If you want to use SPI or 16 bit parallel you need to change the solder pads as required.

The next step is to set up your ports and pins and the basic communication to the display. In my project I used a 18F4550, you can change the pins to suit your Pic.



LCD_Dat var PORTD
LCD_CS var PORTA.0
LCD_RS var PORTA.1
LCD_WR var PORTA.2
LCD_RD var PORTA.3
LCD_RST var PORTA.4

The next item is communication with the display.



'************************************************* *****************************
LCD_Write_CMD:
high lcd_RD
low lcd_rs
low lcd_cs
low lcd_wr
lcd_dat = cmd.highbyte
high lcd_wr
low lcd_wr
LCD_Dat = cmd.lowbyte
high lcd_wr
high lcd_rs
high lcd_cs

Return
'************************************************* *****************************
LCD_Write_Dat:
high lcd_RD
high lcd_rs
low lcd_cs
low lcd_wr
lcd_dat = dat.highbyte
high lcd_wr
low lcd_wr
LCD_Dat = dat.lowbyte
high lcd_wr
high lcd_cs

return


'************************************************* *****************************
LCD_Read_Dat: ' only works with 16 bit control
TRISD = $FF
color_buf = 0
low lcd_cs
high lcd_rs
high lcd_wr


low lcd_rd 'dummy read
high lcd_rd

low lcd_rd
color_buf.lowbyte = lcd_dat
high lcd_rd
'lcd_dat
low lcd_rd
color_buf.highbyte = lcd_dat
high lcd_rd

'lcd_dat
TRISD = $00
high lcd_cs
return
'************************************************* *****************************

LCD_RESET:
low lcd_rst
pause 500
high lcd_rst
pause 1000
return
'************************************************* *****************************

Then you need to initialize the display.



LCD_INIT:
gosub lcd_reset
cmd = $0028 : gosub lcd_write_CMD : dat = $0006 : gosub lcd_write_dat

pause 10
cmd = $0000 : gosub lcd_write_CMD : dat = $0001 : gosub lcd_write_dat ' Start OSC
cmd = $0010 : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
cmd = $0001 : gosub lcd_write_CMD : dat = $30EF : gosub lcd_write_dat ' Driver output 32EF
cmd = $0002 : gosub lcd_write_CMD : dat = $0600 : gosub lcd_write_dat
cmd = $0003 : gosub lcd_write_CMD : dat = $6A64 : gosub lcd_write_dat
cmd = $0011 : gosub lcd_write_CMD : dat = $6830 : gosub lcd_write_dat

cmd = $000F : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat

cmd = $000B : gosub lcd_write_CMD : dat = $5308 : gosub lcd_write_dat
cmd = $000C : gosub lcd_write_CMD : dat = $0003 : gosub lcd_write_dat
cmd = $000D : gosub lcd_write_CMD : dat = $000A : gosub lcd_write_dat
cmd = $000E : gosub lcd_write_CMD : dat = $2E00 : gosub lcd_write_dat

cmd = $001E : gosub lcd_write_CMD : dat = $002B : gosub lcd_write_dat '
cmd = $0025 : gosub lcd_write_CMD : dat = $8000 : gosub lcd_write_dat
cmd = $0026 : gosub lcd_write_CMD : dat = $7000 : gosub lcd_write_dat
cmd = $004E : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
cmd = $004F : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat

cmd = $0012 : gosub lcd_write_CMD : dat = $08D9 : gosub lcd_write_dat
' Gama Curve
cmd = $0030 : gosub lcd_write_CMD : dat = $0000 : gosub lcd_write_dat
cmd = $0031 : gosub lcd_write_CMD : dat = $0104 : gosub lcd_write_dat
cmd = $0032 : gosub lcd_write_CMD : dat = $0100 : gosub lcd_write_dat
cmd = $0033 : gosub lcd_write_CMD : dat = $0305 : gosub lcd_write_dat
cmd = $0034 : gosub lcd_write_CMD : dat = $0505 : gosub lcd_write_dat
cmd = $0035 : gosub lcd_write_CMD : dat = $0305 : gosub lcd_write_dat
cmd = $0036 : gosub lcd_write_CMD : dat = $0707 : gosub lcd_write_dat
cmd = $0037 : gosub lcd_write_CMD : dat = $0300 : gosub lcd_write_dat
cmd = $003A : gosub lcd_write_CMD : dat = $1200 : gosub lcd_write_dat
cmd = $003B : gosub lcd_write_CMD : dat = $0800 : gosub lcd_write_dat
pause 150
cmd = $0007 : gosub lcd_write_CMD : dat = $0033 : gosub lcd_write_dat
pause 200

Return


Now you can start writing to the display.

You will need several sub routines to do things like "Text" shapes etc.

You should read the data sheet for the display to try to understand how the display works. I attached the PBP code that has a number of different subs in another post, http://www.picbasic.co.uk/forum/showthread.php?t=14824 feel free to use it and hopefully improve upon it.

Dave

Normnet
- 12th May 2011, 06:47
Just a post to see if there is any intrest for this. Several of us jumped on the LCD presented here (http://www.picbasic.co.uk/forum/showthread.php?t=13725). Dave has done a great job sharing information and showing some of the power available with this unit.

I must admit I have done nothing with mine, as I am still looking for the starting point.

I propose we attack this as a group and work through it. If anyone is intrested, jump on. Lets first see how many have 1 and want to join the fun.

Goals:
Be able to utilize any of the built in functions. Maybe learn them 1 at a time.
Everyone contributing so we all understand what has happened in any step. (of course anyone is welcome to copy and paste any code available here, but your understanding may be less that way)
Maybe even generate some includes for furture use of this beast

We will all have a different reason in mind for what to use it for, but if we are in command of the entire device, we will be able to use it however we want.

First to decide on a uP to use. I would suggest we use whatever Dave used in his thread, but that too is open at this point.

If there is no intrest here, thats OK too.
Another GLCD example is at wav player with GLCD menu and slide show from SD card. (http://www.norm-online.net/PIC_iPod_wav_player.php)
It features the SparksFun 128x128 color GLCD Nokia Knockoff for $14.95 (http://www.sparkfun.com/products/569)

Norm

cncmachineguy
- 12th May 2011, 14:05
@ DaveC, Thank you for confirming the fuses, and clearing up my confusion about 16,8bit vs 3,4 wire SPI. For some reason I had it in my head both interfaces (parallel & SPI) were active at the same time. Now the truth table makes more sense. The code posted is wonderful! At this point I need to either get a 18F4550, or decide on using something I already have. I will more then likely go with the 4550, just to be consistent with this thread. Once I have the use of this under my belt, then I will venture out and use others.
Have you found uP speed to be an issue? I like to use internal OSC when I can, but this will limit me to 32mHz in most cases. I see you are running at 48.

@Norm, That does look like a great GLCD. and the price is right on too. I didn't notice, does it have touch?

My end goal for this is HMI use. I have lots of stuff here at the shop that would benefit greatly from this.

Off to order some 4550's. It will be a few days before I get them, so I won't be playing till then.

When I find the datasheet, I will post it (or the link) here.

DaveC3
- 12th May 2011, 17:03
Bert

I use the 4550 for several reasons, 1. I have a lot of them, 2. I make a lot of USB devices for my flight simulator, 3. the speed of this chip is 48mhz.

This code can be ported to other devices. I have done SPI with this display but it is a lot slower.

Dave

DaveC3
- 12th May 2011, 17:30
In my previous post I showed how to setup and talk to the GLCD. The next thing to do is get some text on the screen. The controller on this display does not have built in text so you need to provide the text. This is done in a couple of look-up tables,



'=================
'FONT SAMPLE 5x7
'=================

Table1:
lu1 = charpos + char_row

lookup lu1, [0,0,0,0,0,_ 'space
$00,$00,$5f,$00,$00,_ '// 21 !
$00,$07,$00,$07,$00,_ ' 22 "
$14,$7f,$14,$7f,$14,_ ' 23 #
$24,$2a,$7f,$2a,$12,_ ' 24 $
$23,$13,$08,$64,$62,_ ' 25%
$36,$49,$55,$22,$50,_ ' 26 &
$00,$05,$03,$00,$00,_ ' 27 '
$00,$1c,$22,$41,$00,_ ' 28 (
$00,$41,$22,$1c,$00,_ ' 29 )
$14,$08,$3e,$08,$14,_ ' 2a *
$08,$08,$3e,$08,$08,_ ' 2b +
$00,$50,$30,$00,$00,_ ' 2c ,
$08,$08,$08,$08,$08,_ ' 2d -
$00,$60,$60,$00,$00,_ ' 2e .
$20,$10,$08,$04,$02,_ ' 2f /
$3e,$51,$49,$45,$3e,_ ' 30 0
$00,$42,$7f,$40,$00,_ ' 31 1
$42,$61,$51,$49,$46,_ ' 32 2
$21,$41,$45,$4b,$31,_ ' 33 3
$18,$14,$12,$7f,$10,_ ' 34 4
$27,$45,$45,$45,$39,_ ' 35 5
$3c,$4a,$49,$49,$30,_ ' 36 6
$01,$71,$09,$05,$03,_ ' 37 7
$36,$49,$49,$49,$36,_ ' 38 8
$06,$49,$49,$29,$1e,_ '// 39 9
$00,$36,$36,$00,$00,_ '// 3a :
$00,$56,$36,$00,$00,_ '// 3b ;
$08,$14,$22,$41,$00,_ '// 3c <
$14,$14,$14,$14,$14,_ '// 3d =
$00,$41,$22,$14,$08,_ '// 3e >
$02,$01,$51,$09,$06,_ '// 3f ?
$32,$49,$79,$41,$3e,_ '// 40 @
$7e,$11,$11,$11,$7e,_ '// 41 A
$7f,$49,$49,$49,$36,_ '// 42 B
$3e,$41,$41,$41,$22,_ '// 43 C
$7f,$41,$41,$22,$1c,_ '// 44 D
$7f,$49,$49,$49,$41,_ '// 45 E
$7f,$09,$09,$09,$01,_ '// 46 F
$3e,$41,$49,$49,$7a,_ ''// 47 G
$7f,$08,$08,$08,$7f,_ '// 48 H
$00,$41,$7f,$41,$00,_ '// 49 I
$20,$40,$41,$3f,$01,_ '// 4a J
$7f,$08,$14,$22,$41,_ '// 4b K
$7f,$40,$40,$40,$40,_ '// 4c L
$7f,$02,$0c,$02,$7f,_ '// 4d M
$7f,$04,$08,$10,$7f,_ '// 4e N
$3e,$41,$41,$41,$3e],temp '// 4f O
chardata[char_row + 1] = temp


Return

Table2:
lu1 = charpos + char_row

lookup lu1, [$7f,$09,$09,$09,$06,_ '// 50 P
$3e,$41,$51,$21,$5e,_ '// 51 Q
$7f,$09,$19,$29,$46,_ '// 52 R
$46,$49,$49,$49,$31,_ '// 53 S
$01,$01,$7f,$01,$01,_ '// 54 T
$3f,$40,$40,$40,$3f,_ '// 55 U
$1f,$20,$40,$20,$1f,_ '// 56 V
$3f,$40,$38,$40,$3f,_ '// 57 W
$63,$14,$08,$14,$63,_ '// 58 X
$07,$08,$70,$08,$07,_ '// 59 Y
$61,$51,$49,$45,$43,_ '// 5a Z
$00,$7f,$41,$41,$00,_ '// 5b [
$02,$04,$08,$10,$20,_ '// 5c
$00,$41,$41,$7f,$00,_ '// 5d
$04,$02,$01,$02,$04,_ '// 5e
$40,$40,$40,$40,$40,_ '// 5f
$00,$01,$02,$04,$00,_ '// 60
$20,$54,$54,$54,$78,_ '// 61 a
$7f,$48,$44,$44,$38,_ '// 62 b
$38,$44,$44,$44,$20,_ '// 63 c
$38,$44,$44,$48,$7f,_ '// 64 d
$38,$54,$54,$54,$18,_ '// 65 e
$08,$7e,$09,$01,$02,_ '// 66 f
$0c,$52,$52,$52,$3e,_ '// 67 g
$7f,$08,$04,$04,$78,_ '// 68 h
$00,$44,$7d,$40,$00,_ '// 69 i
$20,$40,$44,$3d,$00,_ '// 6a j
$7f,$10,$28,$44,$00,_ '// 6b k
$00,$41,$7f,$40,$00,_ '// 6c l
$7c,$04,$18,$04,$78,_ '// 6d m
$7c,$08,$04,$04,$78,_ '// 6e n
$38,$44,$44,$44,$38,_ '// 6f o
$7c,$14,$14,$14,$08,_ '// 70 p
$08,$14,$14,$18,$7c,_ '// 71 q
$7c,$08,$04,$04,$08,_ '// 72 r
$48,$54,$54,$54,$20,_ '// 73 s
$04,$3f,$44,$40,$20,_ '// 74 t
$3c,$40,$40,$20,$7c,_ '// 75 u
$1c,$20,$40,$20,$1c,_ '// 76 v
$3c,$40,$30,$40,$3c,_ '// 77 w
$44,$28,$10,$28,$44,_ '// 78 x
$0c,$50,$50,$50,$3c,_ '// 79 y
$44,$64,$54,$4c,$44,_ '// 7a z
$00,$08,$36,$41,$00,_ '// 7b
$00,$00,$7f,$00,$00,_ '// 7c
$00,$41,$36,$08,$00,_ '// 7d
$10,$08,$08,$10,$08,_ '// 7e
$78,$46,$41,$46,$78], temp ' // 7f
chardata[char_row + 1] = temp


Return
'************************************************* *****************************


The following macro does the work.



ASM ;printstr2 to color LCD macro, '@ printstr2 x,y, "string2 to lcd at x,y"
printstr2 macro x2, y2, str2
local thestring2, overstr2

bra overstr2
thestring2
data str2,0
overstr2
MOVE?CB x2, _LCDx
MOVE?CB y2, _Row
MOVE?CW thestring2, _addr
L?CALL _stringout2
endm
ENDASM


You call the macro in your application with this
@ printstr2 25,20, "SSD2119 Controller"

This tells the macro to place the text at coordinates X =25, Y =20 and the text follows.

You will need to declare a number of variables
(see full program)

And filaly the sub that puts the text on the screen, I modified the original code to generate text in different sizes by setting the var "big" to; big =0 is 5x7 text, "big=1" is 10x14 text and "big=2" is 20x24 text.



'************************************************* ******************************
' Text
'************************************************* ******************************
stringout2:
lcdy = row
Readcode addr, char :
If char = 0 then return

gosub putclcdtext :
addr = addr + 1 :
lcdx = lcdx + 1 :

lcdy = row

goto stringout2


putclcdtext:
if char < 20 then return
if char > $7f then return

for char_row = 0 to 4
if char < $50 then
charpos = (((char & $ff)- $20)*5)
gosub table1

endif

if char > $4f then
charpos = (((char & $ff)- $50)*5)
gosub table2
endif

next char_row
if big = 0 then ' Normal 5x7 font
for j = 0 to 7 ' data bits 0 - 7

cmd = $004E : gosub lcd_write_CMD : dat = lcdx : gosub lcd_write_dat ' RAM Addsress counter set X
cmd = $004F : gosub lcd_write_CMD : dat = lcdy : gosub lcd_write_dat ' RAM Addsress counter set Y


for k = 1 to 5

dat = fcolor
temp = chardata[k]
if temp.0[j] = 0 then
dat = bcolor
endif
cmd = $0022 : gosub lcd_write_CMD
gosub lcd_write_dat
next k
dat = bcolor
gosub lcd_write_dat
lcdy = lcdy + 1

next j
lcdx = lcdx + 6


elseif big = 1 then ' big 10x14 font
for j = 0 to 7 ' data bits 0 - 7
for n = 0 to 1

cmd = $004E : gosub lcd_write_CMD : dat = lcdx : gosub lcd_write_dat ' RAM Addsress counter set X
cmd = $004F : gosub lcd_write_CMD : dat = lcdy : gosub lcd_write_dat ' RAM Addsress counter set Y


for k = 1 to 5
for m = 0 to 1
dat = fcolor
temp = chardata[k]
if temp.0[j] = 0 then
dat = bcolor
endif
cmd = $0022 : gosub lcd_write_CMD
gosub lcd_write_dat
next m
next k

dat = bcolor
gosub lcd_write_dat
lcdy = lcdy + 1
next n
next j
lcdx = lcdx + 10 '20X24
elseif big = 2 then
for j = 0 to 7 ' data bits 0 - 7
for n = 0 to 3

cmd = $004E : gosub lcd_write_CMD : dat = lcdx : gosub lcd_write_dat ' RAM Addsress counter set X
cmd = $004F : gosub lcd_write_CMD : dat = lcdy : gosub lcd_write_dat ' RAM Addsress counter set Y


for k = 1 to 5
for m = 0 to 3
dat = fcolor
temp = chardata[k]
if temp.0[j] = 0 then
dat = bcolor
endif
cmd = $0022 : gosub lcd_write_CMD
gosub lcd_write_dat
next m
next k

dat = bcolor
gosub lcd_write_dat
lcdy = lcdy + 1
next n
next j
lcdx = lcdx + 24

endif
return


Now you should be able to do the famous "Hello World" on the GLCD