A tft addin for pbp3


Closed Thread
Results 1 to 40 of 142

Hybrid View

  1. #1
    Join Date
    Oct 2013
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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.

  2. #2
    Join Date
    Oct 2013
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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,lCTe mp.lowbyte, pritisak.HighByte, pritisak.LowByte,vlaga,_
    vlagaostatak,LUX.HighByte,lux.LowByte]

  3. #3
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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
    Attached Images Attached Images   

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,174


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,714


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    without seeing your code it looks very much like you are writing outside the screen boundaries
    Warning I'm not a teacher

  6. #6
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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

    Code:
    '****************************************************************************
    '*  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"

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,714


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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

    Code:
    ;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

    Code:
         ;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
    Last edited by richard; - 8th February 2022 at 03:26.
    Warning I'm not a teacher

Similar Threads

  1. Replies: 0
    Last Post: - 25th September 2013, 19:33
  2. code examples / libraries for ILI9320 2.8" TFT LCD Module
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 6th June 2013, 09:50
  3. I really need some help with PBP3
    By Ramius in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th February 2012, 17:05
  4. What's with PBP3?
    By BrianT in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th August 2011, 18:09
  5. Experience of driving TFT screens?
    By isaac in forum General
    Replies: 1
    Last Post: - 26th September 2008, 01:15

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts