TFT LCD Projects/Ideas/Applications Open Discussion.

Status
Not open for further replies.

ericgibbs

Well-Known Member
Most Helpful Member
hi,
A number of our members are developing projects using the ready available, low cost, small screen colour TFT LCD's.

To avoid hijacking other members Threads, I thought it would be a good idea to create a dedicated Thread where any member could submit their current work or ask questions relating to these TFT's.

I had a 9225 2.2" TFT project running, 18F4520, using Oshonsoft Basic and software SPI, which was slow.

With a little help from a couple of fellow members, it is now running hardware SPI with Oshonsoft Basic, 20MHz xtal, SPI clk at 5MHz.
The project now runs faster than the Arduino UNO with TFT.

Currently testing a Alpha Numeric Font writing program, it is quick.

Eric
Nigel Goodwin
Ian Rogers
 
Question 1...
I'm trying to add a constant array in Oshonsoft for the font.. Easy in C, but can't seem to do it in Oshonsoft.

In asm.. dt blah, blah...
In C.. const char font[] = { blah, blah ...

In Oshonsoft ????
 
hi,
I am using an Include file with Oshonsoft for LCD Fonts
E

Dim ary(6) as byte

ascval = char to display
Gosub chr2tft

eg:
chr2tft: ' enter with ascval , exit with ary(0) to (5) filled with pixel pattern 5*7 pix font

Select Case ascval
Case "A"
ary(0) =0x7e
ary(1) =0x11
ary(2) =0x11
ary(3) =0x11
ary(4) =0x7e

Case "B"
ary(0) =0x7f
ary(1) =0x49
ary(2) =0x49
ary(3) =0x49
ary(4) =0x36

Case "C"
ary(0) =0x3e
ary(1) =0x41
ary(2) =0x41
ary(3) =0x41
ary(4) =0x22

...............................

EndSelect
ary(5)=0x00 ' character spacing
Return
 
I have just done this... This is just numbers but the rest can follow...

Code:
Function fontread(addr As Word) As Byte
 Dim lowbyte As Byte
 Dim highbyte As Byte
 lowbyte = addr.LB
 highbyte = addr.HB
 
 
ASM:        movlw low fnt
ASM:        addwf lowbyte,w
ASM:        movwf TBLPTRL,A
ASM:        movlw high fnt
ASM:        addwfc highbyte,w
ASM:        movwf TBLPTRH,A
ASM:        movlw upper fnt
ASM:        addwfc upperbyte,w
ASM:        movwf TBLPTRU,A
ASM:        TBLRD*
ASM:        movfw TABLAT,A
  fontread = WREG
  Goto fin
ASM:fnt:    db 0x3e,0x51,0x49,0x45,0x3e
ASM:        db 0x00,0x42,0x7f,0x40,0x00
ASM:        db 0x42,0x61,0x51,0x49,0x46
ASM:        db 0x21,0x41,0x45,0x4b,0x31
ASM:        db 0x18,0x14,0x12,0x7F,0x10
ASM:        db 0x27,0x45,0x45,0x45,0x39
ASM:        db 0x3c,0x4a,0x49,0x49,0x30
ASM:        db 0x01,0x71,0x09,0x05,0x03
ASM:        db 0x36,0x49,0x49,0x49,0x36
ASM:        db 0x06,0x49,0x49,0x29,0x1e
fin:
End Function
Seems to work okay!!
 
Last edited:
On thinking about it... I'll need to swap the table init upside down as I need to add in the carry if low or high overflow.

Swapped the above code...
 
hi
I used this method for the 5110, its fast, even for horizontal scrolling.
E
'uses Case function to get correct font pattern

chr2lcd: ' enter with the ascval
SPICSOn

Select Case ascval
Case "A"
SPISend 0x7e
SPISend 0x11
SPISend 0x11
SPISend 0x11
SPISend 0x7e

Case "B"
SPISend 0x7f
SPISend 0x49
SPISend 0x49
SPISend 0x49
SPISend 0x36
''''+++++++++++++++++++++++++++++++++++ a bigger font section
If row = 1 Or row = 3 Or row = 5 Then
SPISend 0x00
SPISend 0x0f
SPISend 0x1f
SPISend 0x30
SPISend 0x30
SPISend 0x1f
SPISend 0x0f
SPISend 0x00
Endif
Case Else 'display a space for unrecognised ASCII
SPISend 0x00
SPISend 0x00
SPISend 0x00
SPISend 0x00
SPISend 0x00
SPISend 0x00
SPISend 0x00
SPISend 0x00

EndSelect

SPISend 0x00 'two bit gap between chars on the lcd display
SPICSOff

Return
 
Just tested the above code with 100 elements The overflow worked okay the font table is at 0x3AE and I read the 94th element at 0x40c... Cool... The reason I want it like this is so I can port in fonts... Copy and paste... Much quicker than typing them all in..
 
Problem number 2... After sorting the arrays ROM and RAM... I have just found out ( remembered) one of the reasons I don't use Vladamir's software any more.

He doesn't support negative numbers!!! so:-
while x >= 0
Doesn't work..... My circles turn out to be diamonds and I can only draw 45 degree lines...
 
hi Ian.
I recall camerart had a similar problem.
I got around it by testing for If x < 0xff then .....

You could use Single 'X' Dim.
E
 
Yeah!! Fixed it..

If radiuserror < 0x8000 And radiuserror >= 0 Then....

Circles, boxes and lines are done... I'm doing the character blit now... I'll do 5x7 font and also a 2x version to double the font size...
 
I've done circles, boxes, lines and a font ( only up to C as I got bored and I was only testing!!)

I will continue but here is the code to drive a nokia 5110 with basic primitives..

Code:
Define CONFIG1L = 0x00
Define CONFIG1H = 0x08
Define CONFIG2L = 0x1e
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x83
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
Symbol ss = LATC.2
Symbol d_c = LATC.1
Symbol rst = LATC.0
TRISC = 0x10
Dim x As Word
Dim ret As Byte
Dim scrbuf(504) As Byte
Dim lp As Byte
OSCCON = 0x70
ADCON1 = 0xf
Call spi_init()
TRISA.5 = 0
LATA.5 = 0
lp = 22
WaitMs 10
Call initscreen()
loop:
 
 Call clearscreen()
 Call circle(42, 24, lp)
 Call circle(42, 24, 4)
 Call circle(42, 24, 22)
 Call box(1, 1, 81, 47)
 Call charput(4, 5, 65)
 Call charput(10, 5, 66)
 Call charput(16, 5, 67)
 lp = lp - 1
 If lp = 5 Then lp = 22
 Call blit()
 Goto loop
End                                               
'----------------------------------------
Proc spi_init()
 TRISC.5 = 0
 TRISC.2 = 0
 TRISC.4 = 1
 TRISC.3 = 0
 ss = 1
 SSPSTAT = 0
 'SSPSTAT.CKE = 1  'clock edge un remark for trailing edge
 SSPCON1 = 0x20  'full whack... at 8mhz 2mhz operation no SS control
      '00 = fosc/4.. 01 = fosc /16
      '10 = fosc/64.. 11 contolled by timer2.
 SSPCON1.CKP = 1  'clock polarity unremark for high polarity
End Proc                                          
'----------------------------------------
Function do_spi_8(data As Byte) As Byte
 do_spi_8 = SSPBUF
 SSPBUF = data
 While Not SSPSTAT.BF
 Wend
 
End Function                                      
'----------------------------------------
Proc initscreen()
 rst = 0
 WaitMs 100
 rst = 1
 Call sendcommand(0x21)
 Call sendcommand(0x13)
 Call sendcommand(0x07)
 Call sendcommand(0xc0)
 Call sendcommand(0x20)
 Call sendcommand(0x0c)
End Proc                                          
'----------------------------------------
Proc blit()
  d_c = 1
  ss = 0
  For x = 0 To 503
   ret = do_spi_8(scrbuf(x))
  Next x
  ss = 1
End Proc                                          
'----------------------------------------
Proc clearscreen()
  For x = 0 To 503
   scrbuf(x) = 0
  Next x
End Proc                                          
'----------------------------------------
Proc sendcommand(cmd As Byte)
  d_c = 0
  ss = 0
  ret = do_spi_8(cmd)
  ss = 1
End Proc                                          
'----------------------------------------
Proc senddata(data As Byte)
  d_c = 1
  ss = 0
  ret = do_spi_8(data)
  ss = 1
End Proc                                          
'----------------------------------------
Proc box(x1 As Word, y1 As Word, x2 As Word, y2 As Word)
 Call line(x1, y1, x2, y1)
 Call line(x1, y1, x1, y2)
 Call line(x1, y2, x2, y2)
 Call line(x2, y1, x2, y2)
End Proc                                          
'----------------------------------------
Proc charput(x1 As Word, y1 As Word, ch As Byte)
Dim loop As Word
Dim addr As Word
Dim tmp As Word
Dim char As Byte
Dim tmp2 As Word
Dim shift As Byte
Dim shift2 As Byte
Dim msk As Byte
Dim msk2 As Byte
 addr = ShiftRight(y1, 3)
 shift = ShiftLeft(addr, 3)
 shift = y1 - shift
 shift2 = 8 - shift
 addr = addr * 84
 addr = addr + x1
 ch = ch - 0x20
 For loop = 0 To 4
  tmp = ch * 5 + loop
  char = fontread(tmp)
  tmp2 = addr + loop
  msk = scrbuf(tmp2)
  msk2 = ShiftLeft(char, shift)
  msk = msk Xor msk2
  scrbuf(tmp2) = msk
  tmp2 = addr + loop + 84
  msk = scrbuf(tmp2)
  msk2 = ShiftRight(char, shift2)
  msk = msk Xor msk2
  scrbuf(tmp2) = msk
 Next loop

End Proc                                          
'----------------------------------------
Proc circle(cx As Byte, cy As Byte, rad As Byte)
Dim x As Byte
Dim y As Byte
Dim tmpx As Word
Dim tmpy As Word
Dim xchange As Word
Dim ychange As Word
Dim radiuserror As Word
x = rad
y = 0
xchange = 1 - 2 * rad
ychange = 1
radiuserror = 1 - rad
While x >= y  'now the rest of them..
 tmpx = cx + x
 tmpy = cy + y
 Call putpixel(tmpx, tmpy)
 tmpx = cx - x
 tmpy = cy + y
 Call putpixel(tmpx, tmpy)
 tmpx = cx - x
 tmpy = cy - y
 Call putpixel(tmpx, tmpy)
 tmpx = cx + x
 tmpy = cy - y
 Call putpixel(tmpx, tmpy)
 tmpx = cx + y
 tmpy = cy + x
 Call putpixel(tmpx, tmpy)
 tmpx = cx - y
 tmpy = cy + x
 Call putpixel(tmpx, tmpy)
 tmpx = cx - y
 tmpy = cy - x
 Call putpixel(tmpx, tmpy)
 tmpx = cx + y
 tmpy = cy - x
 Call putpixel(tmpx, tmpy)
 y = y + 1
 radiuserror = radiuserror + ychange
 ychange = ychange + 2
 If radiuserror < 0x8000 And radiuserror >= 0 Then
  x = x - 1
  radiuserror = radiuserror + xchange
  xchange = xchange + 2
 Endif
Wend
End Proc                                          
'----------------------------------------
Proc line(x1 As Word, y1 As Word, x2 As Word, y2 As Word)
 Dim x As Word
 Dim y As Word
 Dim dx As Word
 Dim dy As Word
 Dim incx As Word
 Dim incy As Word
 Dim balance As Word
 incx = 0
 incy = 0
 If x2 > x1 Then
  dx = x2 - x1
  incx = incx + 1
 Else
  dx = x1 - x2
  incx = incx - 1
 Endif
 If y2 > y1 Then
  dy = y2 - y1
  incy = incy + 1
 Else
  dy = y1 - y2
  incy = incy - 1
 Endif
 x = x1
 y = y1
 If dx >= dy Then
  dy = ShiftLeft(dy, 1)
  balance = dy - dx
  dx = ShiftLeft(dx, 1)
  While x <> x2
   Call putpixel(x, y)
   If balance < 0x8000 And balance >= 0 Then
    y = y + incy
    balance = balance - dx
   Endif
   balance = balance + dy
   x = x + incx
   Wend
  Call putpixel(x, y)
 Else
  dx = ShiftLeft(dx, 1)
  balance = dx - dy
  dy = ShiftLeft(dy, 1)
  While y <> y2
   Call putpixel(x, y)
   If balance < 0x8000 And balance >= 0 Then
    x = x + incx
    balance = balance - dy
   Endif
   balance = balance + dx
   y = y + incy
   Wend
  Call putpixel(x, y)
 Endif
End Proc                                          
'----------------------------------------
Proc putpixel(x As Word, y As Word)
 Dim addr As Word
 Dim tmp As Word
 Dim pix As Byte
 Dim msk As Byte
 tmp = ShiftRight(y, 3)
 pix = ShiftLeft(tmp, 3)
 pix = y - pix
 tmp = tmp * 84
 tmp = tmp + x
 pix = LookUp(1, 2, 4, 8, 16, 32, 64, 128), pix
 msk = scrbuf(tmp)
 msk = msk Or pix
 scrbuf(tmp) = msk
End Proc                                          
'----------------------------------------
Function fontread(addr As Word) As Byte
 Dim lowbyte As Byte
 Dim highbyte As Byte
 Dim upperbyte As Byte
 lowbyte = addr.LB
 highbyte = addr.HB
 upperbyte = 0
 
 
ASM:        movlw low fnt
ASM:        addwf lowbyte,w
ASM:        movwf TBLPTRL,A
ASM:        movlw high fnt
ASM:        addwfc highbyte,w
ASM:        movwf TBLPTRH,A
ASM:        movlw upper fnt
ASM:        addwfc upperbyte,w
ASM:        movwf TBLPTRU,A
ASM:        TBLRD*
ASM:        movfw TABLAT,A
  fontread = WREG
  Goto fin
ASM:fnt:    db 0x00,0x00,0x00,0x00,0x00 ;(space)
ASM:        db 0x00,0x00,0x5f,0x00,0x00 ;!
ASM:        db 0x00,0x07,0x00,0x07,0x00 ;quotes
ASM:        db 0x14,0x7f,0x14,0x7f,0x14 ;#
ASM:        db 0x24,0x2a,0x7f,0x2a,0x12 ;$
ASM:        db 0x23,0x13,0x08,0x64,0x62 ;%
ASM:        db 0x36,0x49,0x55,0x22,0x50 ;&
ASM:        db 0x00,0x05,0x03,0x00,0x00 ;/
ASM:        db 0x00,0x1c,0x22,0x41,0x00 ;(
ASM:        db 0x00,0x41,0x22,0x1c,0x00 ;)
ASM:        db 0x08,0x2a,0x1c,0x2a,0x08 ;*
ASM:        db 0x08,0x08,0x3e,0x08,0x08 ;+
ASM:        db 0x00,0x50,0x30,0x00,0x00 ;,
ASM:        db 0x08,0x08,0x08,0x08,0x08 ;-
ASM:        db 0x00,0x30,0x30,0x00,0x00 ;.
ASM:        db 0x20,0x10,0x08,0x04,0x02 ;/
ASM:        db 0x3e,0x51,0x49,0x45,0x3e ;0
ASM:        db 0x00,0x42,0x7f,0x40,0x00 ;1
ASM:        db 0x42,0x61,0x51,0x49,0x46 ;2
ASM:        db 0x21,0x41,0x45,0x4b,0x31 ;3
ASM:        db 0x18,0x14,0x12,0x7F,0x10 ;4
ASM:        db 0x27,0x45,0x45,0x45,0x39 ;5
ASM:        db 0x3c,0x4a,0x49,0x49,0x30 ;6
ASM:        db 0x01,0x71,0x09,0x05,0x03 ;7
ASM:        db 0x36,0x49,0x49,0x49,0x36 ;8
ASM:        db 0x06,0x49,0x49,0x29,0x1e ;9
ASM:        db 0x00,0x36,0x36,0x00,0x00 ;:
ASM:        db 0x00,0x56,0x36,0x00,0x00 ;;
ASM:        db 0x00,0x08,0x14,0x22,0x41 ;<
ASM:        db 0x14,0x14,0x14,0x14,0x14 ;=
ASM:        db 0x41,0x22,0x14,0x08,0x00 ;>
ASM:        db 0x02,0x01,0x51,0x09,0x06 ;?
ASM:        db 0x32,0x49,0x79,0x41,0x3E ;@
ASM:        db 0x7E,0x11,0x11,0x11,0x7E ;A
ASM:        db 0x7F,0x49,0x49,0x49,0x36 ;B
ASM:        db 0x3E,0x41,0x41,0x41,0x22 ;C
fin:
End Function
 
hi I,
This is the same Font matrix I used on the 5110, it looks the same as yours.
May save you a little time in writing the D to Z etc.....
E

EDIT:

Modified the listing to make it easier to copy/paste
font1x.txt
 

Attachments

  • font1.bas
    3.9 KB · Views: 339
  • fontx1.txt
    3.8 KB · Views: 327
Last edited:
Hi Eric.. I have the font... I have also placed all the characters up to "Y"... But!! I hit a wall... I have 290 bytes in my table If I increase to "Z" now 295 bytes, I get stack overflow?? Not getting my head around this as the table reads on the pic 18 are 24 bit.. It must be a glitch in Vlads software as the table will work.... Its not the access as even if I only call numbers in the program it still barfs... It seems to be 290 bytes is the limit
 
hi Ian,
A work around would be to test if the character in the string to be displayed, is less than 'A' ie the @ symbol and down to the (space) char.
Place (space) thru to @ in their own array.
eg:
ASM:fnt2: db 0x00,0x00,0x00,0x00,0x00 ;(space)
++++++
ASM: db 0x32,0x49,0x79,0x41,0x3E ;@

This need for work arounds on Oshonsoft have often been reported to Vlad, but to no avail.

E
 
Hi Eric.. Tried that... I made two tables.... It still barfed with the exact same... My last try is to include the ASM last as there cannot be any basic intervention and the asm will be the last thing in program memory.. I'll let you know how it goes..

I'm only doing this to help Oshon basic users... I have a project on the go, developing a pic18f26k80 and a serial 128x64 adafruit screen... I wouldn't dare do it n basic..

Any help marrying ASM and Basic must be useful!!
 
hi Ian,
I have download your basic /asm code.
extended it by copy/paste the asm chars, now have 350 lines of asm chars, it assembles OK.?
I am using a 18F4520, what are you programming.

Like you, its for interest only, I have no application.

Now have the 9225 TFT running with Basic OK.

E
 

Attachments

  • A002.gif
    12.8 KB · Views: 360
This is an extract from the Osh docs

If large amount of assembler code should be used, it can be loaded from an external assembler file and included to the current program by using IncludeASM directive. Its only argument is a string containing the path to the external .ASM file. This can be the full path or only the file name, if the external file is located in the same folder as the current basic program file. During the compilation process the external assembler code will be appended to the current program at its end, and not at the position of the directive. Multiple files can be included with separate IncludeASM directives. External assembler files should not contain ASM: prefix used for inline assembler code. It is also strongly suggested not to use ORG directives in the external assembler code
 
Okay!! This turned up late on Friday!! **broken link removed**
I know a tad expensive, but I got it with prime so it was here in a day..
Pulled out my Arduino... Dowloaded the ILI9341 driver Opened the GFXtest sketch!!
Nada!!!! Checked my connections ( oooo! more than several times ) Nada!!

I know the Arduino was talking to the screen because the reply's were correct ( according to Lay Ada's web site )!!

I have been at it all morning!! Then I read on a forum that the LDO on these cheap boards aren't particularly very good!

Swapped it all over to 3.3v (I used a 74hc125 ) bridged out the LDO.... Perfect!

So buy one of these at you own peril!! My thoughts are.. If the LDO cannot power the screen what other components on this device are bluddy awful!!

I must admit.. At 3.3v its working pretty good!!
 
Swapped it all over to 3.3v (I used a 74hc125 ) bridged out the LDO.... Perfect!
hi Ian,
This is exactly the same problem I have already posted with the 9225 and Arduino UNO, despite having a onboard hc245, the 9225 does not like 5v signal levels.!
To get reliable operation I had to fit 2k2's in the 9225 signal lines.
On the final project build I used a level shifter 5v down to 3.3v, runs perfectly with a PIC , using a 20MHz xtal, 5 MHz SPI clock.

E
BTW: have you got the LED back lite working,? I cannot
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…