Menu

ST7920GLCD Demo Code not compile

Keith
2023-04-22
2023-05-01
  • Keith

    Keith - 2023-04-22

    My next project is a small Surface Grinder which has three axis motorised tables, X, Y, and Z.

    I am using a and 16F18875,32 40 pin device to control the three stepper motors, 3 position DRO's, the limit switches and the grinder motor.

    I was not expecting problems as early on in the project as this, but frankly the compilation errors have me baffled.
    The demo code is directly from the Great Cow BASIC documentation, GLCD Overview under 'ST7920 Controllers'

    The Errors are as follows

    >>>  WARNINGs / ERRORs reported by Great Cow BASIC  (if Syntax Error, doubleclick on the errormessage below)  <<<
    Surface Grinder Controller.gcb (36): Error: Syntax Error
    Surface Grinder Controller.gcb (41): Error: Syntax Error
    Surface Grinder Controller.gcb (43): Error: Variable RRUN was not explicitly declared
    Surface Grinder Controller.gcb (50): Error: Syntax Error
    Surface Grinder Controller.gcb (62): Error: Variable YPOS was not explicitly declared
    Surface Grinder Controller.gcb (63): Error: Syntax Error
    Surface Grinder Controller.gcb (66): Error: Syntax Error
    glcd.h * (109): Error: Invalid variable name: 6 (Library Include)
    glcd_st7920.h * (248): Error: 6 is not a variable (Library Include)
    

    The last two errors seem to point to the include libraries. It looks like I am missing something major in the setup.

    ;22:26 22.04.2023
    
     ;Chip Settings
    
        #option NoConfig
        #chip 16F18875,32
        #config  MCLRE_ON
        #option explicit
        #include <glcd.h>
    
        #define GLCD_TYPE GLCD_TYPE_ST7920
        #define GLCD_IO 8
        #define GLCD_WIDTH 128
        #define GLCD_HEIGHT 160
        #define GLCDFontWidth 6
    
        dim  xradius, yordinate , radiusErr, incrementalxradius, orginalxradius, orginalyordinate as Integer
        dim msg1 as string * 16
    
        ' read delay of 25 is required at 32mhz, this can be reduced to 0 for slower clock speeds
        #define ST7920ReadDelay 25
        ' write delay of 2 is required at 32mhz.  this can be reduced to 1 for slower clock speeds
        #define ST7920WriteDelay 2
    
        #define GLCD_RS        PORTa.0
        #define GLCD_Enable    PORTA.1
        #define GLCD_RW        PORTA.2
        #define GLCD_RESET     PORTA.3
        #define GLCD_DATA_PORT PORTD
    
        ST7920GLCDEnableGraphics
        ST7920GLCDClearGraphics
        GLCDPrint 0, 1, "Great Cow BASIC "
        wait 1 s
    
        GLCDCLS
        ST7920GLCDClearGraphics
    
        rrun = 0
    
    
    
    
        Do forever
            GLCDCLS
            ST7920GLCDClearGraphics           ;clear screen
            GLCDDrawString 30,0,"ChipMhz@"    ;print string
            GLCDDrawString 78,0, str(ChipMhz) ;print string
            Circle(10,10,10,0)                ;upper left
            Circle(117,10,10,0)               ;upper right
            Circle(63,31,10,0)                ;center
            Circle(63,31,20,0)                ;center
            Circle(10,53,10,0)                ;lower left
            Circle(117,53,10,0)               ;lower right
            GLCDDrawString 30,54,"PIC16F1937" ;print string
            wait 1 s                          ;wait
            FilledBox( 0,0,128,63)            ;create box
            for ypos = 0 to 63                ;draw row by row
            ST7920lineh 0,ypos,128, 0         ;draw line
            next
            wait 1 s                          ;wait
            ST7920GLCDClearGraphics           ;clear
        loop
    
     
  • Anobium

    Anobium - 2023-04-23

    No errors in the library.

    A few errors in the code - a Constant and two missing variables.
    Plus, the calls to the library are out of date. So, the code below uses the renamed calls in the library.

    The ST7920 is a slow but cheap GCLD. Intended for the Chinese market. I fell for the pricing years ago to discover it was so slow.

    Hopefully, the program works for you.


    I will update the Help to remove the constant that should be a variable.


     ;Chip Settings
    
        #chip 16F18875,32
        #config  MCLRE_ON
        #option explicit
        #include <glcd.h>
    
        #define GLCD_TYPE GLCD_TYPE_ST7920
        #define GLCD_IO 8
        #define GLCD_WIDTH 128
        #define GLCD_HEIGHT 160
        // #define GLCDFontWidth 6
    
        dim  xradius, yordinate , radiusErr, incrementalxradius, orginalxradius, orginalyordinate as Integer
        dim msg1 as string * 16
    
        ' read delay of 25 is required at 32mhz, this can be reduced to 0 for slower clock speeds
        #define ST7920ReadDelay 25
        ' write delay of 2 is required at 32mhz.  this can be reduced to 1 for slower clock speeds
        #define ST7920WriteDelay 2
    
        #define GLCD_RS        PORTa.0
        #define GLCD_Enable    PORTA.1
        #define GLCD_RW        PORTA.2
        #define GLCD_RESET     PORTA.3
        #define GLCD_DATA_PORT PORTD
    
        GLCDEnableGraphics_ST7920
        GLCDClearGraphics_ST7920
        GLCDPrint 0, 1, "Great Cow BASIC "
        wait 1 s
    
        GLCDCLS
        GLCDClearGraphics_ST7920
    
        Dim rrun, ypos
        rrun = 0
    
    
    
    
        Do forever
            GLCDCLS
            GLCDClearGraphics_ST7920          ;clear screen
            GLCDDrawString 30,0,"ChipMhz@"    ;print string
            GLCDDrawString 78,0, str(ChipMhz) ;print string
            Circle(10,10,10,0)                ;upper left
            Circle(117,10,10,0)               ;upper right
            Circle(63,31,10,0)                ;center
            Circle(63,31,20,0)                ;center
            Circle(10,53,10,0)                ;lower left
            Circle(117,53,10,0)               ;lower right
            GLCDDrawString 30,54,"PIC16F1937" ;print string
            wait 1 s                          ;wait
            FilledBox( 0,0,128,63)            ;create box
            for ypos = 0 to 63                ;draw row by row
                Line 0,ypos,128, 0         ;draw line
            next
            wait 1 s                          ;wait
            GLCDClearGraphics_ST7920           ;clear
        loop
    
     
  • Keith

    Keith - 2023-04-23

    Great ! That compiles okay - Thank you.

    Forever in your debt Sir.....

     
  • Anobium

    Anobium - 2023-04-24

    Compiling is good. Does it work?


    I will define a new Development Policy. All code in the Help must be 'included' in the Help source file(s). This will support the testing of all Help example programs being tested as part of the release/test suite.

     
  • Keith

    Keith - 2023-04-30

    Another problem. In the demo code it refers to the following:

        #define GLCD_Enable     PORTA.1           'example port setting
        #define GLCD_RS         PORTa.0           'example port setting
        #define GLCD_RW         PORTA.2           'example port setting
        #define GLCD_RESET      PORTA.3           'example port setting
        #define GLCD_DATA_PORT  PORTD             'example port setting
    

    The issue is with the final definition, " #define GLCD_DATA_PORT PORTD"

    I'm not too sure about this port D issue, as soon as I allocate GLCD_DATA_PORT to a physical port, i,e, C.5 the glcd_st7920.inc kicks in and halts the compiler.

    Secondly, where the blue blazes is this connected too on the ST7920 GLD Module.

    Anyone who has any knowledge of the connectivity of the ST7920 GLCD, I would be grateful for your help.

     
    • Anobium

      Anobium - 2023-05-01

      This specific device using an 8-bit bus, meaning there are 8 connections between the mcu and the GLCD. The GLCD_DATA_PORT configures the library to use the 8 bits on the specified port. The other connections are required and are self described.


      The library assumes an 8bit data bus.

      I2C or SPI connectivity would need to be added.

       

Log in to post a comment.