A tft addin for pbp3 - Page 4


Closed Thread
Page 4 of 4 FirstFirst 1234
Results 121 to 142 of 142
  1. #121
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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



    Code:
      
    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
    Attached Files Attached Files

  2. #122
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    CHK?RP , Banksel it gets me every time

  3. #123
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    FIXED again
    Attached Files Attached Files

  4. #124
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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 ?

  5. #125
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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.

  6. #126
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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

  7. #127
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    Would love to upgrade, but being a casual user, and between jobs, upgrading is simply not an option for me at the monemt

  8. #128
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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.

  9. #129
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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
    Code:
    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
    Attached Files Attached Files

  10. #130
    Join Date
    Oct 2013
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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?

  11. #131
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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


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

  12. #132
    Join Date
    Oct 2013
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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

  13. #133
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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

  14. #134
    Join Date
    Oct 2013
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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.

  15. #135
    Join Date
    Oct 2013
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: A tft addin for pbp3

    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

  16. #136
    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.

  17. #137
    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]

  18. #138
    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   

  19. #139
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    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

  20. #140
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    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

  21. #141
    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"

  22. #142
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    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 02:26.
    Warning I'm not a teacher

Similar Threads

  1. Replies: 0
    Last Post: - 25th September 2013, 18: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, 08:50
  3. I really need some help with PBP3
    By Ramius in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th February 2012, 16:05
  4. What's with PBP3?
    By BrianT in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th August 2011, 17:09
  5. Experience of driving TFT screens?
    By isaac in forum General
    Replies: 1
    Last Post: - 26th September 2008, 00:15

Members who have read this thread : 7

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