Graphical Displays with PBP3


+ Reply to Thread
Results 1 to 40 of 108

Hybrid View

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

    Default Graphical Displays with PBP3

    i wrote this graphics lib to handle led dmd's [1/4 scan dot matrix displays] in mono, red/green or rgb in varing sizes up to 128x32 pixels.
    it occured to me that with a little more effort it would make a general purpose graphic lib for nearly any display. so here it is.
    it uses mikroe fonts that you can easily generate. the variable width fonts can be up to 23 bits wide if you like.

    a driver for ssd1306, nokia and the ubiquitious 128x64 glcd are included with a small demo for each.
    note this is pic18 pbp3 only and if a mssp port is warranted then its used. there are more functions in the lib than the USERCMDS
    indicate, i never use them all. i could not be bothered making the usecmd code for everything
    i might publish the led dmd stuff at sometime when i work out dma->spi transfers with a k42


    and some fonts


    and some demos
    Attached Files Attached Files
    Warning I'm not a teacher

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    956


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    You've done an excellent job. Would you consider posting a small video demo to visualize the results?

    Warm wishes

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


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    i dropped my camera and its not too happy, the phone makes ridiculous high res movies too big to use online
    so how about a sim still shot
    Name:  glcd.jpg
Views: 3448
Size:  159.7 KB

    Name:  n7110.png
Views: 3327
Size:  34.3 KB

    nokia 7110 too
    Attached Files Attached Files
    Last edited by richard; - 20th March 2021 at 12:52.
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    That is awesome!

    Thanks for sharing,
    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    Fantastic work again Richard!

    Would you have any particular recommendations for a display to purchase for a newbie just as a play-around learning tool ?

    Regards,

    Troy

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


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    if you don't mind waiting a few weeks the nokia 5110 from china is <$5 . the 7110 have a weird connector and are best avoided imo ,both are good size
    not too many pins needed, 3-5v ok.
    the ssd1306 are about $8 locally but they are pretty small need only two pins if you get i2c variant, 3-5v ok.
    if you catch a special at https://www.rockby.com.au/Index2012.cfm the 128x64 glcd can be real cheap < $5 but need heaps of pins to drive them 5v only.
    they all work .
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    Driver for st7920 display for my system

    notes
    you need to change in/out of graphics mode to use lcdout commands on the display if you have the need, i don't

    it doesn't need the r/w pin when used with frame buffering but i did not test it
    Attached Files Attached Files
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    serial i/f and busy flag check added for st7920


    Code:
    '****************************************************************'*  Name    : ST7920-LCD_DEMO.PBP                               *
    '*  Author  : RICHARD                                           *
    '                                                               *
    '*  Date    : 4/8/2017                                          *
    '*  Version : 1.0                                               *
    '*  Notes   : pic18f26k22                                       *
    '*          :  ST7920-LCD 128X64                                *
    '****************************************************************
    #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 = OFF
      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
    
    
       
        #DEFINE colours 1   ;1 mono 2 rg or 3 rgb
        width  con 128      ;
        height con 64      ;
        'use serial i/f
        #define  stserial 1
        include "grx.pbpMOD" 
        include "st7920.pbpmod" 
        include "font.bas"
        include "bignum.bas"       
        include "bigchr.bas"
        BUFF       VAR BYTE[32]
        ani_h var word  bank0
        ani_r var byte
        ani_c var byte
        OSCCON=$70
        OSCTUNE.6=1
        while ! osccon2.7 :WEND    ;wait for pll
        ANSELB=0
        ANSELC=0
        ANSELA=0 
        
        trisc = %11010101 ;cs,sck,sdo are output
    
    
    
    
        gosub st7920_init    'graphic mode
        SETFONT FONT5x7
        gosub grf_clr
        
        
        ani_r=%10101011
        ARRAYWRITE BUFF,[bin8 ani_r ,0]
        DMDSTR 3,4,buff,1
        for ani_c=0 to 7
        ani_h=ani_h<<2
        if  ani_r.7 then ani_h=ani_h+3
        ani_r=ani_r<<1
        next
        ARRAYWRITE BUFF,[bin16 ani_h ,0]
        DMDSTR 3,12,buff,1   
        
        
    
    
        ani_r=%10101011
        ARRAYWRITE BUFF,[bin8 ani_r ,0]
        DMDSTR 3,20,buff,1
    
    
    X VAR WORD
    
    
    
    
    x = ani_r;
    x = (x ^ (x << 4)) & $0f0f;
    x = (x ^ (x << 2)) & $3333;
    x = (x ^ (x << 1)) & $5555;
    ani_h = x | (x << 1);
    
    
    
    
    ARRAYWRITE BUFF,[bin16 ani_h ,0]
    DMDSTR 3,28,buff,1
           
     gosub show 
    
    
    
    stop
    Code:
    '****************************************************************'*  Name    : st7920.pbpmod                                     *
    '*  Author  : richard                                           *
    '*  Notice  : Copyright (c) 2021 caveat emptor                  *
    '*          : All Rights Reserved                               *
    '*  Date    : 23/10/2021                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : R/W NOT USED, HAS FRAME BUFFER INSTEAD            *
    '*          : LEVERAGES PBP LCD ROUTINES                        *
    '**************************************************************** 
    'SCREEN MAP    128X64
    'ROW COLUMNS  [WORDS]
    ' 0 | 0 1... 6  7
    ' . |
    ' . |
    ' . |
    ' 30| 
    ' 31| 0 1... 6  7
    ' 0 | 8 9...14 15
    ' . |
    ' . |
    ' 30|
    ' 31| 8 9...14 15
    
    
    '  usual  LCD defines are used  eg
    
    
    '    DEFINE LCD_BITS 4 	'defines the number of data interface lines (4 or 8) 
    '    DEFINE LCD_DREG PORTB	'defines the port where data lines are connected to
    '    DEFINE LCD_DBIT 0	'defines the position of data lines for 4-bit interface (0 or 4)
    '    DEFINE LCD_RSREG PORTB	'defines the port where RS line is connected to
    '    DEFINE LCD_RSBIT 6 	'defines the pin where RS line is connected to 
    '    DEFINE LCD_EREG PORTB 	'defines the port where E line is connected to 
    '    DEFINE LCD_EBIT 4 	'defines the pin where E line is connected 
    '    DEFINE LCD_COMMANDUS 1000 	'defines the delay after LCDOUT statement 
    '    DEFINE LCD_DATAUS 40 		'delay in micro seconds
    '    DEFINE LCD_RWREG PORTB ' LCD read/write port
    '    DEFINE LCD_RWBIT 5 ' LCD read/write pin bit
    ''END of LCD DEFINES 
    
    
    
    
    st7920_page var byte
    st7920_gli  var byte
    st7920_inx  var word
    st7920_tmx  var word
    st7920_lfx  var word
    st7920_bf   var byte
    
    
    
    
    
    
    goto overst7920
    #ifndef stserial  
    '4 or 8 bit parallel normsl pbp lcd defs
    st7920_init:
        lcdout $FE,$24 'In same instruction cannot alter DL, RE and G at once. Make sure that change DL or G first and then RE.
        lcdout $FE,$26 
        bgcolour = 0
        colour = 1
    return 
    
    
    st7920_send:   'd in R3
    @  L?CALL lcdsend
    return    
        
    
    
    
    
    st7920_busy:
       TRISB=TRISB&240
    ASM 
        MOVLW 0X0F
        IORWF LCD_DREG+0X12,F
        bsf   LCD_RWREG ,LCD_RWBIT
        NOP
        bcf   LCD_RSREG ,LCD_RSBIT
        NOP
        bsf   LCD_EREG ,LCD_EBIT
        NOP
        NOP
        NOP
        NOP
        MOVFF LCD_DREG ,_st7920_bf
        MOVF  LCD_DREG,W
        BANKSEL  _st7920_bf
        MOVWF   _st7920_bf
        bcf   LCD_EREG ,LCD_EBIT
        NOP
        NOP 
        NOP
        NOP        
        bsf   LCD_EREG ,LCD_EBIT
        NOP
        NOP
        NOP
        NOP
        bcf   LCD_EREG ,LCD_EBIT
        NOP
        NOP 
        NOP
        NOP
        bsf   LCD_RSREG ,LCD_RSBIT
        bcf   LCD_RWREG ,LCD_RWBIT
        NOP
        NOP
        MOVLW 0XF0
        ANDWF LCD_DREG+0X12,F
        BANKSEL 0
        ENDASM
     RETURN
     
    setxy:
    GOSUB   st7920_busy
    IF   st7920_bf.3 THEN  GOTO setxy
    ASM
        MOVLW 128
        BANKSEL _st7920_gli
        IORWF   _st7920_gli,W
        BANKSEL R3
        MOVWF   R3
        bcf   LCD_RSREG ,LCD_RSBIT
        MOVE?CT 1,FLAGS ,0
        L?CALL _st7920_send
        MOVLW 128
        BANKSEL _st7920_page
        IORWF   _st7920_page,W
        BANKSEL R3
        MOVWF   R3 
        bcf   LCD_RSREG ,LCD_RSBIT   
        MOVE?CT 1,FLAGS ,0
        L?CALL _st7920_send
        BANKSEL 0
    ENDASM
    return
    senddat16:
    GOSUB   st7920_busy
    IF   st7920_bf.3 THEN   GOTO setxy
    asm
        MOVE?BB   _st7920_tmx ,R3
        bsf   LCD_RSREG ,LCD_RSBIT
        MOVE?CT 1,FLAGS ,0
        L?CALL _st7920_send
        bsf  LCD_RSREG ,LCD_RSBIT
        MOVE?BB   _st7920_tmx+1 ,R3
        MOVE?CT 1,FLAGS ,0
        L?CALL _st7920_send
        BANKSEL 0
    ENDASM
    
    
    return 
    show:     'SEE MAP
        for  st7920_GLi = 0 to 31
            st7920_page = 0
            gosub setxy
            st7920_inx = st7920_gli*16
            for st7920_page = 0 TO 7    ;IS WORDS 0-7 IN TOP HALF
                st7920_tmx.lowbyte = fbr[st7920_inx] REV 8
                st7920_inx = st7920_inx + 1
                st7920_tmx.highbyte = fbr[st7920_inx]  REV 8
                st7920_inx = st7920_inx + 1
                gosub  senddat16
            next
            st7920_inx = st7920_gli*16+512
            for st7920_page = 0 TO 7     ;IS WORDS 8-15 IN BOTTOM HALF
                st7920_tmx.lowbyte = fbr[st7920_inx]  REV 8
                st7920_inx = st7920_inx + 1
                st7920_tmx.highbyte = fbr[st7920_inx]  REV 8
                st7920_inx = st7920_inx + 1
                gosub  senddat16
            next 
        next     
    return
    
    
    ;spi
    #else
    st7920_dat   var byte
    'spi pins used
    st7920_cs   var latc.1 
    'st7920_sck  is latc.3
    'st7920_sdi  is latc.4
    'st7920_sdo  is latc.5
    
    
    st7920_init:
      SSP1CON1=$22  ;$22 fastest that works @64m
      SSP1STAT=$40
      st7920_cs=1
      st7920_dat = %00001100
      gosub ST7920Command
      st7920_cs=0
      pause 20
      st7920_cs=1
      st7920_dat = %00100100 ; //EXTENDED INSTRUCTION SET
      gosub ST7920Command
      st7920_dat = %00100110 ; //EXTENDED INSTRUCTION SET
      gosub ST7920Command
      st7920_cs=0
      bgcolour = 0
      colour = 1
    return  
    
    
    setxy: 
        st7920_dat = st7920_gli| 128
        gosub ST7920Command
        st7920_dat = st7920_page| 128 
        gosub ST7920Command
    return 
    
    
    
    
    ST7920Data: 
      	PIR1.3=0     
        SSP1BUF = %11111010 
        WHILE   !PIR1.3 :    wend
        PIR1.3=0     
        SSP1BUF = (st7920_dat & %11110000)
        WHILE   !PIR1.3 :    wend
        PIR1.3=0     
        SSP1BUF = (st7920_dat<< 4)
        WHILE   !PIR1.3 :    wend
      	pauseus 50
    return
    
    
    ST7920Command:   
      	PIR1.3=0     
        SSP1BUF = %11111000
        WHILE   !PIR1.3 :    wend
        PIR1.3=0     
        SSP1BUF = st7920_dat & %11110000
        WHILE   !PIR1.3 :    wend
        PIR1.3=0     
        SSP1BUF = (st7920_dat<< 4)
        WHILE   !PIR1.3 :    wend
      	pauseus 100
    return
    
    
    show:     'SEE MAP
        for  st7920_GLi = 0 to 31
            st7920_cs=1
            st7920_page = 0
            gosub setxy
            st7920_inx = st7920_gli*16
            for st7920_page = 0 TO 7    ;IS WORDS 0-7 IN TOP HALF
                st7920_dat = fbr[st7920_inx] REV 8
                gosub  ST7920data
                st7920_inx = st7920_inx + 1
                st7920_dat = fbr[st7920_inx]  REV 8
                gosub  ST7920data
                st7920_inx = st7920_inx + 1
            next
            st7920_inx = st7920_gli*16+512
            for st7920_page = 0 TO 7     ;IS WORDS 8-15 IN BOTTOM HALF
                st7920_dat = fbr[st7920_inx] REV 8
                gosub  ST7920data
                st7920_inx = st7920_inx + 1
                st7920_dat = fbr[st7920_inx]  REV 8
                gosub  ST7920data
                st7920_inx = st7920_inx + 1
            next
           st7920_cs=0  
        next
    return
    
    
    senddat16:
                st7920_dat = st7920_tmx REV 8
                gosub  ST7920data
                st7920_dat = (st7920_tmx>>8) REV 8
                gosub  ST7920data
    return
    #endif
    
    
    
    
    
    
    overst7920:
    Last edited by richard; - 25th October 2021 at 00:51.
    Warning I'm not a teacher

  9. #9
    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,
    Ordered a couple of st7920 displays for this and in the mean time I'm revisiting the Nokia display. 1 question: you're driving the 18F26K22 @64MHz for the sample codes; is that necessary? Can I drive the display using the same processor at, say, 16 MHz?

    Thanks,

    Troy

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


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    1 question: you're driving the 18F26K22 @64MHz for the sample codes; is that necessary? Can I drive the display using the same processor at, say, 16 MHz?
    no not essential any speed will work, its just slower. the hw 12c / spi speeds can be tweaked in some cases to compensate
    Warning I'm not a teacher

  11. #11
    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 received my "st7920" displays from China (at least they're supposed to be) but I can't get anything from them from running your original code attachments in post #26. I haven't tried any of the code in #27 yet as I'm having problems with the "st7920.pbpmod" code having duplicate subroutines???
    Anyway, can you possibly post a link or example of the wiring to this display. So far, I've connected all the 4 data lines, E bit, RS & RW bits to the declared PortB pins in your code. I've connected the V0 pin via a 10K pot and I've pulled up the serial/parallel selection pin to parallel selection and of course connected the power rails.

    Thanks,

    Troy

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


    Did you find this post helpful? Yes | No

    Default Re: Graphical Displays with PBP3

    for parallel i/f the connections are as defined
    'LCD defines begin here
    ' DEFINE LCD_BITS 4 'defines the number of data interface lines (4 or 8)
    ' DEFINE LCD_DREG PORTB 'defines the port where data lines are connected to
    ' DEFINE LCD_DBIT 0 'defines the position of data lines for 4-bit interface (0 or 4)
    ' DEFINE LCD_RSREG PORTB 'defines the port where RS line is connected to
    ' DEFINE LCD_RSBIT 6 'defines the pin where RS line is connected to
    ' DEFINE LCD_EREG PORTB 'defines the port where E line is connected to
    ' DEFINE LCD_EBIT 4 'defines the pin where E line is connected
    ' DEFINE LCD_COMMANDUS 1500 'defines the delay after LCDOUT statement
    ' DEFINE LCD_DATAUS 60 'delay in micro seconds
    ' DEFINE LCD_RWREG PORTB ' LCD read/write port
    ' DEFINE LCD_RWBIT 5 ' LCD read/write pin bit
    ' 'END of LCD DEFINES

    for serial i/f the connections are the mssp sdi sdo sck pins plus what you pick for st7920_cs
    the st7920_rst pin was not required in my tests.

    for a 26k22 i used
    'spi pins used
    'st7920_rst var latc.0
    st7920_cs var latc.1
    'st7920_sck is latc.3
    'st7920_sdi is latc.4
    'st7920_sdo is latc.5

    I'm having problems with the "st7920.pbpmod" code having duplicate subroutines???
    there is no problem pbp just doesn't understand conditional compilation, ignore the warnings
    Last edited by richard; - 20th September 2022 at 02:51.
    Warning I'm not a teacher

Similar Threads

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

Members who have read this thread : 25

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