SSD1306 INCLUDE for PBP3 - Page 3


+ Reply to Thread
Page 3 of 3 FirstFirst 123
Results 81 to 120 of 120
  1. #81
    Join Date
    Feb 2013
    Posts
    860


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Well, they're being sold for $1.4/ea, - same price as infamous "nokia" 128x128 LCD
    https://item.taobao.com/item.htm?id=661389161320

    In fact, I don't need grayscale at all, simple BW would be enough.
    Since I was not able to launch SSD1306 with PBP, maybe I'll have better luck with this?

  2. #82
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    at that price you can't go far wrong
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  3. #83
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    113


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Hi Folks,

    I have a couple of the small 0.96" SSD1306 displays and I've successfully been able to write small and big text to it where I want (thanks Richard). The display is perfect for my application which uses a small DIN rail enclosure with limited area for a screen.

    But I'm unable to write variables to it - I see back in post #36 Henrik mentioned "I've managed to print text and variables on the screen..." so it can be done - Henrik can you please shed some light on how you did this before I bother Richard?

    Is there also a way to invert the 7x5 character block?

    Thanks and regards,
    Bill

  4. #84
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,414


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Use ARRAYWRITE to load the buffer array/string with whatever you want to be displayed, then print on the display using GLCDSTR
    Code:
    Arraywrite BUFF,[SDEC LTC2986_Result/1000, ".", DEC3 LTC2986_Result//1000, 94, " ",0]
    GLCDSTR 78,2, BUFF

  5. #85
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    113


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Thanks Henrik that works well for byte size variables but I get nothing when declared word size. Using soft i2c on 16f1705, ver 3.1.4.4

    The code compiles and appears to program normally but the screen isn't lit, returning to byte sees normal operation restored. Is there a work around for this?

    Any idea how to invert a character also? This would be useful for alarm indications.

    Cheers,
    Bill

  6. #86
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,237


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Arrayread and Arraywrite accept only Byte variables. Maybe double the numbers of array elements?

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    ???


    Arraywrite BUFF,[SDEC LTC2986_Result/1000, ".", DEC3 LTC2986_Result//1000, 94, " ",0]

    LTC2986_Result must be at least a word it could be a long , a byte / by 1000 always = 0 what would be the point

    Arraywrite will write anything properly formatted into the buffer without error as long as it fits
    the display will show it if the results are in the font and it will fit on the screen
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  8. #88
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,414


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    It's correct that ARRAYWRITE writes bytes into an byte array but using modifiers like DEC extracts decimal digits and writes each digits ASCII representation, as individual BYTES, into the array. The example posted above is from a working project. I don't know if LTC2986_Result is a WORD or a LONG but it sure ain't a BYTE :-)

    Why it doesn't work in Bills case is close to impossible to say without at least seeing some code.

  9. #89
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    113


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Hi Henrik,

    Thanks for your help, here's the code warts and all, plus a pic of the display in use with byte variable.

    Needless to say, if I can't write word vars then this display will gather dust.

    Any suggestions also on how to invert a character (not just the full screen) are welcome.

    Cheers,
    Bill

    Code:
     '*******************************************************************
    '*  Name    : ssd1306_DEMO_WJS.PBP                                  *
    '*  Author  : richard                       #### semi Working code ####  *
    '*  Notice  :                                                       *
    '*          :                                                       *
    '*  Date    : 07Feb22                                               *
    '*  Device  : 16F1705 (8k bytes)                                    * 
    '*  Version : 1.0       1952 words (PBP 3.1.4.4)                    *
    '*  Notes   :                                                       *
    '*          : Originally ssd1306_DEMO.PBP for pic 16F1619, edit     *
    '*          : by WJS for 16F1705 and explore the functions.         *
    '*          :                                                       *
    '*          : With thanks to Richard for the hard yards.            *
    '*          : See: www.picbasic.co.uk/forum/showthread.php?t=23758  *
    '*          :                                                       *
    '*  ======> : How to do inverse characters?                         *
    '*          : How to write Word variables?                          *
    '*          :                                                       *
    '********************************************************************
    
    ' History:
    ' 06Feb22   Trial for suitability with Logger. Tested okay at 3.0 volts also (although programmer doesn't like it).
    
    ' The error messages after compile indicate missing macros, these relate to the bar mods Richard did for Louislouis
    ' the forum post above mentions it.  Still compiles and runs okay.
    '[ASM WARNING] SSD1306_DEMO_WJS.ASM (424) : Found label after column 1. (GLCD_BAR?CCBWC)
    '[ASM WARNING] SSD1306_DEMO_WJS.ASM (456) : Found label after column 1. (GLCD_BAR?CCBCC)
    
    ' SSD1306 INCLUDE for PBP3
    'Features :-
    'Pic 16 or 18
    'Tiny size about 1.5k words for soft i2c 1.3k for hw i2c
    '64X128 OR 32X128 DISPLAYS
    'SOFT I2C OR HARDWARE I2C
    'NORMAL OR DOUBLE SIZE CHAR
    'HORIZ and VERT LINES
    'Speed for hw i2c tested up to 2,666,666 clock rate, makes soft i2c look like a snail
    'Simple Usercommand Commands
    
    '=======================================================================================================================
    '        CONFIGURE DEVICE     ######## note weird effects if ZCDDIS_OFF is used.
    '=======================================================================================================================
    #CONFIG ; 16F1705
        __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF
        __config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCDDIS_ON & _PLLEN_ON & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_OFF	   
    ;    __config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCDDIS_ON & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_OFF	   
    #ENDCONFIG
    
    @ ERRORLEVEL -306   ; turn off 'crossing page boundary' message
     
    ; --- *** Oscillator  *** ---------------------------------------------------
    '    DEFINE  OSC  4              ' Adjust to suit design.
    '    define  OSC  8
    '    define  OSC  16
        define  OSC  32              ' Aim for highest clock - slower sees distinct line writes.
    '    OSCCON  = %01101011         ' Internal 4MHz osc.
    '    OSCCON  = %01110011         ' Internal 8MHz osc.
    '    OSCCON  = %01111011         ' Internal 16MHz osc.
        OSCCON  = %11111010         ' Internal 32MHz osc PLL (if PLLEN set in config). 
    ; Tried lots of combinations but looks like fastest is 16Mhz (pause 1000 = 2 seconds).
    
        DEFINE DEBUG_REG PORTC      ' Debug pin port.
        DEFINE DEBUG_BIT 3          ' Debug pin.
        DEFINE DEBUG_BAUD 9600      ' Debug baud rate
        DEFINE DEBUG_MODE 1         ' Debug mode: 0 = True, 1 = Inverted
    '    DEFINE DEBUG_PACING 1000    ' Debug character pacing in us
    '    DEFINE DEBUGIN_BIT 4        ' Input pin.
    
        OPTION_REG.7 = 1            ' Disable weak pullups.
    '    OPTION_REG.7 = 0            ' Enable weak pullups.
    
        ADCON0 = 0                  ' No ADC.
        ANSELA = 0                  ' Disable ADC.
        ANSELC = %00000000          ' All Dig.
    
        CM1CON0 = 0                 ' Comparators off.
    
        TRISA = %000000             ' All output.
        TRISC = %000100             ' C.4 serial in.
    
    ' Connections as follows:
    '     ****16F1705 PIC**** Comments
    '
    ' Vdd          (pin 1)    5 volts.              
    '         RA5  (pin 2)    T1clk.                Spare.       
    '         RA4  (pin 3)	  AN3, T1G.             Spare.
    ' MCLR    RA3  (pin 4)    IOC.  Pull High 10k.  Spare.
    '         RC5  (pin 5)	  Opamp2in+, CCP1.      I2C Data   Module has its own pullups.
    '         RC4  (pin 6)    Opamp2in-.            I2C Clock. Module has its own pullups.
    '         RC3  (pin 7)    AN7, Opamp2Out, CCP2. Serout for sending (9600) via 1k.      
    '         RC2  (pin 8)    AN6, Opamp1Out.       Spare.
    '         RC1  (pin 9)    AN5, Opamp1in-.       Spare.
    '         RC0  (pin 10)   AN4, Opamp1in+.       Spare.
    '         RA2  (pin 11)   AN2, DAC1out2.        Spare.
    ' ICSPclk RA1  (pin 12)   AN1, Vref+.           Spare.
    ' ICSPdat RA0  (pin 13)   AN0, DAC1out1.        Spare.
    ' Vss  Ground  (pin 14)   
    
    char var byte
    x    var byte  
    y    var byte    
    'BUFF VAR BYTE[16]
    BUFF VAR BYTE[23]           ' Max number if using full width, less than gives overwrites.
    AvgT var byte               ' Yes can write byte variables.
    ;AvgT var word               ' NO, word variable hangs the display.
    
    ;AvgT = 2546                 ' Test value
    
    ;use this define for hw i2c 
    ;#define hwi2c 1 
    #DEFINE PIC16 1 
    ;set and uncomment these to use softi2c
    SCL var PortC.4             ' I2C Clock
    SDA var PortC.5             ' I2C Data
    
    ; set these to match display
    ssdheight con 7             ; 7 = 8 PAGES  64*128 ,  3 = 4 pages 32*128
    ssdwidth  con 127           ; 128 PIXELS WIDE
    sdd1306_addr con $78        ;
    
    Include "ssd1306_I2C.INC"   ' bring it in
    include "font7x5_16.bas"
    
    debug "I'm Alive...",13,10  ' Heatbeat.
    
    '==========================    MAIN  Routine    ==============================
    gosub glcd_init
    BIG_TEXT = 0                        ; Small characters (20 across).  Yellow first line.
        GLCD_CLR                        ; CLS.
    
    looper:
        ARRAYWRITE BUFF,["Testing this LCD...!",0] ' 
        GLCDSTR  0,1,BUFF               ' Line 1, start at pixel 0.
        ARRAYWRITE BUFF,["bytes ok, words NBG!",0] ' 
        GLCDSTR  0,3,BUFF               ' Line 3.
        ARRAYWRITE BUFF,["RTC sync'd to GPS ok",0] ' 
        GLCDSTR  0,5,BUFF               ' Line 5, start at pixel 0.
        ARRAYWRITE BUFF,["Logging 10hz RAW Yes",0] ' 
        GLCDSTR  0,6,BUFF               ' Line 6.
        ARRAYWRITE BUFF,["AvgT: ",0]    ' 
        GLCDSTR  0,7,BUFF               ' Line 7.
    change:
    '    for avgt = 6789 to 6889 step 5  ' Word size test - hangs the display.
        for avgt = 100 to 255 step 5
        ARRAYWRITE BUFF,[dec AvgT,0]    ' 
        GLCDSTR  36,7,BUFF              ' Line 7.
        pause 500                       ' not too fast.
        next                            ' increment.
        goto change                     ' repeat.
    
    ;SSDc $A6  ' $A6=NORMAL MODE;  $A7=INVERSE MODE     ' inverts whole screen - how to invert only one char?
    
    GOTO looper
    
    END
    Attached Images Attached Images  

  10. #90
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Well that was a nasty little bug, the chk?rp macro does not work inside a macro as i assumed it would
    yet another

    Code:
    '****************************************************************'*  Name    : ssd1306_I2C.INC                                   *
    '*  Author  : richard                                           *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    : 8/2/2022                                          *
    '*  Version : 1.2                                               *
    '*  Notes   : font address banksel fixed                        *
    '*          :FOR pic 16/18       SSD1306                        *
    '****************************************************************
     
     goto overglcd
    ; adjust to suit and  place these in main prg
    ;use this define for hw i2c 
    ;#define hwi2c 1 
    ;#DEFINE PIC16 1    ;IF PIC 16 USED  [USE PIC16 FONT TOO}
    ' ssdheight con 7       ; 7 = 8 PAGES  64*128 ,  3 = 4 pages 32*128
    ' ssdwidth  con 127     ; 128 PIXELS WIDE
    ' SCL var PortC.3       ' I2C Clock
    ' SDA var PortC.4       ' I2C Data
    ' sdd1306_addr con $78
     
     USERCOMMAND "GLCDC"     ; X,Y,CHR  0 <  X < 127  ,   0 <  Y < 7    31 < CHR > 127  
     USERCOMMAND "GLCD_CLR"  ;clear area x,y,W,H    
     USERCOMMAND "GLCDSTR"   ;STRING @ X,Y  or   Constant String
     USERCOMMAND "GLCDDHL"   ; x,y,L ,bit-patten
     USERCOMMAND "GLCDDVL"   ; x,y,H
     USERCOMMAND "SSDC"      ;cmd BYTE TO SSD1306
     USERCOMMAND "SSDBM"     ;x,y,w,h,label  
    
    
     ASM  
     
     
     ;----------------------VERT LINE------------------------------------        
    GLCDDVL?CCC  macro Xin ,Yin , Hin 
        MOVE?CB  Xin ,_gx 
        MOVE?CB  Yin,_gy 
        MOVE?CB  Hin ,_gl 
        L?CALL _xyy
        endm 
           
     ;----------------------HORIZ LINE------------------------------------ 
    GLCDDHL?CCCC  macro Xin ,Yin , Win ,Cin
        MOVE?CB  Xin ,_gx 
        MOVE?CB  Yin,_gy 
        MOVE?CB  Win ,_gl
        MOVE?CB  Cin ,_glcdData 
        L?CALL _xyx
        endm  
     
      ;----[const String]---------------------------------------------------------------
    GLCDSTR?CCS  macro Xin ,Yin,Cin 
     IFNDEF  TBLPTRL
        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
        da Cin, 0 ;add string to flash at TheString address and end string with 0
    OverStr
        MOVE?CW  TheString, _glcd_bigaddress
        MOVE?CB Xin , _gx
        MOVE?CB Yin , _gy
        L?GOTO  _GlcdUnpackStr
     ELSE  
        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   UPPER TheString
        movwf   TBLPTRU
        movlw   HIGH TheString 
        movwf   TBLPTRH
        movlw   LOW TheString
        movwf   TBLPTRL
        MOVE?CB Xin , _gx
        MOVE?CB Yin , _gy
        L?CALL  GLCD_Cstr_out 
     ENDIF     
        endm  
        
         
    SSDBM?CCCCL   macro Xin ,Yin ,Win,Hin,BMin 
     IFNDEF  TBLPTRL
        ERROR BITMAPS ONLY SUPPORTED ON PIC18
     ENDIF
         MOVE?CB Xin , _gx
         MOVE?CB Yin , _gy
         MOVE?CB Hin/8-1 , _gy_
         MOVE?CB Win+Xin-1 , _gx_
         MOVE?CW Win*Hin/8 , _glcd_rad
         banksel   _glcdbm
         movlw low BMin
         movwf _glcdbm
         movlw high BMin
         movwf _glcdbm +1
         BANKSEL 0
         L?CALL  _ssd_bitmap
          endm
    
    
    
    
     ;----------------------Strings------------------------------------
    GLCDSTR?CBB  macro Xin ,Yin ,Bin
        MOVE?CB Xin , _gx
        MOVE?BB Yin , _gy
        MOVE?CB high Bin, FSR1H ;load highbyte 
        MOVE?CB low  Bin, FSR1L ;load low byte
        L?CALL  GLCD_str_out
        endm         
    GLCDSTR?CCB  macro Xin ,Yin ,Bin
        MOVE?CB Xin , _gx
        MOVE?CB Yin  ,_gy
        MOVE?CB high (Bin), FSR1H ;load highbyte 
        MOVE?CB low  (Bin), FSR1L ;load low byte
        L?CALL  GLCD_str_out
        endm              
    GLCDSTR?BBB  macro Xin ,Yin ,Bin
        MOVE?B  Xin, _gx
        MOVE?B  Yin, _gy
        MOVE?CB high Bin, FSR1H ;load highbyte 
        MOVE?CB low  Bin, FSR1L ;load low byte
        L?CALL  GLCD_str_out
        endm 
    GLCDSTR?WBB  macro Xin ,Yin ,Bin
        MOVE?WB Xin, _gx
        MOVE?BB Yin, _gy
        MOVE?CB high Bin, FSR1H ;load highbyte 
        MOVE?CB low  Bin, FSR1L ;load low byte
        L?CALL  GLCD_str_out
        endm  
    GLCDSTR?WWB  macro Xin ,Yin ,Bin
        MOVE?WB Xin, _gx
        MOVE?WB Yin, _gy
        MOVE?CB high Bin, FSR1H ;load highbyte 
        MOVE?CB low  Bin, FSR1L ;load low byte
        L?CALL  GLCD_str_out
        endm 
     
     
    SSDC?C  macro Cin
        MOVE?CB  Cin , _glcdData
        L?CALL   _cmd_byte
       endm 
    SSDC?B  macro Cin
        MOVE?BB  Cin , _glcdData
        L?CALL   _cmd_byte
       endm 
    
    
    GLCD_CLR? macro
        MOVE?CB  0, _gx 
        MOVE?CB  0, _gy 
        MOVE?CB  _ssdwidth, _gx_ 
        MOVE?CB  _ssdheight, _gy_
        L?CALL   _glcd_clrxy
       endm 
    
    
    GLCD_CLR?CCCC macro   Xin ,Yin,X1in ,Y1in
        MOVE?CB  Xin, _gx 
        MOVE?CB  Yin, _gy 
        MOVE?CB  X1in, _gx_ 
        MOVE?CB  Y1in, _gy_
        L?CALL   _glcd_clrxy
       endm 
           
     ;----------------------Character @ X,Y ------------------------------------        
    GLCDC?BBB  macro Xin ,Yin , Bin
        MOVE?BB  Xin, _gx 
        MOVE?BB  Yin, _gy 
        MOVE?BB  Bin, _glcdCh
        L?CALL   _gcga
        endm    
    GLCDC?WBB  macro Xin ,Yin , Bin
        MOVE?WB  Xin, _gx 
        MOVE?BB  Yin, _gy 
        MOVE?BB  Bin, _glcdCh
        L?CALL   _gcga
        endm  
    GLCDC?WWB  macro Xin ,Yin , Bin
        MOVE?WB  Xin, _gx 
        MOVE?WB  Yin, _gy 
        MOVE?BB  Bin, _glcdCh
        L?CALL  _gcga
        endm    
            
    GLCDC?BBC  macro Xin ,Yin , Cin
        MOVE?BB  Xin, _gx 
        MOVE?BB  Yin, _gy 
        MOVE?CB  Cin ,_glcdCh
        L?CALL   _gcga
        endm   
    GLCDC?WBC  macro Xin ,Yin , Cin
        MOVE?WB  Xin, _gx 
        MOVE?BB  Yin, _gy 
        MOVE?CB  Cin ,_glcdCh
        L?CALL   _gcga
        endm
    GLCDC?CCC  macro Xin ,Yin ,Cin
        MOVE?CB  Xin ,   _gx 
        MOVE?CB  Yin,    _gy 
        MOVE?CB  Cin,   _glcdCh
        L?CALL   _gcga 
        endm   
    GLCDC?CCB  macro Xin ,Yin ,Bin
        MOVE?CB  Xin ,  _gx 
        MOVE?CB  Yin,    _gy 
        MOVE?BB  Bin, _glcdCh
        L?CALL   _gcga 
        endm  
    
    
        
       
    GLetAddress macro Label, Wout
        BANKSEL Wout   ;  the fix
        movlw low Label          ; get low byte
        movwf Wout
        movlw High Label         ; get high byte
        movwf Wout + 1  
        BANKSEL 0
        endm 
          
     IFDEF    TBLPTRL 
         
    GLCD_Cstr_out
        tblrd   *+
        movf   TABLAT,w
        bz	GLCD_exit_Cstr_out  ; EXIT ON Null char 
        CHK?RP  _glcdCh 
        MOVWF   _glcdCh 
        CHK?RP  _glcd_bigaddress
        movff   TBLPTRU,_glcd_bigaddress
        movff   TBLPTRH,_glcd_bigaddress+1
        movff   TBLPTRL,_glcd_bigaddress+2
        L?CALL  _gcga
        CHK?RP  _glcd_bigaddress
        movff   _glcd_bigaddress   ,TBLPTRU
        movff   _glcd_bigaddress+1 ,TBLPTRH
        movff   _glcd_bigaddress+2 ,TBLPTRL
        bra     GLCD_Cstr_out        
    GLCD_exit_Cstr_out
        BANKSEL 0
        return 
         
    
    
          
    GLCD_str_out
        movf POSTINC1, W	; Get a character
        bz	GLCD_exit_strout  ; EXIT ON Null char 
        CHK?RP  _glcdCh 
        MOVWF _glcdCh
        BANKSEL 0
        L?CALL _gcga  
        bra    GLCD_str_out        
    GLCD_exit_strout
        BANKSEL 0
        return    
     ELSE   
    
    
      
    GLCD_str_out
        IFDEF BSR
            MOVIW FSR1++	; Get a character
            BTFSC STATUS,Z
            BRA	GLCD_exit_strout  ; EXIT ON Null char 
        ELSE
            movf INDF, W	; Get a character
           BTFSC STATUS,Z
            GOTO	GLCD_exit_strout  ; EXIT ON Null char 
            INCF FSR,F 
        ENDIF
        CHK?RP  _glcdCh 
        MOVWF _glcdCh
        MOVE?BB FSR1L,_glcd_bigaddress
        MOVE?BB FSR1H,_glcd_bigaddress+1
        BANKSEL 0
        L?CALL _gcga 
        MOVE?BB _glcd_bigaddress,FSR1L
        MOVE?BB _glcd_bigaddress+1,FSR1H
        GOTO  GLCD_str_out      
    GLCD_exit_strout
        BANKSEL 0
        return     
     ENDIF 
    endasm
        
        glcd_bigaddress  VAR BYTE[3]
        glcd_buff        VAR BYTE[32]
        BIG_TEXT    var byte 
        glcd_rad    var word
        glcdCh      var byte  'chr  DATA
        glcdData    VAR byte  'DATA
        glcdBC      VAR word  'gca  var
        glcdDC      VAR BYTE  'gca  var
        glcdFont    var word  'font address
        glcdOffset  VAR word  'font offset
        glcdbm      VAR word  'bitmap offset
        gl          var byte  'width/height
        gy          var byte  'gca  pg   address
        gy_         var byte  'gca  pg   address
        gx          var byte  'gca  row  address
        gx_         var byte  'gca  row  address
        GRX         var byte  'DATA
        ctemp       var word
        ctemp1      var word
        ssd_add     var byte
        glcdStrAddr var word ext
    @glcdStrAddr =   _glcd_bigaddress 
    
    
    GlcdUnpackStr:     
        readcode glcdStrAddr,CTEMP
        glcd_bigaddress[2]  = CTEMP&$7f
        ctemp=ctemp<<1
        glcdCh = CTEMP.HIGHBYTE 
        glcdStrAddr=glcdStrAddr+1
        if   glcdCh then 
            gosub gcga
            glcdCh =  glcd_bigaddress[2]
        else
            return
        endif
        if   glcdCh then 
            gosub gcga
        else
            return
        endif
        goto   GlcdUnpackStr:     
    return    
        
        
     
    glcd_init: 
    #ifdef hwi2c
        SSPSTAT = 0 'High Speed Filter
        SSPADD = $26'400 kHz @32 MHz
        SSPCON1 = %00101000 'I2C Master Mode Enable
        SSPCON3 = 0
        
    #endif
        @ GLetAddress _font7x5,_glcdFont
        ssd_add = sdd1306_addr 
        SSDc $AE ' Display OFF
        SSDc $d5 
        SSDc $80 
        SSDc $a8 : SSDc $3f 
        SSDc $D3 : SSDc $00 ; Set Display Offset Mode Set 0  
        if ssdheight > 3  then
            SSDc $40   ' Set display start line 0 
        else
            SSDc $60   ' Set display start line 4 
        endif 
        SSDc $8D : SSDc $14 ' Set Charge Pump Internal
        SSDc $20 : SSDc $00 ' Adressing mode Horizontal
        SSDc $A1   ' set segment remap column 127 as start
        SSDc $C8   ' Com Scan Direction, Flip display vertically
        SSDc $DA   ' set COM pins
        if ssdheight > 3  then
            SSDc$12  ' set COM pins = 128x64=$12   
        else
            SSDc$02  ' set COM pins = 128x32=$02
        endif 
        SSDc $81 : SSDc$7F  ' Set brightness to $01 to $FF  ($7F is default, $01 is faint)
        SSDc $DB : SSDc$40  ' Set VCOM Deselect Level
        SSDc $B0  ' Set Page Address From $B0 to $B7 
        SSDc $2e  ; scroll off
        SSDc $A4  ' display ON continue
        SSDc $A6  ' $A6=NORMAL MODE;  $A7=INVERSE MODE
        SSDc $AF  ' Display ON
    return 
    
    
    
    
    xyx:  ;draw HORIZ LINE @X,Y for W len   0<X>127   1<W>127
        FOR GRX = 0 TO 31
            glcd_buff[GRX] = glcdData  ;uses this var to set which bit/s is used to generate line
        NEXT
        gx = gx&ssdwidth
        gx_= gx + gl
        gy = gy&ssdheight
        gy_= gy
        gosub   setxy
        GRX = gl/32
        glcd_rad = 32
        WHILE GRX
            gosub ssd_data
            GRX = GRX-1
        WEND
        glcd_rad = gl//32
        IF glcd_rad  THEN
            gosub ssd_data
        ENDIF
    return 
    
    
    
    
    xyy:       ;draw VERT LINE @X,Y for W len   @X 0<X>127   1<W>7  
        FOR GRX = 0 TO ssdheight
            glcd_buff[GRX] = 255
        NEXT
        gx = gx&ssdwidth
        gx_= gx
        gy = gy&ssdheight
        gy_= gy+GL
        gosub   setxy
        glcd_rad = gl
        gosub ssd_data
    return
          
        
    glcd_clrxy:    ' clear area  x1y1 to x2 y2
        FOR GRX = 0 TO 31
            glcd_buff[GRX] = 0
        NEXT
        CTEMP = (1 + GX_ - GX)*(1 + GY_ -  GY)
        gosub   setxy
        GRX = CTEMP/32
        glcd_rad=32
        WHILE GRX
            gosub ssd_data
            GRX = GRX-1
        WEND
        glcd_rad = CTEMP//32
        IF GRX THEN
            gosub ssd_data
        ENDIF
    return
      
        
    gcga:     ;draw a chr
        GY = gy&ssdheight      
        GY_= gy + BIG_TEXT 
        gx = gx&ssdwidth
        #ifdef PIC16
        glcdOffset = (glcdch-32)*3 + glcdFont  ; point to cga data
        #ELSE
        glcdOffset = (glcdch-32)*6 + glcdFont  ; point to cga data
        #ENDIF
        gosub unpack
        IF BIG_TEXT THEN 
            GOSUB SSD_BIG
            glcd_rad = 24
            gx_= gx + 11
        ELSE
            glcd_rad = 6
            gx_= gx + 5
        ENDIF
        gosub setxy
        gosub ssd_data
        gx = gx_+ 1 + BIG_TEXT 
        IF GX > 121  THEN  gx=0    ;wrap 
    return   
    
    
    ssd_data:   ;send data block
    #ifdef hwi2c
     glcdBC=0
     SSPCON2.0 = 1 ; SEN - Start Condition Enable Bit 
     WHILE SSPCON2.0 = 1 : WEND ; Wait for Start to complete
     SSPBUF = ssd_add ; Move data to SSPBUF
     WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
     While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave 
     SSPBUF = $40 ; Move data to SSPBUF
     WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
     While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave 
     while  glcdBC < glcd_rad
         SSPBUF = glcd_buff[glcdBC] ; Move data to SSPBUF
         WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
         While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave 
         glcdBC=glcdBC+1   
     wend   
     SSPCON2.2 = 1 ; PEN - send stop bit
     While SSPCON2.2 = 1 : Wend ; Wait for SSP to complete
    #else
     i2Cwrite SDA,SCL,ssd_add,[$40,str glcd_buff\ glcd_rad]
    #endif 
    return 
    #ifndef PIC16   
    ssd_bitmap:   ;send graphic block from flash
     gosub setxy
     glcdBC=0
     SSPCON2.0 = 1 ; SEN - Start Condition Enable Bit 
     WHILE SSPCON2.0 = 1 : WEND ; Wait for Start to complete
     SSPBUF = ssd_add ; Move data to SSPBUF
     WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
     While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave 
     SSPBUF = $40 ; Move data to SSPBUF
     WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
     While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave 
     while  glcdBC < glcd_rad
         readcode glcdbm+glcdBC,CTEMP
         SSPBUF = ctemp.LOWBYTE ; Move data to SSPBUF
         WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
         While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave
         SSPBUF = ctemp.highBYTE ; Move data to SSPBUF
         WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
         While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave 
         glcdBC=glcdBC+2  
     wend   
     SSPCON2.2 = 1 ; PEN - send stop bit
     While SSPCON2.2 = 1 : Wend ; Wait for SSP to complete
    return  
    #endif        
           
    SSD_BIG:     ;create a big chr from a small one
       for glcddc = 5 to 0 STEP -1
       ctemp = 0
       ctemp1 = 3
       gL = glcd_buff[glcddc]
       for glcdBc = 0 to 7
           IF  GL & 1 THEN ctemp = ctemp|ctemp1
           ctemp1 = ctemp1<<2
           GL = GL>>1
       NEXT
       gL = glcddc*2
       glcd_buff[GL]   =ctemp.LOWBYTE
       glcd_buff[GL+1] =ctemp.LOWBYTE
       glcd_buff[GL+12]=ctemp.HIGHBYTE
       glcd_buff[GL+13]=ctemp.HIGHBYTE
       NEXT
    RETURN
    
    
    unpack:      ;unpack font from flash
       for glcddc = 0 to 2
           GL = glcddc<<1
           readcode glcdOffset,CTEMP
    #ifdef PIC16
           glcd_buff[gl]  = CTEMP&$7f
           ctemp=ctemp<<1
           glcd_buff[gl+1]= CTEMP.HIGHBYTE
           glcdOffset     = glcdOffset + 1 
    #else 
           glcd_buff[gl]  = CTEMP
           glcd_buff[gl+1]= CTEMP.HIGHBYTE 
           glcdOffset     = glcdOffset + 2 
    #endif 
       next
    return
          
        
    cmd_byte:  'send command sequence "glcdData "
    #ifdef hwi2c
     ;hw i2c
     SSPCON2.0 = 1 ; SEN - Start Condition Enable Bit 
     WHILE SSPCON2.0 = 1 : WEND ; Wait for Start to complete
     SSPBUF = ssd_add ; Move data to SSPBUF
     WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
     While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave 
     SSPBUF = 0 ; Move data to SSPBUF
     WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
     While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave 
     SSPBUF = glcdData ; Move data to SSPBUF
     WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
     While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave 
     SSPCON2.2 = 1 ; PEN - send stop bit
     While SSPCON2.2 = 1: Wend ; Wait for SSP to complete
    #else 
     ;soft i2c
       I2Cwrite SDA,SCL,ssd_add,[0,glcdData]
    #ENDIF
    return 
    
    
    
    
    setxy:    ;set PAGE  WINDOW      
        SSDc $22
        SSDc gy
        SSDc gy_
        SSDc $21
        SSDc gx
        SSDc gx_       
    return         
    
    
    
    
    
    
    overglcd :
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  11. #91
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    113


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Thanks Richard, appreciated.

    I'm at work presently (had the last few days off) and won't be able to try this until the weekend (same with the TFT issue).

    I've taken a browse through the edited code and get the gist of it (and I don't want to 'look a gift horse in the mouth' here) but see there isn't any change regarding the inverse section - do you have any time to look into making a character inverted, or is it not possible and only the entire display can be inverted? Worse case I can alternately set/reset the whole screen blinking to gain attention (alarm) however the viewer then needs to read the entire screen to see what parameter is at fault...

    I'll get back to you with the results of your edits as soon as I can.

    Stay safe,
    Bill

    PS
    Can you see any issues with my setup with the Osc? I don't seem to be able to get full speed no matter what I try.

  12. #92
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    not looked at reversed pixels yet , it is probably no too difficult
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  13. #93
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Can you see any issues with my setup with the Osc? I don't seem to be able to get full speed no matter what I try.
    the osc must be set to 8mhz for pll to function

    my take
    Code:
    #CONFIG ; 16F1705   
        __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF
        __config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCDDIS_ON & _PLLEN_ON & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_OFF
    #ENDCONFIG
    
    
     
    
    
        define  OSC  32              ' Aim for highest clock - slower sees distinct line writes.
        OSCCON  = %01110000         ' Internal 8MHz   x4 PLL =32
    
    
        DEFINE DEBUG_REG PORTC      ' Debug pin port.
        DEFINE DEBUG_BIT 3          ' Debug pin.
        DEFINE DEBUG_BAUD 9600      ' Debug baud rate
        DEFINE DEBUG_MODE 0         ' Debug mode: 0 = True, 1 = Inverted
                     
        ANSELA = 0         ' All Dig.
        ANSELC = 0         ' All Dig.
        TRISC = %110111    ' C.3 debug serial out
       
    
    
        
        
    
    
       
    
    
    
    
    char var byte   
    x    var byte   
    y    var byte    
    BUFF VAR BYTE[32]          ' Max number if using full width, less than gives overwrites.
    AvgT var  word              ' Yes can write byte variables.
    
    
    
    
    
    
    
    
    ;use this define for hw i2c 
    ;#define hwi2c 1 
    #DEFINE PIC16 1 
    ;set and uncomment these to use softi2c
    SCL var PortC.4             ' I2C Clock
    SDA var PortC.5             ' I2C Data
    
    
    ; set these to match display
    ssdheight con 7             ; 7 = 8 PAGES  64*128 ,  3 = 4 pages 32*128
    ssdwidth  con 127           ; 128 PIXELS WIDE
    sdd1306_addr con $78        ;
    latc.3=1    ;debug
    pause 1000  ;debug
    
    
    Include "ssd1306_I2C.INC"   ' bring it in
    include "font7x5_16.bas"
    
    
    debug "I'm Alive...",13,10  ' Heatbeat.
    
    
    
    
    
    
    '==========================    MAIN  Routine    ==============================
    gosub glcd_init
    
    
    BIG_TEXT = 0                        ; Small characters (20 across).  Yellow first line.
        GLCD_CLR                        ; CLS.  ,9,HEX4 glcdOffset
     
    looper:
        ARRAYWRITE BUFF,["Testing this LCD...!",0] ' 
        GLCDSTR  0,1,BUFF               ' Line 1, start at pixel 0.
        ARRAYWRITE BUFF,["bytes ok, words too",0] ' 
        GLCDSTR  0,3,BUFF               ' Line 3.
        ARRAYWRITE BUFF,["RTC sync'd to GPS ok",0] ' 
        GLCDSTR  0,5,BUFF               ' Line 5, start at pixel 0.
        ARRAYWRITE BUFF,["Logging 10hz RAW Yes",0] ' 
        GLCDSTR  0,6,BUFF               ' Line 6.
        ARRAYWRITE BUFF,["AvgT: ",0]    ' 
        GLCDSTR  0,7,BUFF               ' Line 7.
    change:
       for avgt = 6789 to 6889 step 5  ' Word size test 
       
        ARRAYWRITE BUFF,[dec5 AvgT,0]    ' 
        GLCDSTR  36,7,BUFF              ' Line 7.
        pause 500                       ' not too fast.
        debug  DEC avgt ,9
        next                            ' increment.
        goto change                     ' repeat.
    
    
    
    
    GOTO looper
    
    
    END
    Last edited by richard; - 9th February 2022 at 00:23.
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  14. #94


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    richard's right, but I wonder if it might be safer to start off with '__config _PLLEN_OFF' and enable it with OSCCON when you change the freq.

    Reasoning: the PLL is spec'd for an input of 4MHz-8MHz (datasheet table 32-9, parameter F10), and at reset the INTOSC freq defaults to 500KHz (OSCCON.IRCF bits=0111).
    If you use the SPLLEN bit of the OSCCON register, it'll start out off and then setting OSCCON = 11110000 will get you 8MHz + 4x PLL = 32MHz.

    Maybe it doesn't matter, but I wonder what happens when the PLL is enabled and the input freq is 500KHz...

  15. #95
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    but I wonder if it might be safer to start off with '__config _PLLEN_OFF' and enable it with OSCCON when you change the freq.
    i think the data sheet is pretty clear

    Name:  Screenshot 2022-02-10 125454.jpg
Views: 175
Size:  143.2 KB
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  16. #96
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    One thing that's caught me out before (more than once [blush]) is I configured the the main clock switch to the internal osc instead of the primary clock thereby bypassing the PLL module. Not saying it's the case in this instance, but it's probably worth mentioning nonetheless.

    Troy

  17. #97


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Quote Originally Posted by richard View Post
    i think the data sheet is pretty clear
    Which part is pretty clear... the statement "subject to oscillator requirements" and parameter F10 (4-8MHz), or that the config bit enables the PLL?

  18. #98
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Which part is pretty clear...
    the whole thing, the pll can be enabled in config , the pll won't work unless/until the osc is in the correct range


    there are chips where the pll cannot be started with the intosc using the config bit, like the k22 chips

    the 16f1705 does not have that limitation, the pll can take 2mS to settle . if that matters use the pllr flag bit


    18f26k22

    2.6.2 PLL IN HFINTOSC MODES
    The 4x frequency multiplier can be used with the
    internal oscillator block to produce faster device clock
    speeds than are normally possible with the internal
    oscillator. When enabled, the PLL multiplies the
    HFINTOSC by 4 to produce clock rates up to 64 MHz.
    Unlike external clock modes, the PLL can only be
    controlled through software. The PLLEN control bit of
    the OSCTUNE register is used to enable or disable the
    PLL operation when the HFINTOSC is used.
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  19. #99


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    the pll can be enabled in config, the pll won't work unless/until the osc is in the correct range
    So where in the datasheet does it tell you what the PLL does while it's "not working"?

    My point is that while you can enable the PLL in the config, it's "subject to oscillator requirements", which aren't met at poweron using just _FOSC_INTOSC since the INTOSC runs at the default of 500KHz, which is outside the PLL requirements of 4-8MHz.

    It seems to me that using "__config _FOSC_INTOSC" and "__config _PLLEN_ON" both together violate the specs.
    PLLEN_ON would be fine with an ext osc of 4-8MHz, but if you're using the INTOSC I wouldn't enable the PLL until you've changed OSCCON to a valid 4-8MHz setting.

    It just seems safer to me, and since you have to setup OSCCON anyway it's no more steps one way or the other.

  20. #100
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    487


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    In the data sheet, take a quick look at 6.2.2.7 (page 69 in my copy).

    Start with OSCCON.SPLLEN = 0 (PLL disabled), IRCF = %1110 (8 MHz or 32 MHz HF), and SCS either %10 or %11 (1x in data sheet)

    Then do a WHILE and wait for OSCSTAT.HFIOR = 1

    Next change OSCCON.SPLLEN = 1

    Then do a WHILE and wait for OSCSTAT.PLLR = 1

    Then work your magic with the rest of your code.

    Shorter code here doesn't guarantee it works. This absolutely does!

  21. #101
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    i understand what you are saying, however in a single speed system where in the initial 1000ms the osc speed is irrelevant
    why bother. there is nothing to be gained.

    what the PLL does while it's "not working"?
    in this case where intosc was set incorrectly to 16mHz the result was a fosc of 16mhz, not the desired 32 mHz
    hence bills question. i would expect similar results from other incorrect inputs
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  22. #102
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    113


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Hi All,

    Many thanks for your comments and efforts.

    @Richard
    I'm pleased to say your update worked and there is no longer a problem with word vars - put a star against your name mate!

    Re the osc problem I managed to find the elusive setting to achieve 32Mhz, please see the code below.

    @mpgmike
    I couldn't get your suggestions to work, maybe I misinterpreted them?

    Code:
    #CONFIG ; 16F1705
        __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF
    ;    __config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCDDIS_ON & _PLLEN_ON & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_OFF	   
        __config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCDDIS_ON & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_OFF	   
    #ENDCONFIG
    
    @ ERRORLEVEL -306   ; turn off 'crossing page boundary' message
     
    ; --- *** Oscillator  *** ---------------------------------------------------
    '    DEFINE  OSC  4              ' Adjust to suit design.
    '    define  OSC  8
    '    define  OSC  16
        define  OSC  32              ' Aim for highest clock - slower sees distinct line writes.
    '---------------------------------------------------------------------------------------------------------------------
    ; See: http://www.picbasic.co.uk/forum/showthread.php?t=23758&page=3	#100   ### compile errors!
    '	OSCCON.SPLLEN = 0	' (PLL disabled)
    '	IRCF = %11100000	' (8 MHz or 32 MHz HF)
    '	SCS = %00000010		' or %00000011 (1x in data sheet)
    
    '	WHILE OSCSTAT.HFIOR = 1
    '	wend
    
    '	OSCCON.SPLLEN = 1	' (PLL enabled)
    
    '	WHILE OSCSTAT.PLLR = 1
    '	wend
    '---------------------------------------------------------------------------------------------------------------------
    
    ; Tried lots of combinations but only uncommented line achieves 32Mhz (proven with debug out) noting config setting
    ; PLLEN_ON or OFF made no difference.
    
    '    OSCCON  = %01101011         ' Internal 4MHz osc.
    '    OSCCON  = %01110011         ' Internal 8MHz osc.
    '    OSCCON  = %01111011         ' Internal 16MHz osc.
    '   OSCCON  = %11111010         ' Internal 32MHz osc PLL.  9600 is 4800 (1/2)
    '   OSCCON  = %11110010         ' Internal 32MHz osc PLL.  9600 is 2400 (1/4)
       OSCCON  = %11110000         ' Internal 32MHz osc PLL.  9600 is 9600 (1/1) ### This one!
    '    OSCCON  = %1111100         ' Internal 32MHz osc PLL. 9600 is 4800 (1/2)
    
        DEFINE DEBUG_REG PORTC      ' Debug pin port.
        DEFINE DEBUG_BIT 3          ' Debug pin.
        DEFINE DEBUG_BAUD 9600      ' Debug baud rate
        DEFINE DEBUG_MODE 0         ' Debug mode: 0 = True, 1 = Inverted
    '    DEFINE DEBUG_PACING 1000    ' Debug character pacing in us
    '    DEFINE DEBUGIN_BIT 4        ' Input pin.
    Kind regards,
    Bill

  23. #103
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    re osc

    OSCCON = %11110000 ' Internal 32MHz osc PLL. 9600 is 9600 (1/1) ### This one!

    i see you never tried

    OSCCON = %01110000 ' Internal 32MHz osc PLL. , which i have tried and tested
    which will never delude you into thinking that the pll is under software control when _PLLEN_ON is asserted in the config word


    I'm pleased to say your update worked and there is no longer a problem with word vars
    there was never a problem with word vars , the issue was that
    the combination of
    BUFF VAR BYTE[23]
    and
    AvgT var word

    conspires to push the glcdFont var out of bank0

    where the dt-ints inspired MACRO failed to set the correct BANK
    [i do notice that dt declared the var he used as BANK0]

    GLetAddress macro Label, Wout
    CHK?RP Wout
    movlw low Label ; get low byte
    movwf Wout
    movlw High Label ; get high byte
    movwf Wout + 1
    BANKSEL 0
    endm


    THIS fixed the problem. I assumed wrongly that CHK?RP Wout would set the bank if the var was not in bank0


    GLetAddress macro Label, Wout
    BANKSEL Wout
    movlw low Label ; get low byte
    movwf Wout
    movlw High Label ; get high byte
    movwf Wout + 1
    BANKSEL 0
    endm
    Last edited by richard; - 11th February 2022 at 01:47.
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  24. #104
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    @mpgmike
    I couldn't get your suggestions to work, maybe I misinterpreted them?

    They were never going to work like that


    the other method done simply
    Code:
    
    #CONFIG ; 16F1705
        __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF
        __config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCDDIS_ON & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_OFF	   
    ;    __config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCDDIS_ON & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LPBOR_OFF & _LVP_OFF	   
    #ENDCONFIG
    
    
     
    
    
        define  OSC  32              ' Aim for highest clock - slower sees distinct line writes.
        OSCCON  = %01110000         ' Internal 8MHz  
    
    
        DEFINE DEBUG_REG PORTC      ' Debug pin port.
        DEFINE DEBUG_BIT 3          ' Debug pin.
        DEFINE DEBUG_BAUD 9600      ' Debug baud rate
        DEFINE DEBUG_MODE 0         ' Debug mode: 0 = True, 1 = Inverted
                     
        ANSELA = 0         ' All Dig.
        ANSELC = 0         ' All Dig.
        TRISC = %110111    ' C.3 debug serial out
       
    
    
        
        
    
    
       
    
    
    
    
    char var byte   
    x    var byte   
    y    var byte    
    BUFF VAR BYTE[32]          ' Max number if using full width, less than gives overwrites.
    AvgT var  word              ' Yes can write byte variables.
    
    
    
    
    
    
    
    
    ;use this define for hw i2c 
    ;#define hwi2c 1 
    #DEFINE PIC16 1 
    ;set and uncomment these to use softi2c
    SCL var PortC.4             ' I2C Clock
    SDA var PortC.5             ' I2C Data
    
    
    ; set these to match display
    ssdheight con 7             ; 7 = 8 PAGES  64*128 ,  3 = 4 pages 32*128
    ssdwidth  con 127           ; 128 PIXELS WIDE
    sdd1306_addr con $78        ;
    
    
    WHILE OSCSTAT.4 = 0 :wend ; WAIT TILL INTOSC IS READY
    OSCCON.7 = 1	                    ; SET PLL ON
    WHILE OSCSTAT.6 = 0 :wend  ;WAIT TILL PLL READY
    
    
    
    
    
    
    latc.3=1    ;debug
    pause 1000  ;debug
    
    
    Include "ssd1306_I2C.INC"   ' bring it in
    include "font7x5_16.bas"
    
    
    debug "I'm Alive...",13,10  ' Heatbeat.
    
    
    
    
    
    
    '==========================    MAIN  Routine    ==============================
    gosub glcd_init
    
    
    BIG_TEXT = 0                        ; Small characters (20 across).  Yellow first line.
        GLCD_CLR                        ; CLS.  ,9,HEX4 glcdOffset
     
    looper:
        ARRAYWRITE BUFF,["Testing this LCD...!",0] ' 
        GLCDSTR  0,1,BUFF               ' Line 1, start at pixel 0.
        ARRAYWRITE BUFF,["bytes ok, words NBG!",0] ' 
        GLCDSTR  0,3,BUFF               ' Line 3.
        ARRAYWRITE BUFF,["RTC sync'd to GPS ok",0] ' 
        GLCDSTR  0,5,BUFF               ' Line 5, start at pixel 0.
        ARRAYWRITE BUFF,["Logging 10hz RAW Yes",0] ' 
        GLCDSTR  0,6,BUFF               ' Line 6.
        ARRAYWRITE BUFF,["AvgT: ",0]    ' 
        GLCDSTR  0,7,BUFF               ' Line 7.
    change:
       for avgt = 6789 to 6889 step 5  ' Word size test - hangs the display.
       
        ARRAYWRITE BUFF,[dec5 AvgT,0]    ' 
        GLCDSTR  36,7,BUFF              ' Line 7.
        pause 500                       ' not too fast.
        debug  DEC avgt ,9
        next                            ' increment.
        goto change                     ' repeat.
    
    
    
    
    GOTO looper
    
    
    END
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  25. #105
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,414


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    @Richard
    I'm pleased to say your update worked and there is no longer a problem with word vars - put a star against your name mate!
    Enlighten me please, displaying word vars obviously worked for me. Was there then a change that broke it which has now been fixed or what actually happened here.

    Anyway, glad you got it going and another thank you to Richard for this piece of code!

  26. #106
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Enlighten me please, displaying word vars obviously worked for me. Was there then a change that broke it which has now been fixed or what actually happened here.
    i think the issue was brought to light by bills increase of BUFF[] from 16 to 23 bytes , pbp keeps buff in bank0 and displaces other vars
    to keep it there the glcdFont var did not appreciate the move.

    i use this macro GetAddress in the initialise routine, its copied from dt-ints

    just renamed to stop any conflict if dt-ints used

    glcd_init:
    #ifdef hwi2c
    SSPSTAT = 0 'High Speed Filter
    SSPADD = $26'400 kHz @32 MHz
    SSPCON1 = %00101000 'I2C Master Mode Enable
    SSPCON3 = 0

    #endif
    @ GLetAddress _font7x5,_glcdFont


    its used to get the font address. the glcdFont var was pushed out of bank0 in bills code.
    i had and always assumed the CHK?RP MACRO set the correct bank for a var
    in this case it did not. i had made no effort to place the var anywhere in particular
    thinking i had this covered. looking at dt's code i see now that he uses a bank0 modifier
    for his address var. anyway a simple fix is to ensure correct bank selected in the macro
    incidentally glcdFont var word bank0 'font address
    failed to keep var in bank0 in all cases
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  27. #107
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    113


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Hi All,

    Some good learning stuff amongst this lot, you are an asset to this forum Richard. I can't help but wonder what breakthroughs and innovations would surface if DT was still with us and bouncing ideas between yourselves...

    @Richard
    Back in post #92 you wrote "not looked at reversed pixels yet , it is probably no too difficult" - are there any plans to do this? It would be the cherry atop the cake.

    FYI I've moved across to an 18F26k20 for my logger - what a great chip! - so the osc issue I had with the 16f1705 (now fixed, thank you) no longer applies.

    Regards to the community, stay safe,
    Bill

  28. #108
    Join Date
    Feb 2013
    Posts
    860


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    There are several updates posted, so which ones are final?
    I'd like to test this on PIC16F886 @ 8mhz intosc, if possible.

  29. #109
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    post #90 for the include

    '************************************************* ***************'
    * Name : ssd1306_I2C.INC *
    '* Author : richard *
    '* Notice : *
    '* : *
    '* Date : 8/2/2022 *
    '* Version : 1.2 *
    '* Notes : font address banksel fixed *
    '* :FOR pic 16/18 SSD1306 *
    '************************************************* ***************
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  30. #110
    Join Date
    Apr 2022
    Posts
    6


    Did you find this post helpful? Yes | No

    Default SSD1306 INCLUDE for PBP3.... Bigger Fonts?

    Hello Richard,

    Its my first time joining here. Firstly i would like to thank you for your work on the Ssd 1306 include files and code. I have tried them and they work.

    I have a question is there a way of making the Big Fonts bigger than the SSD_BIG?

    I apologies if this is the wrong way to contact you for my questions.

    Kind Regards,
    Tony

  31. #111
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    I have a question is there a way of making the Big Fonts bigger than the SSD_BIG?
    not easily its a skimpy minimalist thing for pic16's, bitmaps are possible

    if you use a pic18 {with enough resources} i have a fancier method

    u can make your own font up to quite large [from memory 23x16 is possible]
    with a reasonable graphics suite also

    see here

    http://www.picbasic.co.uk/forum/showthread.php?t=24218
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  32. #112
    Join Date
    Apr 2022
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Hello Richard,

    Thank you for your reply, gees you are quick, did not realize you will answer that soon, I appreciate your quick response.

    I will have a look at those files and thanks for sharing.

    I am using a pic16F1847 and for some reason the on board i2s is not working with the code of the #define hwi2c, I have noticed that in the ssd_data sub routine the SSPCON some parts are as SSP1CON2 and some SSPCON and same with the SSPSTAT, some is SSP1STAT. I never used these systems before so I am still trying to work out how you made this work.
    On the data sheet for the pic1847 the register is not SSPCON on its own but SSPxCON1 and SSPxCON2. I am assuming because the pic16F1847 has two I2C systems. So the x is for 1 or 2 assuming! Anyway having said all that, your 12cwrite command works fine with the ssd1306 64X128 screen, but with a 32X128 it does not work at all with both codes (#define hwi2c and i2swrite). I tested the screen with a totally different code and the screen does work fine so its not the screen.

    I am not going to ask you to help with this because I know you have spent allot of time on it many years ago already. But if you ever come across to know what it might be....please let me know.

    A bit about myself: I am not an expert on picbasic pro but I have used it for many years. I am only a self thought programmer and just never realized it has so much hidden features like the private commands you can make...which I still don't fully understand. The first time I saw these is from Darrel Taylor, I think this man was a genius. It was very sad to hear he passed away.
    I have made many programs with picbasic pro and if you like "DC loads'' I have made one for that, it took me probably 6months bit by bit to make the software work fine. I am sure more advanced programmers like you, can improve it to make the code smaller like your include files commands. As you know already the problem with pics their program memory is not great. I would have added some extra features but ran out of code space. If you are building a DC load one day and interested in my code let me know, I can share it.

    Thanks again.

  33. #113
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,237


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Hi Tony.

    About the load, I am indeed in the designing one, so if you are willing to share the project, I'd appreciate it a lot.

    Ioannis

  34. #114
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    For chips with multiple mssp modules microchip define sspcon and ssp1con to be equal , ditto for the rest of the mssp regs.
    If you have only one mssp then ssp1con etc are not defined .you can always refer to the device Inc file
    to Side step this issue I had a conditional define to allow for a standard include file regardless of the number of modules, I seldom use these displays so it may no still be effective
    It's 4 or 5 times faster to use hw i2c over the bitbanged i2c
    Warning I'm not a teacher , prose like a gushing embroilment is not my style

  35. #115
    Join Date
    Apr 2022
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    I noticed you have a newer ssd1306 the one I have is ver1.0.. I see there is a v1.2
    Thanks for your reply.

  36. #116
    Join Date
    Apr 2022
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Quote Originally Posted by Ioannis View Post
    Hi Tony.

    About the load, I am indeed in the designing one, so if you are willing to share the project, I'd appreciate it a lot.

    Ioannis
    Hi Ioaness,

    When you say project , do you mean just the programming code or circuit diagrams as well? As it is a very big project.
    The main code its self is very complex, as it even confuses me even though its my own, it took me months and months to do the software and when i leave it for a few weeks or months I spend the first hour trying to figure out what I did, even though I put many text comments.

    I dont have experience with forums, so not sure how I should go about this,may be you or anybody here can advise.

  37. #117
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,237


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    If you want to share a big file, then there are few methods: either share your Dropbox, OneDrive or Google Drive for that specific file. Or load it to WeTransfer (free for a week) or other file sharing services.

    Ioannis

  38. #118
    Join Date
    Apr 2022
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Hi Ioannis,


    Tried uploading the files with attachments but after uploading nothing is in the system.
    any ideas?

  39. #119
    Join Date
    Apr 2022
    Posts
    6


    Did you find this post helpful? Yes | No

    Default DC Load

    Tried just one file and it says error: file invalid
    I don't use anything google drives or the one you mentioned.

  40. #120
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,237


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    The system has a limit in the size and type of files.

    Valid file extensions are: bas, bmp, doc, gif, jpe, jpeg, jpg, pdf, png, psd, txt and zip files.

    The size is not known to me but I guess less than 2MB. After that the system fails to upload the file with no message.

    Ioannis

Similar Threads

  1. SSD1306 Include example
    By timc in forum Code Examples
    Replies: 11
    Last Post: - 28th November 2017, 08:53
  2. SSD1306 start display problem
    By harryweb in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th December 2016, 19:16
  3. Using INCLUDE to add a text file in PBP3
    By Sumobob in forum PBP3
    Replies: 4
    Last Post: - 16th May 2016, 18:56
  4. PBP3 to include 18F97J94?
    By fowardbias in forum PBP3
    Replies: 1
    Last Post: - 18th December 2013, 16:42
  5. Help With OLED Display / 128X64 SSD1306
    By Denner in forum General
    Replies: 6
    Last Post: - 25th May 2013, 15:40

Posting Permissions

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