PDA

View Full Version : A tft addin for pbp3



richard
- 20th June 2015, 12:30
The first of my tft modules arrived today a 1.8 inch st7735 with spi interface

so far I have a scalable chr32 to 90 font and a rectangle fill utility . no one responded to my previous offer to make joint effort to develop this idea but now that I have something working it might be different . so I will have one more go ,if no one is interested I will just develop it for myself .
this is just a demo and not documented at all ( it would be a waste of time if there is no interest)

richard
- 20th June 2015, 23:20
a photo of the output

pedja089
- 21st June 2015, 12:10
Very nice. And nice example for using USERCOMMAND :)

Heckler
- 21st June 2015, 19:34
That's very nice!

yes, please do share... I'd live to try one of those little displays.

thanks

richard
- 21st June 2015, 23:42
glad to see some interest

some ideas needed :-


currently to display a string


fg=$F800 ; set colour
TEXTSIZE=2
ARRAYWRITE buffer,["HELLO WORLD",0]
GLCDC 1,63 ; set x ,y position
ch=0
WHILE (ch< 32) AND (buffer[ch]>0 ) ; check for end of string
GLCDC buffer[ch] ; disp ch
ch=ch +1
WEND
I would rather have a usercommand

GLCDS 1,63 ,buffer
but I can't figure a way of getting the address of buffer from the usercommand macros
GLCDS 1,63 ,"HELLO WORLD"
but I can't figure a way of getting the string data from the usercommand macros


I would like to put the display hardware dependent code into a separate include file (that way other displays could be incorporated)


not all the useful input combinations have had their macros written for each user command


more user commands are required
drawHline,drawVline,drawline,drawcircle,drawrect,f illcircle



the hardware connection interface is defined like this



tft_dc_bit con 4
tft_cs_bit con 1
tft_rst_bit con 8
tft_port var latd

its a bit clunky I sure there are better ways


bit banging the data could be investigated


over to you

richard
- 21st June 2015, 23:44
another pic

pedja089
- 22nd June 2015, 02:03
Never done something like that, but as DT said there is no better manual than .mac and .lib files.
So here is what I found.

Compiler use this macro from pbppic18.mac file when LCDOUT STR is used

;************************************************* ***************
;* LCDOUTSTR?B : Macro - Lcdout string *
;* *
;* Input : B[] *
;* Output : None *
;* *
;* Notes : *
;************************************************* ***************

LCDOUTSTR?B macro Bin
MOVE?CW LCDOUTJ, R8 'dont know what this line do
MOVE?CB high (Bin), FSR2H 'load highbyte of adr, from pbppic18.lib Macro - Move BYTE Variable into WORD Variable
MOVE?CA low (Bin) 'load low byte of adr to w, from pbppic18.lib MOVE?CA : Macro - Move constant into W

L?CALL SEROUT2STR
endm


SEROUT2STR is in file pbppic18.

SEROUT2STR movwf FSR2L ; Set up for index
serout2strloop movf POSTINC2, W ; Get a character
bnz serout2str1 ; Not null char


So you could use in your program something like this:

TFTSTR?B macro Bin
MOVE?CB high (Bin), FSR2H ;load highbyte
MOVE?CB low (Bin), FSR2L ;load low byte
local tftstrloop
local tftStrDone
tftstrloop movf POSTINC2, W ; Get a character, then increment pointer
BZ tftStrDone ;All strings must end with 0
;Not Null char
L?CALL tftWoutput; CALL print char in W to TFT
BRA tftstrloop ;Get next chr

tftStrDone: ;Null char

endm ;end of macro

EDIT:
You could also use PBP's routine like LCDOUTSTR do, but you must see what this flags do
LCDOUTJ_USED = 1
SEROUT2STR_USED = 1
And how JUMPMAN is used.

Archangel
- 22nd June 2015, 03:25
Hi Richard,
Where is the subroutine tft_init ?
I have ordered 2 from your seller should get then before Christmas . . .
These look very promising .. .

richard
- 22nd June 2015, 04:30
updated version , complete this time {end must have fallen off first time}

richard
- 22nd June 2015, 04:35
MOVE?CB high (Bin), FSR2H ;load highbyte
MOVE?CB low (Bin), FSR2L ;load low byte


that's what I was looking for thanks pedja089

richard
- 22nd June 2015, 06:02
that's one down , works like a dream


GLCDSTR?CCB macro Xin ,Yin ,Bin
movlw Xin
CHK?RP _X
MOVWF _X
movlw Yin
CHK?RP _Y
MOVWF _Y
MOVE?CB high (Bin), FSR2H ;load highbyte
MOVE?CB low (Bin), FSR2L ;load low byte
strloop movf POSTINC2, W ; Get a character
bnz outstr1 ; Not null char
bra exstr
outstr1 MOVWF _g_chr
L?CALL _gcga
bra strloop
exstr
endm

richard
- 22nd June 2015, 06:31
woops - looping in macro for multiple calls is a no go
needs to be like this



GLCDSTR?CCB macro Xin ,Yin ,Bin
movlw Xin
CHK?RP _X
MOVWF _X
movlw Yin
CHK?RP _Y
MOVWF _Y
MOVE?CB high (Bin), FSR2H ;load highbyte
MOVE?CB low (Bin), FSR2L ;load low byte
L?CALL bfill

endm



bfill
Next_Char
movf POSTINC2, W ; Get a character
bnz outchr ; Not null char
bra exstr2
outchr MOVWF _g_chr
L?CALL _gcga
bra Next_Char
exstr2 return

richard
- 22nd June 2015, 12:00
now have strings and circles, moved font to include file



USERCOMMAND?S HOW TO USE THIS STILL ELUDES ME would be nice for display of "constant" string

pedja089
- 22nd June 2015, 12:23
You can use label in macro and multiple call to that macro.
Just need to define your labels as local.
Here is local used in my example:

TFTSTR?B macro Bin
MOVE?CB high (Bin), FSR2H ;load highbyte
MOVE?CB low (Bin), FSR2L ;load low byte
local tftstrloop
local tftStrDone
tftstrloop movf POSTINC2, W ; Get a character, then increment pointer
BZ tftStrDone ;All strings must end with 0
;Not Null char
L?CALL tftWoutput; CALL print char in W to TFT
BRA tftstrloop ;Get next chr

tftStrDone: ;Null char

endm ;end of macro
But way your done use less FLASH ;)
And you can make bfill little smaller

bfill
Next_Char
movf POSTINC2, W ; Get a character
bz exstr2 ; Null char
MOVWF _g_chr
L?CALL _gcga
bra Next_Char
exstr2 return
To save few bytes in FLASH.
And I'll suggest you to put TFT_ in front all labels and variable names so there is minimal chance for user to duplicate label/variable or unintentional use one of tft variables.

pedja089
- 22nd June 2015, 12:41
And for "Constant String" I don't know how to implement it with user command. But I know assembler part ;)
Here is use of asm macro
PrintStr 0,0," Test Clock"
And macro:

PrintStr macro x, y, Str
local TheString, OverStr ; define local labels so you can call macro multiple times
goto OverStr ' goto over string stored in FLASH, so processor can't execute that
TheString ;label to get address of your string
data Str, 0 ;add string to flash at TheString address and end string with 0
OverStr
MOVE?CB x, _GLCD_X
MOVE?CB x, _GLCD_SX
MOVE?CB y, _PosY
MOVE?CW TheString, _GLCD_Addr ;move addres of string to word variable, don't know how it would work with device that have more than 65535K of FLASH???
L?CALL _GLCD_StringOut
endm
ENDASM

GLCD_StringOut:
Readcode GLCD_Addr, GLCD_Char ' Get a character
if GLCD_Char = 0 then RETURN ' Look for Null char, Stop if found
......
RETURN

This is from example for nokia 3310 lcd, that I tried to get to work with GLCD with KS0108 controler.

richard
- 23rd June 2015, 02:44
Just need to define your labels as local.
brilliant , thanks for the tip pedja089


And for "Constant String" I don't know how to implement it with user command
seems nobody does

I might just stick to my flash2ram macro for now

richard
- 23rd June 2015, 07:05
now with drawline and a bit of optimising
I will wait now for my 2.8" ILI9340C tft display to arrive and see if I can separate out a hw include for each type

pedja089
- 23rd June 2015, 08:02
Compiler know how to handle user command with string.
So lets try to get something...
Try this code:


GLCD_Addr var word
GLCD_Char var byte
asm
;----[String]---------------------------------------------------------------
GLCDC?S macro Cin
local TheString, OverStr ; define local labels so you can call macro multiple times
goto OverStr ; goto over string stored in FLASH, so processor can't execute that
TheString ;label to get address of your string
data Cin, 0 ;add string to flash at TheString address and end string with 0
OverStr
MOVE?CW TheString, _GLCD_Addr ;move addres of string to word variable, don't know how it would work with device that have more than 65535K of FLASH???
L?CALL _GLCD_StringOut
endm

ENDASM
GLCD_StringOut:
Readcode GLCD_Addr, GLCD_Char ' Get a character
if GLCD_Char = 0 then RETURN ' Look for Null char, Stop if found

richard
- 23rd June 2015, 08:29
that's got it



GLCD_StringOut:
Readcode GLCD_Addr+j, g_chr ' Get a character
if g_chr = 0 then RETURN ' Look for Null char, Stop if found
j=j+1
gosub gcga
goto GLCD_StringOut



;----[String]---------------------------------------------------------------
GLCDC?S macro Cin
local TheString, OverStr ; define local labels so you can call macro multiple times
goto OverStr ; goto over string stored in FLASH, so processor can't execute that
TheString ;label to get address of your string
data Cin, 0 ;add string to flash at TheString address and end string with 0
OverStr
movlw 0
CHK?RP _j
MOVWF _j
MOVE?CW TheString, _GLCD_Addr ;move addres of string to word variable, don't know how it would work with device that have more than 65535K of FLASH???
L?CALL _GLCD_StringOut
endm


good work

pedja089
- 23rd June 2015, 09:11
You don't need J var. Just increment GLCD_Addr.

GLCD_StringOut:
Readcode GLCD_Addr, g_chr ' Get a character
if g_chr = 0 then RETURN ' Look for Null char, Stop if found
GLCD_Addr=GLCD_Addr+1
gosub gcga
goto GLCD_StringOut
And If you need to clear variable, you always can use CLRF, it's just shorter then loading 0 to w then from W to variable.
And if you want to avoid CHK?RP, declare variable to BANKA.

HenrikOlsson
- 23rd June 2015, 09:59
Hi,
This is great stuff, very nice work!

I will wait now for my 2.8" ILI9340C tft display to arrive and see if I can separate out a hw include for each type
May I suggest that you instead look into the posibillity of having it all in one file or set of files and make use of conditional compilation features to select between the targeted controller?

/Henrik.

richard
- 23rd June 2015, 10:32
You don't need J var. Just increment GLCD_Addr.
good idea, the extra eyes are very handy

and henrik
I'm not sure how different the hardware will be , when I set it up your very welcome to contribute some conditional compilation expertise.
the more heads we get working on this sort of thing the better. if arduino can have a free lib for everything at least we could have something for popular devices.
maybe some public domain free addins will breathe a bit of life back into pbp.
I feel that now that usefulness of usercommand macros are endless and have been largely unexplored on the forum

richard
- 23rd June 2015, 10:42
And if you want to avoid CHK?RP, declare variable to BANKA.
the book says that to declare a variable in BANKA is not guaranteed its just a suggestion to the compile process. if this is just an addon to a much larger project I'm thinking CHK?RP is probably a good thing just in case
but I'm open to suggestion

pedja089
- 23rd June 2015, 11:30
If variable doesn't fit into BANKA, then MPASM show error.
Used almost in all my project, and always worked fine. Also when coding in ASM, I use SYSTEM, so there is no annoying underscore in front of variable name.
EDIT:
From manual:
BANKx Instructs PBP to locate the variable in a specific bank of RAM.
If things as address of variable, and bank of variable not guarantied if you specify them, then that is idiotic :eek:
I'm sure if you specify location and bank of variable, compiler will try to fit in that location, otherwise throw error or at last warning.

richard
- 23rd June 2015, 11:33
circles and lines and constant string

richard
- 23rd June 2015, 13:07
If variable doesn't fit into BANKA, then MPASM show error.
Used almost in all my project, and always worked fine. Also when coding in ASM, I use SYSTEM, so there is no annoying underscore in front of variable name.
EDIT:
From manual:
BANKx Instructs PBP to locate the variable in a specific bank of RAM.
If things as address of variable, and bank of variable not guarantied if you specify them, then that is idiotic :eek:
I'm sure if you specify location and bank of variable, compiler will try to fit in that location, otherwise throw error or at last warning.
yet in 7.3

You can suggest to PBP a particular bank to place the variable in:
penny VAR WORD
BANK0
nickel VAR BYTE
BANK1
If specific bank requests are made, those are handled first. If there is not enough room in a requested bank, the first available space is used and a warning is issued.






but you get a warning

pedja089
- 23rd June 2015, 14:15
I newer see that syntax...
I use pdf that came with PBP 3
PICBASIC PRO™ Compiler
REFERENCE MANUAL
Revised March 6, 2013

Bank should be stated after variable type.
eg
ticker VAR BYTE BANK0 SYSTEM 'Creates "ticker" as a BYTE in BANK0, with no Assembly prefix character
wsave VAR BYTE $70 'Creates "wsave" at RAM address 0x70 (hex)

HenrikOlsson
- 23rd June 2015, 19:04
Richard,
I'd be happy to help if I can. You're WAY ahead of me with the usercommand and assembly type stuff so I just sit back and admire your work.

Unfortunately the forum (or my computer(s)) no longer allows me to download any attachments. Even when logged all it serves me is a file called attachment.php. Had that happen before, then it worked with another computer but not any more.

/Henrik.

Ioannis
- 23rd June 2015, 19:39
I have this problem too. But if I rename the file it opens normally.

Ioannis

richard
- 23rd June 2015, 22:57
I newer see that syntax...
I use pdf that came with PBP 3
PICBASIC PRO™ Compiler
REFERENCE MANUAL
Revised March 6, 2013

Bank should be stated after variable type.
eg
ticker VAR BYTE BANK0 SYSTEM 'Creates "ticker" as a BYTE in BANK0, with no Assembly prefix character
wsave VAR BYTE $70 'Creates "wsave" at RAM address 0x70 (hex)

the forum messes with the white space so the layout of my post was a bit off looking, but look at your reference manual pdf section 7.3 ram allocation page 265 ,thats what I'm referring to.

richard
- 26th June 2015, 12:36
The 2.2 " ili9341 (ili9340c how do tell) arrived today , after resoldering all the dry joints on the module it works .
I have separated things out like this main pbp pgm --- usercommand pbpmod file , an include bas file for either st7735 or ili9341 and a font bas file


in the pbp file
your hardware connections

;----GLOBAL----HW---------
SSP_IF VAR PIR3.7 ; must match your spi port
tft_dc_bit con 32 ;5 binary weighted pin values
tft_cs_bit con 16 ;4
tft_rst_bit con 128 ;7
tft_port var lath ; ; the output port for control signals


includes



INCLUDE "glcd_chr.pbpmod" ;glcdc
include "tft-ILI9431.bas" one or the other not both
; include "tft-ST7735.bas" one or the other not both

INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
INCLUDE "Elapsed_INT-18.bas"
INCLUDE "font7x8.bas"


in the usercommand file glcd_chr
WIDTH con 320;160 X
HEIGHT con 240; 128 Y
set to appropriate values

and this bit needs to match your spi port too a definite conditional compile potential here

TFT_CMD:
spi_cbyte :
tft_port = tft_port & (~ tft_dc_bit )
TFT_DATA:
spi_byte :
@ movff INTCON , _p_int
@ bcf INTCON ,7
tft_port = tft_port& (~ tft_cs_bit )
SSP_IF = 0
SSP2BUF = CMD
WHILE SSP_IF =0 ' wait for SPI interupt flag
wend
tft_port = tft_port | ( tft_dc_bit| tft_cs_bit )

@ movff _p_int , INTCON
return



and off you go

I would have liked to have the hw connections and the height width in the relevant hw include file but that presented too many issues for me

richard
- 26th June 2015, 12:41
forgot the happy snap

visnja30
- 26th June 2015, 21:58
HELLO Richard,
If you could give me some explanations about connections of the LCD display on PIC processor.
I just ordered one piece from eBay and on it I have these pins:


LCD DISPLAY ILI9341 --------> PIC-PROCESSOR
VCC---->3.3V
GND--->ground
LED--->
CS---->
D/C------->
RESET---->
SDI------>
SDO----->
SCK------->

I don't now how to connect it on PIC?

richard
- 26th June 2015, 23:54
cs,d/c,reset all need to be on the same port / sdi and sck connect to a h/w spi port (adjust code to suit)

LCD DISPLAY ILI9341 --------> PIC-PROCESSOR
VCC---->3.3V ( seems to be ok with 5v the board has an onboard regulator) but 3.3v works too
GND--->ground
LED---> -----------3.3v
CS----> in my example porth.4
D/C-------> in my example porth.5
RESET----> in my example porth.5
SDI------> in my example portd.4 sdo2 on pic
SDO-----> n/c
SCK-------> in my example portd.6 sck2 o pic

st7735 is the same but has no sdo pin

Aussie Barry
- 27th June 2015, 01:10
Hi Richard,

I am keen to replicate the great work you are doing with these TFT displays.
I have looked on eBay for an ILI9341 display and there appears to be a gazillion of them to choose from.
Can you share information on the eBay seller you bought your display from?

Cheers
Barry
VK2XBP

richard
- 27th June 2015, 01:32
hi barry ,these are what I used I'm sure the others would be ok too just make sure the I/f is spi
http://www.ebay.com.au/itm/271683495419?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
http://www.ebay.com.au/itm/191534577067?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

Aussie Barry
- 27th June 2015, 05:05
Thanks Richard.

I have now placed an order and hope to take delivery some time in July.

Cheers
Barry
VK2XBP

Gusse
- 27th June 2015, 15:58
Very nice work Richard!
ILI9341 based TFT display with resistive touch screen could be the module that I was searching.
With STMPE610 touch controller (SPI/I2C) it would be easy to make systems that do not need any additional input devices (buttons/joystick).

visnja30
- 27th June 2015, 20:22
Hi Richard

I am little confused how to adjust code to work.
I have a PIC18F45K22 and I plan to use it with your code but I never work with this PIC processor and I need some Help to configure it.


From datasheet of PIC18F45K22 PORTD.0 is SPI clock and PORTD.4 i SPI data out.

What I must change in your TFT_demo code to adjust PIC pin to work with TFT display.
Whether the pins of TFT displays D/C and RESET connected together on the same pin of the PIC processors or not.


;----GLOBAL----HW---------
SSP_IF VAR PIR3.7
tft_dc_bit con 32 ;5
tft_cs_bit con 16 ;4
tft_rst_bit con 128 ;7
tft_port var lath




INCLUDE "glcd_chr.pbpmod" ;glcdc
include "tft-ILI9431.bas"
; include "tft-ST7735.bas"
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
INCLUDE "Elapsed_INT-18.bas"
INCLUDE "font7x8.bas"


ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE


ENDASM
@ INT_ENABLE TMR1_INT








define OSC 48

' osccon=$70 '64 mhz
OSCTUNE.6=1
trisb.7=0
trish=0 ' each pin on d has a led for debug
trisd.6=0 ;sck
trisd.4=0 ;sdo

BOXX VAR BYTE
BOXY VAR BYTE
BOXZ VAR BYTE
disp var byte
tmp var word
buff var byte[32]
SSP2CON1=$20 ;$20 works too
SSP2STAT=$40

;led var latd.7
latb.7=1

;led=1
gosub tft_init

Serout2 PORTb.7,84,["ready ",#latd, 13,10]
glcdc font7x8 ;SET FONT



is this OK?

[CODE];----GLOBAL----HW---------
SSP_IF VAR PIR3.7 'I don't understand what it mean

symbol tft_dc_bit = PORTB.5
symbol tft_cs_bit = PORTB.4
symbol tft_rst_bit = PORTB.7

tft_port var PORTB

SDi from display I connect to PORD.4 and SCK from display I connect to PORTD.0 on PIC processor

richard
- 28th June 2015, 04:42
SSP_IF VAR PIR3.7 'I don't understand what it mean

THE SSP_IF VAR IS an alias to the SSP Interrupt Flag where PIR3.7 is the SSP2IF if you use ssp1 then use PIR1.3 for your chip




symbol tft_dc_bit = PORTB.5
symbol tft_cs_bit = PORTB.4
symbol tft_rst_bit = PORTB.7

you are asking for rmw trouble by using portb use latb instead


symbol tft_dc_bit = latb.5 >>with matching constant tft_dc_bit con 32 ie 2^5
symbol tft_cs_bit = latb.4 " " tft_cs_bit con 16 ie 2^4
symbol tft_rst_bit = latb.7 " " tft_rst_bit con 128 ie 2^7
tft_port var latb

SDi from display I connect to PORD.4 and SCK from display I connect to PORTD.0 on PIC processor

correct for a PIC18F45K22 PORTD.4 is SDO2 and connects to display sdi
and PORTD.0 is SCK2 and connects to display sck

richard
- 28th June 2015, 05:06
CURRENTLY tring to get an image drwn on to the display
I'm using the arduino utft ImageConverter 565.exe to generate a data file , but I'm at a loss to understand what it produces.
I have a 246x204 b&w pixel bmp file as input and expected a 246x204 word array as output (ie a word to describe the colour of each pixel) with pixels either black or white. that's not what I get


partial sample

// Generated by : ImageConverter 565 v2.1
// Generated from: duck.bmp
// Time generated: 28/06/2015 1:18:14 PM
// Dimensions : 246x204 pixels
// Size : 100,368 Bytes
#include <avr/pgmspace.h>
prog_uint16_t duck[0xC408] PROGMEM ={
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0010 (16)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0020 (32)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0030 (48)
0x0000, 0x0000, 0x0000, 0x0000, 0x0861, 0x4A49, 0x6B6D, 0xA534, 0xDEDB, 0xFFDF, 0xFFFF, 0xFFFF, 0xEF7D, 0xD69A, 0xA534, 0x630C, // 0x0040 (64)
0x4228, 0x0861, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0050 (80)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0060 (96)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0070 (112)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0080 (128)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0090 (144)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00A0 (160)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00B0 (176)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00C0 (192)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00D0 (208)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00E0 (224)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x00F0 (240)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0100 (256)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0110 (272)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0120 (288)
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4228, 0xBDD7, 0xFFFF

you can that some pixels have become coloured or more likely I am not interpreting the file correctly
source attached

any help here would be appreciated

richard
- 29th June 2015, 00:08
tft now with duck, drawimage now works
and a python script to convert utf565 generated c file to pbp friendly format

richard
- 29th June 2015, 00:12
forgot the python script

richard
- 1st July 2015, 10:59
The dev board I'm using for this project has a w25q32 flash memory chip on board , unfortunately on the same spi port as the display. this little display does a really fine job on graphics but transferring image data from flash to display is turning out to be much more complicated than expected. the other spi port is loaded up with a rtc and an eeprom (both i2c) . I'm not sure how they will react to the spi signals if I move the display to that port.
hoping to avoid smoke
here is the flash usercommand file so far

richard
- 3rd July 2015, 00:32
I have a bit of conditional compiling going on to select mssp1 or mssp2 but is there a way to conditionally check if the pic18 chosen to compile for has 1,2 or no mssp modules .



#IFNDEF TFT_SPI
#DEFINE TFT_SPI 1
;DEFAULT
#ENDIF



#IF TFT_SPI = 1
SSP1_IF VAR pir1.3
#ELSE
SSP1_IF VAR PIR3.7
#ENDIF



TFT_CMD:
spi_cbyte :
tft_port = tft_port & (~ tft_dc_bit )
TFT_DATA:
spi_byte :
'@ movff INTCON , _p_int
'@ bcf INTCON ,7
tft_port = tft_port& (~ tft_cs_bit )
SSP1_IF = 0
#IF TFT_SPI = 1
SSP1BUF = CMD
#else
SSP2BUF = CMD
#endif
WHILE SSP1_IF =0 ' wait for SPI interupt flag
wend
tft_port = tft_port | ( tft_dc_bit| tft_cs_bit )

'@ movff _p_int , INTCON
return

the problem is that if the pic has only one mssp then sspbuffer becomes sspbuf where as for two its ssp1buf or ssp2buf.
and it would nice to have shiftout as an option.

other than that it nearly a done deal

HenrikOlsson
- 3rd July 2015, 06:36
Hi Richard,
Apart from including a list of all PICs with two MSSP modules and checking against that list I don't know a way of telling at compile time. There's probably a way to have the assembler do it but then its too late.....

However, looking at the P18F45K22.INC file, as an example, one can see that SSPBUF and SSP1BUF are both declared and pointing at the same adress so I think you should be safe using SSPBUF and SSP2BUF. Obviously one can't know if Microchip will continue to alias SSPBUF to SSP1BUF on devices with multiple MSSP modules...

/Henrik.

richard
- 3rd July 2015, 06:49
hi henrik

in asm I can do this



asm
ifdef SSPIF
#define ssp_1 0
endif


ifdef SSP1IF
#define ssp_1 1
endif

endasm





but a #define thats made here seems unreadable to the pbp compiler
and I don't really want to do the whole routine in asm

richard
- 3rd July 2015, 07:00
tried using
SSPBUF = CMD
when ssp1buf exists and it syntax errors it really wants SSP1BUF = CMD

tried
sspbuf var ssp1buf

result
syntax error var is already an alias

HenrikOlsson
- 3rd July 2015, 08:02
Hi Richard,
Which device are you targeting?

/Henrik.

HenrikOlsson
- 3rd July 2015, 08:04
but a #define thats made here seems unreadable to the pbp compiler
and I don't really want to do the whole routine in asm
Exactly, that's what I meant by "but then it's too late". The assembler doesn't do its stuff until PBP is finished doing it stuff so whatever you do in and with the assembler is unkown to the compiler....

richard
- 3rd July 2015, 08:20
Which device are you targeting?

any pic18 was what I'm aiming at , hoping to get a default compile that would use mssp1 if it exists/shiftout if no mssp exits and mssp2 if user sets a define to do so.
dare I say idiot proof , but I don't think I can do it , at this point users will need some knowledge of the pic hardware chosen for their application and will need to modify the code accordingly.

HenrikOlsson
- 3rd July 2015, 09:02
Hi Richard,
I tried the following very simple program

CMD VAR BYTE
CMD = SSPBUF
CMD = SSP1BUF
CMD = SSP2BUF
I compiled it for a couple of 18F devices, all with 2 MSSP modules. Some of them (like the 18F24J11, 18F44J50 and 18F46K22) worked fine while others didn't and gave a Bad Expression error on the CMD=SSPBUF. My conclusion is that Microchip isn't consistent in aliasing SSPBUF to SSP1BUF thru all their device header files :-(

I don't know a way of doing it automatically - that's not to say it can't be done though!
I'd probably use SSPBUF in the code and add a comment saying that if the compiler complains then add SSPBUF VAR SSP1BUF to the code. That's certainly not idiot proof but you do know that's an impossible thing to achieve ;-)

/Henrik.

richard
- 3rd July 2015, 09:27
henrik
I think your right and what you suggest may be as good as it gets



add SSPBUF VAR SSP1BUF on Expression error

richard
- 3rd July 2015, 10:33
WILL call this version 1.0 , the python code now converts the pixels to suit (saves the pic18 from all that work)

the usercommand file has a more meaningful name but I forgot to update the demo's include to the new name
change glcd_chr include to INCLUDE "TFT_SPI.pbpmod" ;glcdc

Tabsoft
- 3rd July 2015, 19:13
Richard,

Great amount of work on this library.
I have to hand it to you, a lot of coding you worked out there.

For my own edification, I have a question for you.

In "TFT_SPI.PBPMOD" you have your setxy 8-element byte array for y0, y1, x0 & x1 declared.
This I understand.
You do this to support Word variables for x0 & x1 and space for y0 and y1 to be used as Word variables in the future,
but used as byte variables today. This I assume as the TFT display's y axis in less than 255.

One thing I notice though is that you have the following ASM address mapping for the individual x&y elements.


ASM
y0 = _setxy +1
y1 = _setxy +3
x0 = _setxy +4
x1 = _setxy +6
ENDASM


Then you have the following PBP variable declarations.


x0 var WORD EXT
x1 var WORD EXT
y0 var byte EXT
y1 var byte EXT


Understood at this point.
x vars are Words and y vars are Bytes.

But here is my question, I thought I noticed you use a lot of manual (CHK?RP/movlw/movwf) manipulation within the USERCOMMANDS for
the y0 & y1 variables instead of using PBP standard macros for MOVE?xx.

Could you not change the ASM address mapping for the y0 & y1 elements to use Little Endian style, instead of Big Endian, and then use the
standard PBP macros (MOVE?BB, MOVE?CB, MOVE?WB)?
Wouldn't that simplify the ASM in the USERCOMMAND macros?
Doesn't the PBP standard MOVE?xx macros take care of the BankSel testing/switching and movement of the High and Low bytes for you?



ASM
y0 = _setxy +0
y1 = _setxy +2
x0 = _setxy +4
x1 = _setxy +6
ENDASM


I may be off base, but was just curious.
I didn't read through the entire "TFT_SPI.PBPMOD", to see if there was another reason you have y0 & y1 defined in ASM as Big Endian.

richard
- 4th July 2015, 00:04
good catch tabsoft , I missed that when I changed the setxy method and never finished "cleaning up" . the two hardware includes have been fixed also (same error)
y0,y1 are now words and usercommand macros are more consistent
version 1.1 for these files (already)

richard
- 6th July 2015, 07:07
now have the image rotation corrected , made all the x,y vars word sized (heading towards a portrait/landscape command)
the font now has lowercase , chars 32-127. and few other subtle changes
the image file can be located anywhere , have tested with a 127k pic18f87j11 and loading file past the 64k boundary is no problem

ruijc
- 10th July 2015, 00:42
Greetings Guys,

First of all, congrats to Richard and all the other that participated in this addin.
Very good work !

I ordered one of these displays to test but i wanted to know if ( maybe a stupid question but... ) there is any "minimum requirement" when selecting a pic to work with this addin like min size memory, min osc speed, etc?

I only have a 18F2520 at the moment and i'm wondering if this one will work fine.

Thanks for the feedback

Regards
Rui

richard
- 10th July 2015, 01:22
"minimum requirement" when selecting a pic to work with this addin like min size memory, min osc speed, etc?

the code takes < 6k with no images stored , so the chip needs at least that much code space + what your code requires , ram requirements are modest (but uncounted)
at this point the chip must have at least 1 mssp (spi) module
regarding osc :--- faster = better performance


your 18F2520 should be fine

ruijc
- 10th July 2015, 12:54
Thank you for the feedback Richard,

One last question...

Is there any quick way to display an individual pixel @ a given x,y coordinate?

I'm asking that for displaying graphs, for example.

Also,
Your addin has many commands. Do you have a list of all the commands available?

Regards
Rui

richard
- 11th July 2015, 02:08
Is there any quick way to display an individual pixel @ a given x,y coordinate?

this will set a pixel to the fg colour at x0,y0


x0= y coordinate
y0= x coordinate
GOSUB drawpixel



Your addin has many commands. Do you have a list of all the commands available?

no. documenting code is my nemesis , but there are some comments in the code and I have tried to make most functions fairly consistent in their approach to the tasks at hand.

richard
- 11th July 2015, 04:59
try again got my x's and y's the wrong way round obviously




x0= x coordinate
y0= y coordinate
GOSUB drawpixel

ruijc
- 11th July 2015, 10:01
Thanks again Richard,

Awesome work you got here!

Cant wait to get the display and test it out :)

Regards
Rui

richard
- 12th July 2015, 06:27
changing the xy vars to words meant all the usercommand macros need to be changed too , I missed some .

the flash addin no works nicely if anyones interested

ruijc
- 14th July 2015, 08:34
Hi guys,

I dont have my TFT yet, but i tryed to compile the TFT-Demo.pbp file using the same pic Richard used ( 18F87J11 ) but i get lots of compile errors.
One of them is with the FONT7x8 include file.

Can everyone compile the file without any errors?
Do we have to do something in between or are these files plug-and-play?

Regards
Rui

richard
- 14th July 2015, 09:28
the demo has the following includes


INCLUDE "TFT_SPI.pbpmod" ;glcdc
include "tft-ILI9431.bas" ; or include "tft-ST7735.bas"

INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
INCLUDE "Elapsed_INT-18.bas"
INCLUDE "font7x8.bas"
INCLUDE "duck.bas"

make sure you have the latest version of them , if they are not located in the pbp3 dir or your current dir you need to specify the full path to each file
if testing with pbp3 3.0.7.4


the font file is messed up and has redundant copies included you only need 1
I will upload a new one later

richard
- 14th July 2015, 09:59
additions


TFT_wr_mode VAR byte ;for image drawing 0= normal , 1=flip y , 2= flip x , 3=flip x and y

ie set TFT_wr_mode to 1 to flip image on y axis when DRAWIMAGE used

font file fixed

demo simplified (elapsed_int commented out)

richard
- 14th July 2015, 10:25
forgot to add

doVdline doHdline


x= 196
y= 34
TFT_j= 312
gosub doHdline

will draw a dashed horizontal line from x=196 to 312 at y =34
and a update to the flash add in

x= 256
y= 11
TFT_k= 105
gosub doVdline

bit clunky to use I might add another couple of user commands

richard
- 15th July 2015, 09:42
rui discovered a find and replace error I have made int the tft-st7735 file .
here is the corrected version

richard
- 24th July 2015, 12:30
still fiddling with things , changed external flash routines to expect a 32 byte header in the image file ( x y size and image name), moved all external flash routines to flash pbpmod file.
have uploaded a python2.7 gui pgm to convert 565c image data and add the header , then transfer data to flash via eusart2 @38400 baud . the python code can also erase blocks/read blocks and convert files to bas format (with or without header). (note its set to use com27 edit file to suit your system) all the pic routines are in the flash pbpmod file. this demo has it all setup .

have also made a touch screen addin , that is also included in this demo

richard
- 24th July 2015, 12:34
there are some slight changes in these files too

richard
- 30th July 2015, 02:48
added a draw rectangle function and animated buttons for touch screen (with long and short press detection)

ruijc
- 30th July 2015, 20:07
Hello Richard,

you are the man !
I'm still waiting for the ST7735 display but now i will order the ILI9431 display too :)

Amazing job!

Congrats.

richard
- 31st July 2015, 00:52
now with individually sizeable buttons

visnja30
- 31st July 2015, 22:24
hi Richard,

today arrived TFT display to me from eBay.

I can not wait to start playing with it

Do you can tell me if this is the correct way to connecting peripherals with a PIC processor (pic18f87J11)



TOUCH PANEL connection to PIC

TOUCH PANEL PIC
T_CS PORT F.2
T_DIN PORT F.3
T_DO PORT F.4
T_CLK PORT F.1
T_IRQ PORT F.5


TFT display connection to PIC

TFT DISPLAY PIC
DC PORT C.2
CS PORT C.1
RST PORT C.0
MOSI PORT C.5
SCK PORT C.3




FLASH MEMORY W25Q32 connection to PIC
FLASH W25Q32 PIC

CS PORT H.0
SO PORT D.5
SI PORT D.4
SCK PORT D.6




My TFT module have a XPT2046 touch controller is this the some controller on your board?
Model of my tft module is : TJTCM24028-SPI 2.8 TFT SPI 240X320 v1.1

richard
- 1st August 2015, 00:12
is the correct way to connecting peripherals with a PIC processor (pic18f87J11)

its not the only way but its the way my demo platform is connected



Model of my tft module is : TJTCM24028-SPI 2.8 TFT SPI 240X320 v1.1


my tft touch module is : TJTCM24024-SPI 2.8 TFT SPI 240X320 , I got no docs with it and have not been able to identify the controller. but it has XPT2046 stamped on the chip so it looks the same as yours

ruijc
- 1st August 2015, 01:15
I was looking on ebay and i could not find any 2.8" TJTCM24024.
The only TJTCM24024 i could find is a 2.4"

see here:
http://www.ebay.com/itm/2-4-240x320-SPI-TFT-LCD-Serial-Port-Module-3-3V-PBC-Adapter-SD-ILI9341-/141381535697?pt=LH_DefaultDomain_0&hash=item20eaff07d1

Also the TJTCM24028:
http://www.ebay.com/itm/240x320-2-8-SPI-TFT-LCD-Touch-Panel-Serial-Port-Module-PCB-ILI9341-5V-3-3V-/281748908187?hash=item41998b289b


Maybe the 24028 means 2.8" and the 24024 means 2.4".

@Richard,
Can you double check you your display is really 2.4" or 2.8"?

Thanks

Regards
Rui

richard
- 1st August 2015, 01:30
its 2.4 TJTCM24024-SPI 2.4 TFT SPI 240X320
http://www.ebay.com.au/itm/181500077459?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

I should be more careful cutting and pasting

ruijc
- 1st August 2015, 01:37
Thanks Richard...

Pressing buy now... :biggrin:

Regards
Rui

richard
- 1st August 2015, 02:10
the 2.2 board before and after the flash chip added (w25q32bv)

richard
- 2nd August 2015, 10:53
did a bit more fiddling with the buttons
we now have rounded corners and self centering title text , and self scaling title text size too.

the flash bit now has a flasheader cmd to read image nams and x y sizes .

this demo has the flash bits commented out

ps the button x,y value now is the centre of the button (was bottom lh cnr) and each button can have its own size still

richard
- 5th August 2015, 11:43
fixed touch module cs pin not initialised to unselected state on boot up and had some vars being used without being cleared first (real amateur hour stuff)

richard
- 12th August 2015, 13:47
now with sliders, might try to get the touch module on the spi bus next (should then be able to read touch x,y ps about 16 times faster than bit banging with shiftin )

ruijc
- 12th August 2015, 18:37
Excellent work Richard ;)

Regards
Rui

Ioannis
- 13th August 2015, 07:50
This is so great work Richard. I believe you will put many here in the temptation to try at least the project.

I am very anxious too, but unfortunately our country is still under capital control and no orders can be placed on ebay etc...

Ioannis

richard
- 29th August 2015, 02:33
done a bit more

have added tft_sleep tft_wake tft_on tft_off subs, added DRAWRRECT usercmd (draw round cornered rectangle).
change way buttons are defined . can have rectangular buttons , a button colour scheme and the button "title" text is now stored in pgm memory
attached is a demo for a pic18f2520 using sleep/ wake on touch interrupt , backlight modulation using a pnp trany bc557 (full 10 bit)

can supply cct if req

visnja30
- 30th August 2015, 13:45
Hello people
if someone tried Richard's example with PIC18F2520 or PIC18f4520
I tried his example with PIC18F4520 and unfortunately not working. I have just a white screen.
If someone can send me a hex file or an example of code that works with the PIC18F4520 so that I know if my screen working properly or it is damaged.

my connection from TFT to PIC
tft_dc_bit con 8 ;ie bit 3 PORT B.3
tft_cs_bit con 32 ;ie bit 5 PORTB.5
tft_rst_bit con 16 ;ie bit 4 PORTB.4
tft mosi PORTC.5
tft sck PORTC.3



when I change value of this variable the led intensity is change on port C.2 , so PIC is working
cont=50 ;half brightness

visnja30
- 30th August 2015, 18:49
Is it possible that I destroy my TFT-display because my power supply for PIC18f4520 is 5volt?Communication between PIC and ILI9341 is on 5 volt.

richard
- 30th August 2015, 23:22
these displays are 3.3v devices . the only pin that is different is the vcc pin that leads to a 3.3v ldo regulator . my displays function ok with vcc =3.3v . one has a jumper to bypass the regulator if desired but this has not been necessary .
see schematic
ps the schematic shows the mclr pullup resistor connected to gnd , this is wrong it should be vcc

visnja30
- 31st August 2015, 21:05
OK,it works now.I replace a voltage regulator on EASYPIC 5 board from 5V to 3.3V and it works.
What I need to do to send JPG picture to TFT display?

richard
- 1st September 2015, 02:17
What I need to do to send JPG picture to TFT display?
start about post#41 I have provided some python code to convert arduino c code files generated by the "UTFT ImageConverter565.exe PGM " TO a pbp compatible format.
be aware that a 200x200 pixel image takes 80,000 bytes of flash memory. an external flash chip is more practical for this sort of thing , I have provided code to do that also

richard
- 1st September 2015, 11:41
some more ways to define and animate buttons

visnja30
- 3rd September 2015, 19:04
Because I'm not a good programmer there is a few things that are not clear to me.

Where I can download the Arduino utft ImageConverter 565.exe.I found only a online converter on Rinky-Dink Electronics web page.

What is the purpose of this file "flash.py.TXT" and where I must copied this file.

When I get a image file from ImageConverter565 how I can send this file to external Flash memory w25q32.

richard
- 3rd September 2015, 23:43
where can I get ImageConverter565

to find the image converter just google arduino utft library

I got mine from here
http://www.rinkydinkelectronics.com/library.php?id=51
download the utft.zip ,its in the utft/tools folder


What is the purpose of this file "flash.py.TXT" and where I must copied this file.

flash.py.TXT needs to be renamed to flash.py
its a python 2.7 script . you will need to install python 2.7 on to your pc

to be able to run it



#flash.py extract
import os
import time
from Tkinter import *
import serial
import glob
ser=serial.Serial("com27",38400)
ser.flush()
ser.timeout=.005


there are some python apps that mat need to be installed too see above (os,time,Tkinter,serial,glob) most come preinstalled
the code also wants a serial port (or it will crash and burn) mine uses com27 you can edit file to suit your setup , whatever port you supply needs to exist and be available for python to use


this code can either make a pbp.bas include image file or transfer the image directly to external Flash memory via the serial port when used with my flash add in

visnja30
- 4th September 2015, 22:39
I download python 2.7.10 version for windows and when I run it I get some errors.
When I open script FLASH.py and pres F5 button run module I got this message:




Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>

Traceback (most recent call last):
File "C:\Python27\flash.py.TXT", line 6, in <module>
import serial
ImportError: No module named serial
>>>

richard
- 5th September 2015, 00:22
ImportError: No module named serial


as I said you need to install some python extensions too


the serial module is pyserial
http://www.lfd.uci.edu/~gohlke/pythonlibs/

richard
- 5th September 2015, 00:43
back in post #54 I uploaded another python script 565-pbp.py that code is a bit simpler , it just converts the data . also if you intend to use an external flash chip with my flash code then your pic18 needs to have two mssp ports . I found buffering image data between flash and tft with them on the same port was just too tedious and slow and gave up on the process , its doable but complicated .

visnja30
- 5th September 2015, 20:06
I managed to run a python script FLASH.py and ImageConvertor565
.
in the FLASH .py scripts can I put COM.1 as default port to communicate with PIC chip?


On which the port and pin I connects serial communication between PC and PIC

PIC RX-pin is ?
PIC TX-pin is ?

What is the maximum number of buttons possible to make the TFT screen.

I tried to make a four keys and the fourth button is not working. The first three are working.

here's the code for PIC18F4520 that I use:



'************************************************* ***************
'* Name : pic18f2520_tft_demo.pbp *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 8/28/2015 *
'* Version : 1.0 *
'* Notes : sleep, pwm brightness (10 bit pwm) *
'* : *
'************************************************* ***************
#CONFIG
CONFIG OSC = INTIO67
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRT = OFF
CONFIG BOREN = SBORDIS
CONFIG BORV = 3
CONFIG WDT = OFF
CONFIG WDTPS = 512
CONFIG CCP2MX = PORTC
CONFIG PBADEN = OFF
CONFIG LPT1OSC = OFF
CONFIG MCLRE = ON
CONFIG STVREN = ON
CONFIG LVP = OFF
CONFIG XINST = OFF
CONFIG DEBUG = OFF
CONFIG CP0 = OFF
CONFIG CP1 = OFF
CONFIG CP2 = OFF
CONFIG CP3 = OFF
CONFIG CPB = OFF
CONFIG CPD = OFF
CONFIG WRT0 = OFF
CONFIG WRT1 = OFF
CONFIG WRT2 = OFF
CONFIG WRT3 = OFF
CONFIG WRTC = OFF
CONFIG WRTB = OFF
CONFIG WRTD = OFF
CONFIG EBTR0 = OFF
CONFIG EBTR1 = OFF
CONFIG EBTR2 = OFF
CONFIG EBTR3 = OFF
CONFIG EBTRB = OFF
#ENDCONFIG
DEFINE NO_CLRWDT 1
#DEFINE TOUCH_SCREEN 1
'#DEFine dbug 1
;-----------connection----------
; pic tft
; <tft_port.tft_dc_bit >-------< dc >
; <tft_port.tft_cs_bit >-------< cs >
; <tft_port.tft_rst_bit>-------< rst >
; <msspx.sdo >-----------------< mosi >
; <msspx.sck >-----------------< sck >
; <back_light>-----------------< led > via pnp cct



tft_dc_bit con 8 ;ie bit 3
tft_cs_bit con 32 ;ie bit 5
tft_rst_bit con 16 ;ie bit 4
tft_port var latb
back_light var latc.2 ;portc.2
cont var word ; backlight level
WIDTH con 320 ; 160 X MUST MATCH TFT MODULE
HEIGHT con 240 ; 128 Y

' my TOUCH_SCREEN connection definitions
T_CLK VAR PORTa.7
T_INPin VAR PORTa.4
T_OUTPin VAR PORTa.6
T_INT VAR PORTb.0
T_CS VAR LATb.2

number_of_buttons con 4
number_of_sliders con 1


INCLUDE "TFT_SPI.pbpmod" ;glcdc
include "tft-ILI9431.bas"
'INCLUDE "flash_spi.pbpmod"

include "TOUCH_TFT.PBPMOD" ;uncomment to use TOUCH_TFT
INCLUDE "font7x8.bas"
latb=255 ; make sure tft etc are not selected ie all cs high
TRISA=111111
TRISB=000011
TRISC=010011
TRISD=000000
PORTD=0000000

OSCCON = 110000 'Internal 8 Mhz Osc
OSCTUNE=000000 'PLL ON
cont=500 ;half brightness
DEFINE OSC 32
buff var byte[32]
t2con=5
PR2 = 255;
CCPR1L = cont>>2; ;set pwm
ccp1con=12|((cont&3)<<4);
SSPCON1=$20 ;$20-21-22 works 20 IS FASTEST
SSPSTAT=$40
TEXTSIZE=4
gosub tft_init
gosub TOUCH_INIT

#ifdef dbug
trisb.7=0 ;DEBUG OUT
latb.7=1
pause 4000
Serout2 PORTb.7,84,["ready ", 13,10]
#ENDIF


glcdc font7x8 ;SET FONT
bg=$ffff
fg=0
fillrect 0,0,WIDTH,height ;cls

MAKEBUTTON 30,180,0,50, "CLEAR"
MAKEBUTTON 90,180,1,50, "SLP"
MAKEBUTTON 150,180,2,50, "LED"
MAKEBUTTON 210,180,3,50, "VISNJA"
MAKESLIDER 100,80,0
slider_index =0
the_slider = slider_index *SL_SZ ; set slider indexing properly
slider_FG[the_slider ]=$ffe0 ;set slider bar colour if default not desired
slider_count[the_slider]=cont/10
bg=0
INTCON2.6=0
main:
fg=$7FF
DRAWBUTTON 0
DRAWBUTTON 1
DRAWBUTTON 2
DRAWBUTTON 3
slider_index =0
the_slider = slider_index *SL_SZ
slider_MODE[the_slider]=0 ;FORCE DRAW OF SLIDER
DRAWSLIDER 0
LOP:
GOSUB CK_BUTTON
IF BUTTON_STATE[0]=1 THEN
BUTTON_STATE[0]=0
fg=0
fillrect 0,0,WIDTH,height ;cls
goto main

ELSEIF BUTTON_STATE[2]=1 THEN
TOGGLE PORTD.0
BUTTON_STATE[2]=0

ELSEIF BUTTON_STATE[3]=1 THEN
TOGGLE PORTD.1
BUTTON_STATE[3]=0


elseIF BUTTON_STATE[1] THEN
if BUTTON_STATE[1]==2 then ; shut it all down
gosub tft_sleep
ccp1con=0
back_light=1
pause 100
intcon=$10
@ sleep
@ nop
intcon=0
gosub tft_wake
CCPR1L = cont>>2;
ccp1con=12|((cont&3)<<4);
endif
BUTTON_STATE[1]=0
endif



slider_index =0
the_slider = slider_index *SL_SZ
IF slider_MODE[the_slider]&1 THEN ; adjust brightness
cont = 1000 - slider_COUNT[0]*10
CCPR1L = cont>>2;
ccp1con=12|((cont&3)<<4);
slider_MODE[the_slider]=slider_MODE[the_slider]&$FE
TEXTSIZE=2
fg=$7FF
ARRAYWRITE buff,[dec3 slider_COUNT[the_slider],0]
GLCDSTR 50,10 ,buff
ENDIF


goto LOP












VISNJA button not working.When I touch them nothing is happend.

visnja30
- 5th September 2015, 20:32
I have several questions about the code pic18f2520_tft_demo.pbp.

how I can change color of screen wallpaper from black to yellow

how I can changes color of buttons from red to green and how to change color of outline on buttons

richard
- 5th September 2015, 23:31
On which the port and pin I connects serial communication between PC and PIC

I have used rx2/tx2 (the code could be altered to use tx1/rx1)


What is the maximum number of buttons possible to make the TFT screen.
this is the limiting factor
button_flg VAR BYTE ;1 BIT PER BUTTON make it a word to have up to 16 buttons





I tried to make a four keys and the fourth button is not working. The first three are working.
button state is not defined when buttons are created easiest solution is to insert a clear command





INCLUDE "TFT_SPI.pbpmod" ;glcdc
include "tft-ILI9431.bas"
'INCLUDE "flash_spi.pbpmod"

include "TOUCH_TFT.PBPMOD" ;uncomment to use TOUCH_TFT
INCLUDE "font7x8.bas"
latb=255 ; make sure tft etc are not selected ie all cs high
TRISA=111111
TRISB=000011
TRISC=010011
TRISD=000000
PORTD=0000000

OSCCON = 110000 'Internal 8 Mhz Osc
OSCTUNE=000000 'PLL ON

clear

cont=500 ;half brightness
DEFINE OSC 32
buff var byte[32]
t2con=5
PR2 = 255;
CCPR1L = cont>>2; ;set pwm
ccp1con=12|((cont&3)<<4);
SSPCON1=$20 ;$20-21-22 works 20 IS FASTEST




how I can change color of screen wallpaper from black to yellow
the screen colour has two properties fg (foreground) bg (background)
set them as you like

use fg=bg and fillrect to clear an area


how I can changes color of buttons from red to green and how to change color of outline on buttons

button_scheme var word[4] ; [background,text,border,animated (background or border) ]

defaults
button_scheme[0]= $1f
button_scheme[1]= $0
button_scheme[2]= $7ff
button_scheme[3]= $ffff

buttons can have different animations too
button_action.0[1]=1 ;flash text for this button1
button_action.0[2]=0 ;flash outline for this button2 ; default action

visnja30
- 6th September 2015, 20:07
Why I can not write lovercase letters only capital letters work?When I write lovercase letter I got only a bad piksel on screen.
Buttons now work excellent.

richard
- 6th September 2015, 22:01
are you using the font that has lowercase chars in it ?

the first font has chr 32 to 90 post#54
the second has chr 32 to 127 post#67

visnja30
- 7th September 2015, 20:03
Yes,wrong include I use,now it is work.

I create a counter,and when I touch the button counter increase e his value for 1.Each press increase counter for 1.

COUNTER=COUNTER+1
Is it possible to make that when i press a button and hold pressed the counter increase his value throughout the whole period when it pressed

richard
- 7th September 2015, 21:42
Is it possible to make that when i press a button and hold pressed the counter increase his value throughout the whole period when it pressed

yes good idea , I have added an auto repeat property to buttons


button_rpt.0[3]=1 ;button3 auto rpt

Aussie Barry
- 9th September 2015, 08:43
Hi Richard,

I am having some issues compiling your TFT_Demo program and hope you can steer me in the right direction.
I am using Microcode Studio 5.0.0 5 and PBPX 3.0.7.4

When I first compile I get a "Syntax Error (195)". The line of code is "fillcircle 60 , 60 , 20"
I have looked through the include files and cannot find a USERCOMMAND for "fillcircle". What am I missing?

Attempting to move on, I commented out the offending fillcircle line of code and tried to compile again.
Now I get four ASM ERROR message "Address label duplication or different in second pass".
(Z001D9) (Z001DA) (Z001DB) (Z001DC)

I am very keen to get my new TFT Touchscreen operational so any advice on how to correct the above issues would be greatly appreciated.

I have attached all relevant files (main program, includes etc.) for your reference.

Cheers
Barry
VK2XBP

richard
- 9th September 2015, 10:28
hi barry


the address dup messages come from having coff file generation turned on when using dt_ints , don't know why ,wish it wouldn't
see the attached screen shot to remedy that

the syntax error i think comes from not using the latest tft-spi.pbpmod file

I have uploaded the latest just incase I stuffed up

richard
- 9th September 2015, 10:42
I did stuff up , seems I forgot to upload the latest version with fillcircle command in it .
apologies to all,

Aussie Barry
- 9th September 2015, 11:40
Thanks Richard - that did the trick!
Everything compiles and programs.
Now to breadboard it and make it work :)

Cheers
Barry
VK2XBP

Aussie Barry
- 9th September 2015, 13:49
Hi Richard,

I have had a small amount of success getting this thing going but still having a few problems.
Firstly, your .pdf circuit diagram appears to have another mistake (apart from the MCLR issue)
You show the LED connection on J2 as being Pin 9 however I believe it should be Pin 8 - or at least that's what is printed on the PCB silkscreen.
I made the necessary adjustments but still nothing. I am getting a nice 50% duty cycle PWM signal (~7.8kHz) on CCP1.
In frustration I connected the LED connection (J2 Pin 8) to the wiper of a 10k pot and adjusted it between 0V and 3.3V.
Once I got to around 3V the screen came to life - or at least half of it did :(
I think I might have a dodgy TFT screen.
I can see the elapsed timer counting and some of the reset button but most of the right side of the screen is scrambled with a big black ovoid shape in the middle.

Looks like I need to do another eBay purchase but don't really want to have to wait 3-4 weeks for it to arrive!

Thanks for all your help thus far. I will be in touch again once I have a new screen to play with.

Cheers
Barry
VK2XBP

richard
- 9th September 2015, 22:23
your right about the schematic I have uploaded a correct version , I have replaced the transistor with a pch mosfet (saves two resistors) but it still loses a little brightness and is no better than the transistor version


most of the right side of the screen is scrambled with a big black ovoid shape in the middle.
I had similar issues with mine , turns out the sil connector was very poorly soldered a bit of rework fixed it

Gusse
- 11th September 2015, 14:35
your right about the schematic I have uploaded a correct version , I have replaced the transistor with a pch mosfet (saves two resistors) but it still loses a little brightness and is no better than the transistor version
Thanks for the schematic update. Now I have to start gathering all needed components.
Why you have selected BS250, which has quite huge Rds(on), it is round 10 Ohm or more @3.3V. Why not go with a good PFET like IRLML9301TRPbF, which has ~100-200mOhm Rds(on) @3.3V. Also price is half of the BS250. With this FET you will not burn energy in transistor -> LED will be brighter.

visnja30
- 11th September 2015, 20:42
I tried to test the repetitively button, it works but not as expected.

When I touch the button the counter starts counting, and its value increases every 300ms for one and then suddenly accelerate and in few mS in increase his value very quikly and then slow down.

If it happens to someone else or just me?

richard
- 11th September 2015, 21:12
Why you have selected BS250

because it comes in a t092 package I can use in a breadboard for testing , yes a IRLML9301TRPbF would probably be better but they only come in a sot23 package.


visnja30 repetitively button, it works but not as expected

I would need to see your code to be sure ,button auto repeat works for me just fine . auto repeat won't begin until long_press_threshold has been reached and will repeat @ repeat_press_rate

these constants in the TOUCH_TFT.PBPMOD file control button timing . they may need adjusting depending on OSC and "gosub CK_BUTTON " loop rate

repeat_press_rate con 100 ;button auto repeat rate (must be less than long_press_threshold)
long_press_threshold con 300 ; min time for a BUTTON long press result
short_press_threshold con 20 ; min time for a BUTTON pressed result

richard
- 12th September 2015, 10:59
I put a bug in the CK_BUTTON: subroutine in the TOUCH_TFT.PBPMOD file , it stops a long_press being detected


should be this

IF button_count[the_button] >= long_press_threshold THEN
instead of

IF button_count[the_button] > long_press_threshold THEN

I will post a amended version when I finish getting the >64k code location problem solved for strings

richard
- 13th September 2015, 23:55
some updates

CK_BUTTON: subroutine in the TOUCH_TFT.PBPMOD file fixed
const txt strings can now be anywhere in addressable pgm memory
button txt strings can now be anywhere in addressable pgm memory


pin definitions for tft dc/cs/rst have been simplified
eg. for tft cs on bit 5 instead of tft_cs_bit con 32 is now


tft_cs_bit con 5

richard
- 20th September 2015, 07:32
some changes to the touch add in
now ready for 16 buttons ,makebutton is optimised a bit better, bank 0 dependency relaxed

richard
- 22nd September 2015, 00:49
finally worked out why fillcircle was so slooooow
a much faster solution

visnja30
- 23rd September 2015, 18:48
I include file flash_spi.pbpmod there is two labels with the same name FL_IMG: is it OK or one labels is too much?

richard
- 23rd September 2015, 22:18
its ok the same label is use twice but it is conditional,only one is selected depending on the display type when the code is compiled
#ifdef st7735
FL_IMG:

or
#ifdef ILI9431
FL_IMG:

richard
- 25th September 2015, 02:56
some further refinements , drawarc (45deg arc ) fillarc (45 deg pie slice ) and a proper fillrrect (fill round cornered rectangle) and drarrrect , also fixed errors for button macros that had no text option selected

richard
- 29th September 2015, 05:49
having an issue here with a usercmd macro overwriting an array boundary and I'm at a loss to understand what I'm doing wrong ,
attached is a safer version of the touch screen addin.

problem is , lets say I have defined number_of_buttons con 9
vars are defined by button_Taddr VAR byte[number_of_buttons*3]

by my count that's 27 bytes

I usercmd a button the nineth button

MAKEBUTTON 34,216,8,40
in the macro k=Button*3 which should be 24
so

movlw 0
movwf _button_Taddr +k
movwf _button_Taddr +k+1
movwf _button_Taddr +k+2
should place 0 into button_Taddr[24-26]
but something else gets clobbered instead , buttons 0-7 seem ok but I might be wrong





MAKEBUTTON?CCCC macro X0in ,Y0in ,Button ,Szin ;sqr button no text
k=Button*3 ;
j=Button*2 ;1 WORD PER BUTTON
i=Button*6 ;3 WORDS PER BUTTON

if Button <8
bcf _button_action ,Button
bcf _button_rpt ,Button
bcf _button_set ,Button
else
bcf _button_action+1 ,Button-8
bcf _button_rpt+1 ,Button-8
bcf _button_set+1 ,Button-8
endif
MOVE?CW Szin ,_button_xsize+ j
MOVE?CW Szin ,_button_ysize+ j
MOVE?CB 0 , _BUTTON_STATE + Button
; movlw 0
; movwf _button_Taddr +k
; movwf _button_Taddr +k+1
; movwf _button_Taddr +k+2
MOVE?CW 0 ,button_count +i
MOVE?CW X0in ,button_X +i
MOVE?CW Y0in ,button_Y +i
MOVE?CW 0, _button_Tsize + j
endm

richard
- 29th September 2015, 07:39
CHK?RP , Banksel it gets me every time

richard
- 29th September 2015, 07:59
FIXED again

Scampy
- 29th October 2015, 14:47
Richard, Seems you've done some fantastic work on using TFT's with PBP.

I have a 2.8" display of the same resolution, but I'm running PBP 2.60c which lacks the usercommand function. Is there any chance you could advise / produce a library that works with version 2.60 ?

HenrikOlsson
- 29th October 2015, 18:34
I won't speak for Richard but I'd take this as the opportunity you've been looking for to finally justify the upgrade PBP3 - you've now found a feature it has that you want/need ;-)

/Henrik.

richard
- 29th October 2015, 20:20
I won't say its impossible but


lets take one simple usercmd


GLCDSTR 2,2,buff

macro called is


GLCDSTR?CCB macro Xin ,Yin ,Bin
MOVE?CW Xin , _X
MOVE?CW Yin ,_Y
MOVE?CB high Bin, FSR1H ;load highbyte
MOVE?CB low Bin, FSR1L ;load low byte
L?CALL tft_str_out
endm


translation to pbp2.6




X=2
Y=2
@ MOVE?CB high _buff, FSR1H ;load highbyte
@ MOVE?CB low _buff, FSR1L ;load low byte
call tft_str_out


not too difficult but its messy and could get very ugly very quickly , as henrik says an upgrade looks good

Scampy
- 30th October 2015, 00:23
Would love to upgrade, but being a casual user, and between jobs, upgrading is simply not an option for me at the monemt

CuriousOne
- 30th November 2015, 08:52
Just found this thread! I like idea very much, and I'd like to contribute, but my programming skills aren't that good. However, I'm way better on graphics, so I can create better looking fonts with chars of different dimensions. Just point me to font file so I can have look how it is organized.

richard
- 30th November 2015, 09:42
the fonts are really 8x8 fronts but the alpha/numeric char only use 7x8 with the last bit always o (for chr spacing)
there are two fonts in this thread the first is chr 32-90 and the second chr 32-127. I have a extended font (attached) that has
a radio button arrows ,play,stop,pause,speaker on/off symbols ,these use the full 8x8

this is the routine to display font chars

g
cga:
g_fontoffset = (g_chr-font_begin)*8 + fontaddr

if (x+textsize*7) > width then return
if (y+textsize*8) > height then return
if (g_chr <font_begin) || (g_chr >font_end ) then return
for ROW=0 to 7 ;font height this would need to be a var set to font height size
readcode g_fontoffset +ROW,ctemp ;this would need to be able to "unpack" different font with bits
for PIXEL=0 to 7 ;font width ; font width var req here too
X1= X+PIXEL
X0=X1
Y0=Y+7-ROW
Y1=Y0
IF TEXTSIZE ==1 THEN
GOSUB SETWINDOW
if ctemp.0[PIXEL] then
;SETPIXEL X+PIXEL,Y+7-ROW ,FG
TFT_CMD_IN= FG>>8
GOSUB TFT_DATA
TFT_CMD_IN= FG
GOSUB TFT_DATA
ELSE
;SETPIXEL X+PIXEL,Y+7-ROW ,BG
TFT_CMD_IN= BG>>8
GOSUB TFT_DATA
TFT_CMD_IN= BG
GOSUB TFT_DATA
ENDIF
ELSE
X0=X+PIXEL*TEXTSIZE
Y0=Y+( 7-ROW )*TEXTSIZE
X1= TEXTSIZE
Y1= TEXTSIZE
if ctemp.0[PIXEL] then
FrG=fg
GOSUB frectc
ELSE
FrG=BG
GOSUB frectc
ENDIF
ENDIF
NEXT
next
x=x+textsize*7 ;auto increment x for str function ; and font width here too
RETURN

the arduino utft code can handle variable width fonts by storing a second table along with the font . that table records the h/w of every chr in the font and ascii val of the first and last chr in the font too.
its pretty straight forward but not trivial task to change the pgm to do that ; however all the text box code for buttons etc would need to be altered too

visnja30
- 5th January 2016, 18:40
I create a six buttons on LCD and one button must work like a push button.

When I push the button, the LED which is connected to PORTD.0 must light all the time as the button is pressed.
When I release the button LED must go off.

Is it possible to create something like that?

richard
- 5th January 2016, 20:37
when a repeat enabled button is "held" it returns a BUTTON_STATE of 5
this can be the led "on" cue

when the button is "released" it returns a BUTTON_STATE of < 5 (1 or 2 )
this can be the led "off" cue



LOP:
GOSUB CK_BUTTON
IF BUTTON_STATE[0] THEN
IF BUTTON_STATE[0] >4 then
PORTD.0=1
else
PORTD.0=0
BUTTON_STATE[0]=0
endif
endif
goto lop

visnja30
- 6th January 2016, 21:32
when I press a button and hold it the led diode is on.That is OK.when I release a button led is off.
Is it possible to make that when the button is pressed and hold, led is on, and when I connect 5V to pin PORTD.7 then led is off.
I dont now how to explain a problem.
When I press a button window is opening and when it is full open then he must stop .Stop signal is connect to PORTD.7



'-----------------------OPEN WINDOW ------------------------------------------------------
IF BUTTON_STATE[2] THEN
IF BUTTON_STATE[2] >4 then
PORTD.0=1
else
PORTD.0=0
BUTTON_STATE[2]=0
endif
endif

richard
- 6th January 2016, 23:13
you could do this but ..............
a big if

is the portd.7 signal is a limit switch or an emergency stop switch ?... if it is then its best done in hardware a hung loop here could cause fire/smoke/damage or hurt


'-----------------------OPEN WINDOW ------------------------------------------------------
IF BUTTON_STATE[2] THEN
IF BUTTON_STATE[2] >4 then
if PORTD.7 ==0 then
PORTD.0=1
else
PORTD.0=0
endif
else
PORTD.0=0
BUTTON_STATE[2]=0
endif
endif

visnja30
- 7th January 2016, 06:37
the portd.7 signal is a limit switch for max position of open window.He must disable opening,but if something goes wrong I will put a second hardware switch to disable motor.
On test board this routine works good.

visnja30
- 7th January 2016, 15:47
I am stuck with serin2 and serout2 comands.

I use PIC18F252 for reading sensor.
BMP085 for temperature and pressure
DS3231 for time and date
BH1750 for light intensity
DHT11 for humidity

All this values I have on 2x16 LCD and it work perfect.

pressure and temperature showing on lcd like this


'DISPLAY true temperature in C
lCTemp = (B5 + 8) / 16 'Hey presto, lCTemp appears...
INTEMP = lCTemp / 10 'find value above decimal point
INTEMPOSTATAK = lCTemp // 10 'Find decimal value
LCDOut $fe,$c0+12, DEC2 INTEMP, ".", DEC2 INTEMPOSTATAK





'DISPLAY true pressure in hPa
lPres = lPres + (X1 + X2 + 3791) / 16 'lPres is the true pressure in Pa
X1 = lPres / 100+16
PRITISAK = X1 'find value above decimal point
PRITISAKOSTATAK = lPres // 100 'find value below decimal point
LCDOut $fe,$80+9 , DEC PRITISAK, "." ,DEC2 PRITISAKOSTATAK








Now I want to send all this values to TFT lcd with SEROUT2/SERIN2 commands

Transminter:

B2400 Con 16780
lPres var long
lCTemp var long

Sec VAR word
Mins VAR word
hr VAR word
date VAR WORD
mon VAR WORD
yr VAR WORD

PRITISAK VAR WORD
INTEMP VAR WORD
DHT_Humidity var word
lux var word



Serout2 PortC.7,B2400,["#OK",HR,MINS,SEC,DATE,MON,YR,INTEMP, PRITISAK,DHT_HUMIDITY,LUX]




On receiver side i have this:

create two buttons and write receive info on screen


B240 Con 16780
cnt var WORD
HR var WORD
MINS var WORD
SEC var WORD
DATE var WORD
MON var WORD
YR var WORD
LCTEMP var WORD
LPRES var WORD
DHT_HUMIDITY var WORD
LUX var WORD
buff var byte[32]





LOP2:

GOSUB CK_BUTTON
'*******SET BUTTON FOR ADJUST TIME AND DATE******************************
IF BUTTON_STATE[0]=1 THEN
PAUSE 1000
BUTTON_STATE[0]=0
ENDIF

'************NEXT BUTTON GO TO NEXT SCREEN *****************************
if BUTTON_STATE[1]=1 then
GOTO SCREEN_1
BUTTON_STATE[1]=0
endif

Serin2 PORTC.0,B2400,10,LOP2,[wait ("#OK"),HR,MINS,SEC,DATE,MON,YR,LCTEMP, LPRES,DHT_HUMIDITY,LUX]

TEXTSIZE=2
bg=0
fg=$7FF
' LR UD
GLCDC 10,200
GLCDC "Time : "
ARRAYWRITE buff,[dec2 HR,0]
GLCDSTR 70,200,buff

ARRAYWRITE buff,[dec2 MINS,0]
GLCDSTR 100,200 ,buff

ARRAYWRITE buff,[dec2 SEC,0]
GLCDSTR 130,200 ,buff

GLCDC 10,170
GLCDC "Date : "

ARRAYWRITE buff,[dec2 DATE,0]
GLCDSTR 70,170 ,buff

ARRAYWRITE buff,[dec2 MON,0]
GLCDSTR 100,170 ,buff

ARRAYWRITE buff,[dec2 YR,0]
GLCDSTR 130,170 ,buff

ARRAYWRITE buff,[DEC4 LCTEMP,0]
GLCDSTR 10,100 ,BUFF

ARRAYWRITE buff,[ DEC4 LPRES,0]
GLCDSTR 100,100 ,BUFF

ARRAYWRITE buff,[dec3 DHT_HUMIDITY,0]
GLCDSTR 200,100,buff

ARRAYWRITE buff,[dec4 LUX,0]
GLCDSTR 270,100 ,buff


GOTO LOP2


Hr,mins,sec,date,mon,yr and temp are OK

Pressure are not OK, I have on screen 0235

Lux and humidity still not connected on transmiter side I have 0 readings

visnja30
- 7th January 2016, 16:19
I just tested a humidity sensor and his value are correct on lcd and TFT but value of lux are ok if are they below 255.
How to send variable word size over serout2 commands,I think this is my problem.

visnja30
- 7th January 2016, 19:04
Solved,

receive:
Serin2 PORTC.0,B2400,10,LOP2,[wait ("#OK"),HR,MINS,SEC,DATE,MON,YR , LCTEMP.highbyte,lctemp.lowbyte , LPRES.highbyte,lpres.lowbyte ,_
vlaga ,vlagaostatak,lux.highbyte,lux.lowbyte ]


transmit

Serout2 PortC.7,B2400,["#OK",HR,MINS,SEC,DATE,MON,YR,lCTemp.highbyte,lCTemp.lo wbyte, pritisak.HighByte, pritisak.LowByte,vlaga,_
vlagaostatak,LUX.HighByte,lux.LowByte]

wjsmarine
- 7th February 2022, 09:57
Hi All,

I'm toying with two different GLCD's, one a 1.8" 160x128 (actually 2 of these but slightly different in overall size and connector with ST7735) and a 2.4" 320x240 with ILI9341, all TFT and 3v3 supply. Using an 18f2520 for testing.

The larger display works fine however something is awry with the smaller units when I reconfigure Richard's code for the different size and driver. Both exhibit a smaller section of the expected display and some corruption instead of crystal clear and a full screen of scaled icons. The attached photo's show the problem.

I'm using the last versions of Richard's updates seen on this thread. I went back to the beginning but I don't have a 45k20 on hand to test if the bare bones version works.

Any suggestions?

Thanks,
Bill

Ioannis
- 7th February 2022, 11:13
I am sorry that cannot help but I am amazed that your did drive the TFT displays through PIC and PicBasic! Congrats on that. Is it possible to show the code please?

I am using Nextion to do similar things but it would be nice if an alternative could be used.

Ioannis

richard
- 7th February 2022, 21:48
without seeing your code it looks very much like you are writing outside the screen boundaries

wjsmarine
- 8th February 2022, 01:05
Hi Richard,

Thanks for being there :). Yes I think so too but don't know how to enforce the borders. I'm really interested in using Portrait mode too to make text legible in a skinny rail mounted enclosure.

@Ioannis
It's Richard's hard work not mine, he deserves the congrats. Below is the code configured for the ST7735 and the Includes/files are the latest I could find in the thread.

Any help or suggestions appreciated.

Kind regards,
Bill



'************************************************* ***************************
'* Name : pic18f2520_tft_demo.pbp #### semi-Working Code #### * but not pretty, needs lots of work.
'* Author : RICHAED *
'* Notice : Copyright (c) 2015 *
'* : All Rights Reserved *
'* Date : 12/09/2015 *
'* Device : 18F2520 (32k) *
'* Version : ? 25295 bytes (PBP 3.1.4.4) *
'* Notes : sleep, pwm brightness (10 bit pwm) *
'* : new way to define tft pins *
'* : 24 BIT ADDRESS FOR STRINGS AND BUTTON TEXT *
'* : *
'* : See: www.picbasic.co.uk/forum/showthread.php?t=20115 *
'* : *
'* ======> : 3v3 screen! Draws ~ 80mA. *
'* : *
'* : TFT ILI9431 works okay but not pretty, needs lots of work. *
'* : *
'* : ST7735 (KMR-1.8" and Touch version each 128x160) work but the *
'* : code needs fix - only 1/4 of TFT size screen shown instead of *
'* : a reduced scale version to fit into 128x160 frame. *
'* : *
'* : #### How to put into Portrait mode? #### *
'* : *
'************************************************* ***************************
;
; 07Feb22 Huge trawling exercise to sort the many variations of this evolution on the Forum.
; Includes are the last/latest versions found in the thread (could this be the problem?).
;
; Testing with 2.4" 240x320 TFT is functional using ILI9431 and also ST7735 (1.8" 128x160).
; Had some frustrating moments programming this, MeLabs usb changed for PicKit3 confirmed it
; was the problem, using Test 18f2520.pbp code also proved it.

#CONFIG
CONFIG OSC = INTIO67
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRT = OFF
CONFIG BOREN = SBORDIS
CONFIG BORV = 3
CONFIG WDT = OFF
CONFIG WDTPS = 512
CONFIG CCP2MX = PORTC
CONFIG PBADEN = OFF
CONFIG LPT1OSC = OFF
CONFIG MCLRE = ON
CONFIG STVREN = ON
CONFIG LVP = OFF
CONFIG XINST = OFF
CONFIG DEBUG = OFF
CONFIG CP0 = OFF
CONFIG CP1 = OFF
CONFIG CP2 = OFF
CONFIG CP3 = OFF
CONFIG CPB = OFF
CONFIG CPD = OFF
CONFIG WRT0 = OFF
CONFIG WRT1 = OFF
CONFIG WRT2 = OFF
CONFIG WRT3 = OFF
CONFIG WRTC = OFF
CONFIG WRTB = OFF
CONFIG WRTD = OFF
CONFIG EBTR0 = OFF
CONFIG EBTR1 = OFF
CONFIG EBTR2 = OFF
CONFIG EBTR3 = OFF
CONFIG EBTRB = OFF
#ENDCONFIG

; TFT in landscape has conn LHS, KMR RHS, 1.8 Touch RHS
; TFT in portrait has conn ?, KMR ?, 1.8 Touch ?
;
; Led- Gnd 2x8 pin hdr
' PIC(18F2520) OTHER KMR-1.8" 1.8" Touch
' | | |
' MCLR PortE.3 (pin 1) Pull High 10k.
' C1- PortA.0 (pin 2)
' PortA.1 (pin 3)
' C1+ PortA.2 (pin 4)
' PortA.3 (pin 5)
' C1OP PortA.4 (pin 6) T_DIN Pin TFT. nc
' PortA.5 (pin 7)
' Ground (pin 8)
' PortA.7 (pin 9) T_CLK Pin TFT.
' PortA.6 (pin 10) T_DO Pin TFT. not tested XPT2046 chip
' PortC.0 (pin 11)
' CCP2 PortC.1 (pin 12) 9600 True via 1k.
' CCP1 PortC.2 (pin 13) BL drive-1k-PNP. Led+ BLK(7) Led A already to +, rejig PNP to switch ground.
' SCL PortC.3 (pin 14) SCK Pin TFT. SCL CLK(3)
' SDA PortC.4 (pin 15)
' SDO PortC.5 (pin 16) SDI(MOSI)Pin TFT. SDA MOS(4)
' Tx PortC.6 (pin 17)
' Rx PortC.7 (pin 18)
' Ground (pin 19) Gnd Gnd Gnd(1)
' +Supply (pin 20) +3v3 +3v3 +3v3(2)
' INT0 PortB.0 (pin 21) T_IRQ Pin TFT.
' PortB.1 (pin 22)
' PortB.2 (pin 23) T_CS Pin TFT.
' PortB.3 (pin 24) DC Pin TFT. A0 DC(6)
' PortB.4 (pin 25) RESET Pin TFT. RESET RES(5)
' T1G PortB.5 (pin 26) CS Pin TFT. CS CS1(9), CS2(10) works w/o either????
' PGD PortB.6 (pin 27)
' PGC PortB.7 (pin 28)

DEFINE NO_CLRWDT 1
#DEFINE TOUCH_SCREEN 1
#DEFine dbug 1 ; Comment if not req'd.
;-----------connection----------
; pic tft
; <tft_port.tft_dc_bit >-------< dc >
; <tft_port.tft_cs_bit >-------< cs >
; <tft_port.tft_rst_bit>-------< rst >
; <msspx.sdo >-----------------< mosi >
; <msspx.sck >-----------------< sck >
; <back_light>-----------------< led > via pnp cct


;*****************NEW EASY PIN DEFINES*********************************
tft_dc_bit con 3 ;ie bit 3
tft_cs_bit con 5 ;ie bit 5
tft_rst_bit con 4 ;ie bit 4
;*****************NEW EASY PIN DEFINES*********************************

tft_port var latb
back_light var latc.2 ; portc.2
cont var word ; backlight level

; WIDTH con 320 ; X MUST MATCH TFT MODULE
; HEIGHT con 240 ; Y
WIDTH con 160 ; X
HEIGHT con 128 ; Y

' my TOUCH_SCREEN connection definitions
T_CLK VAR PORTa.7
T_INPin VAR PORTa.4
T_OUTPin VAR PORTa.6
T_INT VAR PORTb.0
T_CS VAR LATb.2

number_of_buttons con 6
number_of_sliders con 1


INCLUDE "TFT_SPI.pbpmod" ;glcdc
; include "tft-ILI9431.bas"
include "tft-ST7735.bas"
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
INCLUDE "my_Elapsed_INT-18.bas"
include "TOUCH_TFT.PBPMOD" ;uncomment to use TOUCH_TFT
INCLUDE "font7x8.bas"
goto demostart

upbutton:
@ db 131,0 ; chr 131 is AN up arrow in this font THAT I'M USING

demostart:
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE
ENDASM

@ INT_ENABLE TMR1_INT

led_on var bit
led_on_time var word
time_now var word
BOXX VAR BYTE
BOXY VAR BYTE
BOXZ VAR BYTE
cnt var byte

clear

' latb=255 ; make sure tft etc are not selected ie all cs high *************NOW IN TFT INIT********************
TRISA=%00111111
TRISB=%11000011
TRISC=%11010011

ADCON0 = 0 ' Disable A/D.
ADCON1 = %00000110 ' All digital.

OSCCON = %01110000 ' Internal 8 Mhz Osc
OSCTUNE=%01000000 ' PLL ON
cont=500 ; half brightness
DEFINE OSC 32
buff var byte[32]
t2con=5
PR2 = 255;
CCPR1L = cont>>2; ;set pwm
ccp1con=12|((cont&3)<<4);
SSPCON1=$20 ;$20-21-22 works 20 IS FASTEST
SSPSTAT=$40
TEXTSIZE=2
gosub tft_init
gosub TOUCH_INIT

GOSUB ResetTime
GOSUB StartTimer

' #ifdef dbug
' trisb.7=0 ;DEBUG OUT
' latb.7=1
' pause 4000
' Serout2 PORTb.7,84,["ready ", 13,10]
' #ENDIF

#ifdef dbug
trisc.1=0 ; DEBUG OUT
; latc.1=1 ; Float high for True.
latc.1=0 ; Float low for Inverted. The Nortek white usb serial adapter used here.
pause 4000
; Serout2 PORTc.1,84,["ready True ", 13,10]
Serout2 PORTc.1,16468,["ready Inverted ", 13,10]
#ENDIF

glcdc font7x8 ;SET FONT
bg=$ffff
fg=0
fillrect 0,0,WIDTH,height ;cls
TEXTSIZE=4

GLCDc 50,103
GLCDC "READY"
pause 400
bg=$ffff
fg=0
fillrect 0,0,WIDTH,height ;cls

MAKEBUTTON 53,170,0,92 ,40,"Clear" ;
MAKEBUTTON 276,220,1,56,30,"Sleep"
MAKEBUTTON 280,150,2,60,"Led"
MAKEBUTTON 242,52,3,40 ; no text SEE BELOW FOR Another way to attach text
MAKEBUTTON 140,150,4,50,30," +"
MAKEBUTTON 205,150,5,50,30," -"
button_action.0[1]=1 ; flash text for this button
button_action.0[2]=1 ; flash text for this button
button_rpt.0[4]=1 ; auto rpt on button 4
button_rpt.0[5]=1 ; auto rpt on button 5

;another way to attach text to a button [HANDY FOR CHRS NOT IN ASCII 7 BIT PRINTABLE RANGE] EG THERE IS NO OTHER WAY TO GET CHR 131 IN A PBP STRING
@ GetAddress21 _upbutton ,_tft_bigaddress ;macro in dt_ints-18
button_Taddr[3*3] = tft_bigaddress[2]
button_Taddr[3*3+1]= tft_bigaddress[1] ;assign a new text to button 3
button_Taddr[3*3+2]= tft_bigaddress[0]
button_Tsize[3] =1 ;UPDATE NUMBER OF text CHRS for this button

MAKESLIDER 100,80,0
slider_index =0
the_slider = slider_index *SL_SZ ; set slider indexing properly
slider_FG[the_slider ]=$ffe0 ;set slider bar colour if default not desired
slider_count[the_slider]=cont/10
bg=0
INTCON2.6=0
led_on=0
main:
fg=$7FF
DRAWBUTTON 0
DRAWBUTTON 1
DRAWBUTTON 2
DRAWBUTTON 3
DRAWBUTTON 4
DRAWBUTTON 5
slider_index =0
the_slider = slider_index *SL_SZ
slider_MODE[the_slider]=0 ;FORCE DRAW OF SLIDER
DRAWSLIDER 0

fg=$ffFF
DRAWcircle 60 , 60 , 20
fillcircle 60 , 60 , 20

LOP:
GOSUB CK_BUTTON
IF BUTTON_STATE[0]==2 THEN
BUTTON_STATE[0]=0
fg=0
fillrect 0,0,WIDTH,height ;cls
goto main
elseIF BUTTON_STATE[1] THEN
if BUTTON_STATE[1]==2 then ; shut it all down
gosub tft_sleep
ccp1con=0
back_light=1
pause 100
intcon=$10
@ sleep
@ nop
intcon=$c0
gosub tft_wake
CCPR1L = cont>>2;
ccp1con=12|((cont&3)<<4);
endif
BUTTON_STATE[1]=0
elseIF BUTTON_STATE[2] THEN ;short or long press
drawimage 220,30,45,45,led
led_on=1
gosub get_now
led_on_time=time_now
BUTTON_STATE[2]=0
elseIF BUTTON_STATE[3] THEN
if BUTTON_STATE[3]==2 then
drawimage 220,30,45,45,led
else
DRAWBUTTON 3
fg=0
fillrect 220,30,45,45
drawimage 220,30,45,45,led2
endif
BUTTON_STATE[3]=0
elseIF BUTTON_STATE[4] THEN ; short , long press or RPT
CNT=CNT+1
BUTTON_STATE[4]=0
gosub s_cont
elseIF BUTTON_STATE[5] THEN ; short , long press or RPT
CNT=CNT-1
BUTTON_STATE[5]=0
gosub s_cont
endif
slider_index =0
the_slider = slider_index *SL_SZ
IF slider_MODE[the_slider]&1 THEN ; adjust brightness
gosub set_cont
ENDIF

if led_on then
gosub get_now
if abs(time_now-led_on_time) > 100 then
DRAWBUTTON 3
fg=0
' fillrect 220,30,45,45
' drawimage 220,30,45,45,led2
led_on=0
endif
endif

if SecondsChanged then
fg=$F800
bg=$ffff
SecondsChanged=0
TEXTSIZE=2
BOXX=6*7*TEXTSIZE
BOXY=HEIGHT-(TEXTSIZE*8+1)
ARRAYWRITE buff,[dec2 seconds,0]
GLCDSTR BOXX,BOXY ,buff
endif

if hoursChanged then
hoursChanged=0
TEXTSIZE=2
BOXY=HEIGHT-(TEXTSIZE*8+1)
ARRAYWRITE buff,[dec2 hours,0]
GLCDSTR 1,BOXY ,buff
endif

if minutesChanged then
TEXTSIZE=2
minutesChanged=0
BOXX=3*7*TEXTSIZE
BOXY=HEIGHT-(TEXTSIZE*8+1)
ARRAYWRITE buff,[dec2 minutes,0]
GLCDSTR BOXX,BOXY,buff
endif
goto LOP

set_cont:
cont = 1000 - slider_COUNT[0]*10
CCPR1L = cont>>2;
ccp1con=12|((cont&3)<<4);
slider_MODE[the_slider]=slider_MODE[the_slider]&$FE
cnt= slider_COUNT[the_slider]
s_cont:
TEXTSIZE=3
bg=0
fg=$7FF
ARRAYWRITE buff,[dec3 cnt,0]
GLCDSTR 50,10 ,buff
return

get_now :
@ INT_DISABLE TMR1_INT ;disable int to get value of ticks WITHOUT ROLLOVER ISSUES [TICKS IS NOT ATOMIC]
time_now=ticks ; 1 tick==10mS
@ INT_ENABLE TMR1_INT
return

#ifdef dbug
db_prn:
intcon.7=0
Serout2 PORTb.7,84,["t ",#TU_TMP3 , 13,10]
intcon.7=1
return
#ENDIF

INCLUDE "led2.bas"
INCLUDE "led.bas"

richard
- 8th February 2022, 02:17
Any help or suggestions appreciated.

most of the addin's have user-commands. in the include file where the commands are declared there are comments on how to use them

eg in touch_tft


;work around fact that usercommand won't accept a 1 chr string (thinks its a const) so leading space is ignored in button title
USERCOMMAND "DRAWBUTTON" ; BTN { BUTTON NUMBER }
USERCOMMAND "MAKEBUTTON" ; X,Y ,BTN,{w},{h} ,"title" [(XY IS button centre) BUTTON number , BUTTON size WILL BE default_button_size IF SIZE OMITTED h=w if h omitted]
USERCOMMAND "DRAWSLIDER" ; SLIDER { SLIDER NUMBER }
USERCOMMAND "MAKESLIDER" ; X,Y {W,H},SLIDER [(XY IS LHBottom CNR ) SLIDER number size WILL BE default IF W,H OMITTED


x, y are cartesian coordinates for the screen position of the desired object , it goes without saying that x is horizontal axis [width] y vertical axis [height] when facing screen. both x and y need to be on the screen, objects can also have a width [w] and a height [h] and it follows that
x+w should still be on the screen as well as with y+h

if your objects don't fit on the screen then things won't play nice


start here
which of these fit on a screen 160x128 ?

MAKEBUTTON 53,170,0,92 ,40,"Clear" ;
MAKEBUTTON 276,220,1,56,30,"Sleep"
MAKEBUTTON 280,150,2,60,"Led"
MAKEBUTTON 242,52,3,40 ; no text SEE BELOW FOR Another way to attach text
MAKEBUTTON 140,150,4,50,30," +"
MAKEBUTTON 205,150,5,50,30," -"

answer none
and so on


I'm really interested in using Portrait mode too

in chipset driver file you will find this


;SCREEN ORIENTATION
TFTDATA $18 ;bit3 controls rgb/bgr 0=bgr , 1 =rgb
;bit2 controls refresh direction long axis
;bit4 controls refresh direction short axis
;bit5 controls portrait/landscape 1=portrait , 0 =landscape / adjust height width to suit
;bit6 controls write direction short axis
;bit7 controls write direction long axis

it needs to be setup to match your screen re-orientation and mirror imaging, its no big deal
you need to set height/width declares to match