SSD1306 INCLUDE for PBP3


Closed Thread
Results 1 to 40 of 102

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    So, the final test was done on a 18F4550 chip, with a 64x128 oled LCD, soft I2C and files sd1306_demo.pbp, font7x5_18.bas and latest ssd1306_I2C.inc from post #41.
    sorry I'm lost, i need to restore some old backup files to get back to speed with this.
    i forgot i did actually make a 16/18 version, i have not used that pbp code for quite sometime and my laptop that
    held all that code died bigtime. i only use the grx.pbpmod ver or C ver these days, so i'm a bit rusty on the old pbp stuff.

    the old code should work with a 18F4550 and the pic18 font posted with hw or soft i2c, the new font format previously discussed will not work with this code
    as it stands. i do have a 18F4550 proto board so i could check it out. post the whole lot, includes too i have lost most of the originals and am not absolutely sure we have the same thing.
    i would just the new code.
    Warning I'm not a teacher

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    OK. Later I will do that. But all what I described is from this thread starting from post #1 and on.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Quote Originally Posted by Ioannis View Post
    OK. Later I will do that. But all what I described is from this thread starting from post #1 and on.

    Ioannis
    i know but some errors crept in and some posted files are not right and i cannot fix them nor remember which ones they are
    its best to be dealing from the same deck
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Yes you are right. Will post that later today.

    Ioannis

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Merry Xmas to all.

    here are the files I used to test the SSD1306 lcd.

    Ioannis
    Attached Files Attached Files

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    Just tested the new include you post and works with soft I2C as expected. But not on hardware I2C...

    My code with new include:

    Code:
    #CONFIG
        CONFIG  PLLDIV = 1            ; Divide by 5 (20 MHz oscillator input)
        CONFIG  CPUDIV = OSC1_PLL2    ; [Primary Oscillator Src: /1][96 MHz PLL Src: /2]
        CONFIG  USBDIV = 2            ; USB clock source comes from the 96 MHz PLL divided by 2
        CONFIG  FOSC = ECPLLIO_EC     ; HSPLL_HS       ; HS oscillator, PLL enabled (HSPLL)
        CONFIG  FCMEN = OFF           ; Fail-Safe Clock Monitor disabled
        CONFIG  IESO = OFF            ; Oscillator Switchover mode disabled
        CONFIG  PWRT = OFF            ; PWRT disabled
        CONFIG  BOR = ON              ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
        CONFIG  BORV = 3              ; Minimum setting
        CONFIG  VREGEN = ON           ; USB voltage regulator enabled
        CONFIG  WDT = ON              ; WDT enabled
        CONFIG  WDTPS = 512           ; 1:512
        CONFIG  CCP2MX = ON           ; CCP2 input/output is multiplexed with RC1
        CONFIG  PBADEN = OFF          ; PORTB<4:0> pins are configured as digital I/O on Reset
        CONFIG  LPT1OSC = OFF         ; Timer1 configured for higher power operation
        CONFIG  MCLRE = ON            ; MCLR pin enabled; RE3 input pin disabled
        CONFIG  STVREN = ON           ; Stack full/underflow will cause Reset
        CONFIG  LVP = OFF             ; Single-Supply ICSP disabled
        CONFIG  ICPRT = OFF           ; ICPORT disabled
        CONFIG  XINST = OFF           ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        CONFIG  DEBUG = OFF           ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
        CONFIG  CP0 = OFF             ; Block 0 (000800-001FFFh) is not code-protected
        CONFIG  CP1 = OFF             ; Block 1 (002000-003FFFh) is not code-protected
        CONFIG  CP2 = OFF             ; Block 2 (004000-005FFFh) is not code-protected
        CONFIG  CP3 = OFF             ; Block 3 (006000-007FFFh) is not code-protected
        CONFIG  CPB = OFF             ; Boot block (000000-0007FFh) is not code-protected
        CONFIG  CPD = OFF             ; Data EEPROM is not code-protected
        CONFIG  WRT0 = OFF            ; Block 0 (000800-001FFFh) is not write-protected
        CONFIG  WRT1 = OFF            ; Block 1 (002000-003FFFh) is not write-protected
        CONFIG  WRT2 = OFF            ; Block 2 (004000-005FFFh) is not write-protected
        CONFIG  WRT3 = OFF            ; Block 3 (006000-007FFFh) is not write-protected
        CONFIG  WRTC = OFF            ; Configuration registers (300000-3000FFh) are not write-protected
        CONFIG  WRTB = OFF            ; Boot block (000000-0007FFh) is not write-protected
        CONFIG  WRTD = OFF            ; Data EEPROM is not write-protected
        CONFIG  EBTR0 = OFF           ; Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
        CONFIG  EBTR1 = OFF           ; Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
        CONFIG  EBTR2 = OFF           ; Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
        CONFIG  EBTR3 = OFF           ; Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks
        CONFIG  EBTRB = OFF           ; Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
    #ENDCONFIG
    
    
    DEFINE OSC 48          
        
    LATA = %00000000
    LATB = %00000000
    LATC = %00000000 
    LATD = %00000000
    LATE = %00000000
    
    TRISA = %00100001
    TRISB = %00010000
    TRISC = %00000000
    TRISD = %00000000
    TRISE = %00000000
    
    ;*********************************************************************
    ;           ADC Settings
    ;*********************************************************************
    ADCON0=%00000001
    ADCON1=%00001110
    ADCON2=%10100111
    cmcon=0
    
    ;*********************************************************************
    
     ' Set LCD Data port
    DEFINE LCD_DREG PORTD
    ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_DBIT 4
    ' Set LCD Register Select port
    DEFINE LCD_RSREG PORTD
    ' Set LCD Register Select bit
    DEFINE LCD_RSBIT 0
    ' Set LCD Enable port
    DEFINE LCD_EREG PORTD
    ' Set LCD Enable bit
    DEFINE LCD_EBIT 1
    ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_BITS 4
    ' Set number of lines on LCD
    DEFINE LCD_LINES 2
    ' Set command delay time in us
    'DEFINE LCD_COMMANDUS 1500
    ' Set data delay time in us
    'DEFINE LCD_DATAUS 50
    
    DEFINE ADC_BITS 10 ' Set number of bits in result
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
    DEFINE ADC_CLOCK 3
    
    pause 100
    t1con=0
    
    char var byte
    x    var byte  
    y    var byte    
    BUFF VAR BYTE[16]
    
    ;use this define for hw i2c 
    #define hwi2c 1 
    
    ;set and uncomment these to use softi2c
    SCL var Portb.1      ' I2C Clock
    SDA var Portb.0      ' 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_16_18.INC"  ' bring it in
    include "font7x5_18.bas"
    '==========================    MAIN  Routine    ==============================
    
    
    gosub glcd_init
    BIG_TEXT = 0
    
    
    looper:
        GLCD_CLR
        GLCDDHL 0,0,75,1       ;x,y,len,patten
        GLCDDHL 0,2,75,128
        GLCDDVL 0,0,3           ;x,y,height [in pages]
        GLCDDVL 75,0,3
        GLCDSTR  5,1,"--SSD1306--"   ;x,y, cont string
        ARRAYWRITE BUFF,["JBCDEF",0]
        CHAR="!"
        GLCDC 100,2,CHAR             ;x,y , chr
        BIG_TEXT = 1
        if ssdheight > 3  then
            GLCDSTR  2,4,BUFF
            ARRAYWRITE BUFF,["@12456-=#",0]
            BIG_TEXT = 0
            GLCDSTR  2,7,BUFF          ;x,y ,str buffer [null terminated]
        else
            pause 1000
            GLCD_CLR
            GLCDSTR  2,0,BUFF
            ARRAYWRITE BUFF,["@12456-=#",0]
            BIG_TEXT = 0
            GLCDSTR  2,3,BUFF
        endif
        PAUSE 3000
    GOTO looper
    Ioannis
    Last edited by Ioannis; - 25th December 2021 at 21:10.

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


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    it works for me with
    TRISB = % 00010011

    most pic modules that switch pin directions like to control tris themselves, the data sheet for this chip is totally not clear
    at all re i2c tris requirements
    Warning I'm not a teacher

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 INCLUDE for PBP3

    i see the prob

    4550 has only 1 mssp try this

    Code:
    '****************************************************************'*  Name    : ssd1306_I2C.INC                                   *
    '*  Author  : richard                                           *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    : 7/5/2018                                          *
    '*  Version : 1.1                                               *
    '*  Notes   : const str added for pic16                         *
    '*          :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
        CHK?RP Wout
        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 = $13'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

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

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