Graphical Displays with PBP3


Results 1 to 40 of 115

Threaded View

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


    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; - 24th October 2021 at 23:51.
    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 : 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