Graphical Displays with PBP3


+ Reply to Thread
Results 1 to 40 of 115

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    in theory portrait mode should be easier and faster than what i have now, the screen width 64 height 128
    and the buffer sent to the screen in horiz fill mode nice and sequentially [ might need bit reversal, could be upside down or mirrored]
    i will have a look one day time permitting
    Warning I'm not a teacher

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    a portrait version

    Name:  shawn.jpg
Views: 42917
Size:  41.3 KB

    Code:
     
    '*******************************************************************
    '*  Name    : SSD1306p.pbpmod                                          *
    '*  Author  : richard                                                 *
    '*  Notice  : Copyright (c) 2021                                      *
    '*          :                                                         *
    '*  Date    : 28/12/2023                                              *
    '*  Version : 1.1                                                     *
    '*  Notes   : generic GRX graphics DRIVER FOR SSD1306                 *
    '*          :  HW I2C PIC18 ONLY                                      *
    '*          :  40x72 disp added                                       * 
    '*          :    portrait version                                                     * 
    '*          :                                                         *
    '*          :                                                         *
    '********************************************************************** 
           ;set these  to match display IN MAIN
    '    ssd1306_addr con $78 
    '    #DEFINE colours 1   ;1 mono 2 rg or 3 rgb
    '    width  con 128      
    '    height con 32 
    '    h_offset con 0   ;28 for 40x72
    
    
           
        glrot       var byte[8]
        glrb        var byte[8]
        gltmp       var byte[3] 
        glcd_rad    var WORD
        glcdData    VAR byte  'DATA
        glcdBC      VAR BYTE  'gca  var
        page        VAR WORD  'gca  var
        gy          var byte  'gca  pg   address
        gy_         var byte  'gca  pg   address
        gx          var byte  'gca  row  address
        gx_         var byte  'gca  row  address
        ssd_add     var byte
        USERCOMMAND "SENDBYTE"     ;BYTE
        USERCOMMAND "SSDC"      ;cmd BYTE TO SSD1306
        ssdheight con WIDTH/8-1      ; 7 = 8 PAGES  64*128 ,  3 = 4 pages 32*128
        ssdwidth  con HEIGHT-1    ; 128 PIXELS WIDE   
      
    goto overssd  
    ASM
    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    
    SENDBYTE?B  macro Dat 
        MOVE?BB    Dat ,_glcdData
        L?CALL _send_byte 
        endm 
    SENDBYTE?W  macro Dat 
        MOVE?WB    Dat ,_glcdData
        L?CALL _send_byte 
        endm      
    SENDBYTE?C  macro Dat 
        MOVE?CB    Dat ,_glcdData
        L?CALL _send_byte 
        endm  
     ENDASM
    glcd_init:
        bgcolour = 0
        colour  = 1
        SSPSTAT = 0 'High Speed Filter
        SSPADD = $14'400 kHz @64 MHz  ?
        SSPCON1 = 101000 'I2C Master Mode Enable
        SSPCON3 = 0
        ssd_add = ssd1306_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 > 4  then
            SSDc $40   ' Set display start line 0 
        elseif ssdheight > 3  then
            SSDc $68   ' Set display start line 
        else
            SSDc $60   ' Set display start line 4 
        endif 
        SSDc $8D : SSDc $14 ' Set Charge Pump Internal
        SSDc $20 : SSDc $01 ' Adressing mode Horizontal
        SSDc $A1   ' set segment remap column 127 as start
        SSDc $C0   ' 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
    show:
    '    gosub flip
        SSDc $22
        SSDc  0       
        SSDc  ssdheight 
        SSDc $21     
        SSDc  h_offset     
        SSDc  ssdwidth + h_offset
        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 SSP1STAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
        While SSP1CON2.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 
        for glcd_rad = 0 to  width/8 * height -1
            SENDBYTE fbr[glcd_rad ]
        next 
        SSPCON2.2 = 1 
    '    gosub flip    
    return
    send_byte :  'DATA
        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 
    return 
    cmd_byte:  'send command sequence "glcdData "
        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 SSP1CON2.2 = 1 : Wend ; Wait for SSP to complete
    return  
     overssd:

    with demo


    Code:
    'PIC18F26K22#CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  PLLCFG = ON
      CONFIG  PRICLKEN = ON
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = ON
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5                                
      CONFIG  T3CMX = PORTC0
      CONFIG  HFOFST = ON
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG       
    DEFINE OSC 64
        clear
        ssd1306_addr con $78 
        #DEFINE colours 1   ;1 mono 2 rg or 3 rgb
        width  con 64      
        height con 128      
        h_offset con 0
        DEFINE DEBUG_REG PORTB
        DEFINE DEBUG_BIT 7
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0
        LATB.7=1
        trisb.7=0
        include "grx.pbpMOD" 
        include "SSD1306p.pbpMOD"
        include "font.bas" 
        BUFF     VAR BYTE[32]
        ANSELB=0
        ANSELC=0
        ANSELA=0
        OSCCON=$70
        OSCTUNE.6=1
        SETFONT FONT5x7
        gosub glcd_init
       
    main:    
       gosub grf_clr
        gosub show 
        ARRAYWRITE BUFF,["GLCD",0]
        DMDSTR 3,75,buff,1
        DMDBMP 0,0,TestIcon
        gosub show 
        pause 5000
          
    goto main 
     
    end
    
    
    TestIcon:
    @ db 0x10,0x10 ;16x16
    @ db 0xFF,0xFF;
    @ db 0xC0,0x03;
    @ db 0xA0,0x05;
    @ db 0x90,0x09;
    @ db 0x88,0x11;
    @ db 0x84,0x21;
    @ db 0x82,0x41;
    @ db 0x81,0x81;
    @ db 0x81,0x81;
    @ db 0x82,0x41;
    @ db 0x84,0x21;
    @ db 0x88,0x11;
    @ db 0x90,0x09;
    @ db 0xA0,0x05;
    @ db 0xC0,0x03;
    @ db 0xFF,0xFF;
    Warning I'm not a teacher

  3. #3
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    Excellent work Richard!!!

    This will work well for my use, but with a little more tweaking it would be nice to have a define to set 1 of 4 different viewing directions to make a more universal driver.
    Shawn

  4. #4
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    169


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    Hi Richard,
    I've been using your display drivers with 12864 ST7920 LCDs and one thing that's annoying (for me) is randomly on startup I'll be getting 3 large(ish) zeros in the top left corner of the display. If they appear, there's no getting rid of them without cutting power to the display. Any idea what I'm missing here? I can still write stuff to the display, but the zeros will remain there irrespective of screen clearing. Even filling the screen with a filled (black) rectangle - the zeros are still there but just colour inverted.
    You can see if they're going to appear with the initialisation call to st7920_init as the areas around there is more populated with random dots than neighbouring areas. Sometimes it's clear enough to make them out before calling a screen clear and show.

    Could this be a timing problem on my initialisation? It's happened on various displays (same model) and various completely different programs.

    Troy
    Last edited by rocket_troy; - 8th October 2024 at 01:58.

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


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    Could this be a timing problem on my initialisation?
    most likely, the displays have two screen memory regions one for graphics the other for the normal lcd character display
    at power up display is in lcd mode, the init routine sets it to graphics, lcds are slow to powerup they cannot be hurried.
    if the display is written to before graphics mode is established then its possible some lcd chrs will be displayed accidently.
    lcd chrs can only be cleared if the display is in lcd mode , graphic pixels can only be set in graphics mode
    both memories are visible on screen no matter what mode is set.
    Warning I'm not a teacher

  6. #6
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    169


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    Quote Originally Posted by richard View Post
    most likely, the displays have two screen memory regions one for graphics the other for the normal lcd character display
    at power up display is in lcd mode, the init routine sets it to graphics, lcds are slow to powerup they cannot be hurried.
    if the display is written to before graphics mode is established then its possible some lcd chrs will be displayed accidently.
    lcd chrs can only be cleared if the display is in lcd mode , graphic pixels can only be set in graphics mode
    both memories are visible on screen no matter what mode is set.
    Yeah, what you've said does make sense. I've played around with all sorts of timings - like up to 10s pause after calling the st7920_init and 2s prior, but I don't think it's my writing to the display that's causing the issue as the signs are already there when I call st7920_init.

    So, are you aware of any commands I can call to initialise the "character" memory before calling st7920_init?

    Thanks,

    Troy

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


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    as in my demo
    Code:
        Pause  1500      ' LCD initialize time
        lcdout $FE,1
        gosub st7920_init    'graphic mode
    Warning I'm not a teacher

Similar Threads

  1. Replies: 3
    Last Post: - 1st January 2021, 21:28
  2. problem using Graphical LCD
    By Mostafa in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th July 2007, 18:15
  3. Graphical LCDs
    By T.Jackson in forum General
    Replies: 5
    Last Post: - 14th May 2007, 06:29
  4. Vb 6.0 Graphical plug in
    By rocky79 in forum Serial
    Replies: 0
    Last Post: - 8th March 2006, 18:42
  5. Graphical user interface
    By rocky79 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th October 2005, 12:25

Members who have read this thread : 26

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