Menu

I'm having a problem with glcd.h

2026-07-27
2026-07-29
1 2 > >> (Page 1 of 2)
  • Joe Tannenbaum

    Joe Tannenbaum - 2026-07-27

    Gcstudio ver 1.76.2
    glcd.h last update 19/02/25

    I include glcd.h
    I define: #define GLCD_TYPE_SSD1306_64x32

    I get this error:[{
    "resource": "/c:/GCstudio/gcbasic/include/glcd.h",
    "owner": "gcb",
    "severity": 8,
    "message": "SCRIPT/Constant: GLCD_TYPE_SSD1306_64X32 cannot reassigned to 38 (Library Include)",
    "source": "gcb",
    "startLineNumber": 118,
    "startColumn": 1,
    "endLineNumber": 118,
    "endColumn": 2147483647
    }]

    Is glcd.h corrupted?

     
  • Anobium

    Anobium - 2026-07-27

    Hello,

    Not likely to be corrupted.

    Post your source program.

     
  • Joe Tannenbaum

    Joe Tannenbaum - 2026-07-27

    Attached

     
  • Anobium

    Anobium - 2026-07-27

    Thanks.

    #define GLCD_TYPE_SSD1306_64x32
    

    This doesn't actually set anything. You've defined a stray symbol called GLCD_TYPE_SSD1306_64x32 (with no value), but GCBASIC's GLCD library looks for a constant named GLCD_TYPE to know which driver to load. Since GLCD_TYPE is missing you are trying to redfine a system constant - hence the error.

    Fix it like this:

    #chip 16f877A, 20
    
    #include <glcd.h>
    
    ; ----- Define GLCD Hardware Settings
    #define GLCD_TYPE GLCD_TYPE_SSD1306_64x32
    #define GLCD_I2C_Address 0x78
    .....
    

    However, I never got round to testing the GLCD_TYPE_SSD1306_64x32 on low memory chips.
    So, try using GLCD_TYPE_SSD1306 to see if the basic work but you may need to sort the library out,

     
  • Joe Tannenbaum

    Joe Tannenbaum - 2026-07-27

    I tried to re=install gcstudio, but error persists.

     
  • Anobium

    Anobium - 2026-07-27

    This is a syntax issue. Check my post.

     
  • Joe Tannenbaum

    Joe Tannenbaum - 2026-07-27

    That did it, I screwed up the define. I changed to GLCD_TYPE_SSD1306 , and am back to The array SSD1306_BUFFERALIAS is too large. If I add this: #define GLCD_TYPE_SH1306_LOWMEMORY_GLCD_MODE
    finally went back to GLVF_TYPE_64_32, and it compiled ok. Thanks

     

    Last edit: Joe Tannenbaum 2026-07-27
  • Anobium

    Anobium - 2026-07-27

    This library with 64×32 was not implemented or tested for low memory modes. And, your very old microcontroller does not have sufficient ram for a full buffer of 1024 bytes. The easy fix.. get a microcontroller with more RAM will resolve.

     
  • Joe Tannenbaum

    Joe Tannenbaum - 2026-07-27

    ok, figured I was mis interperting the datasheet. Thank you.

     
  • Anobium

    Anobium - 2026-07-28

    And, I have just test the GLCD library for low memory. I do not have time to test old 16F877A but it works OK, with an updated library, on the 16F1937. This means it should work great.

    #Chip 16F1937
    #Option Explicit
    #include <glcd.h>
    
    // Display configuration
    #DEFINE GLCD_TYPE         GLCD_TYPE_SSD1306_64x32 
    #DEFINE GLCD_I2C_Address  0x78 
    
    // I2C Software settings
    #DEFINE I2C_MODE Master
    #DEFINE I2C_DATA    PORTC.4
    #DEFINE I2C_CLOCK   PORTC.5
    #DEFINE I2C_DISABLE_INTERRUPTS ON
    
        #define GLCD_TYPE_SSD1306_CHARACTER_MODE_ONLY
        #define GLCD_TYPE_SSD1306_LOWMEMORY_GLCD_MODE
    
        //! This ONLY has pages pic 0,3
          GLCD_Open_PageTransaction 0,3
            GLCDPrint 2,2, "GCBASIC"
            GLCDPrint 2,15, "2026"
            Box 0,0,63,31
            line 0,0,63,31
          GLCD_Close_PageTransaction
    

    and

    #Chip 16F1937, 32
    #Option Explicit
    #include <glcd.h>
    
    // Display configuration
    #DEFINE GLCD_TYPE         GLCD_TYPE_SSD1306_64x32 
    #DEFINE GLCD_I2C_Address  0x78 
    
    // I2C Software settings
    #DEFINE I2C_MODE Master
    #DEFINE I2C_DATA    PORTC.4
    #DEFINE I2C_CLOCK   PORTC.5
    #DEFINE I2C_DISABLE_INTERRUPTS ON
    
        #define GLCD_TYPE_SSD1306_CHARACTER_MODE_ONLY
        #define GLCD_TYPE_SSD1306_LOWMEMORY_GLCD_MODE
    
        GLCD_Open_PageTransaction 0,3
          GLCDPrint 2,2, "GCBASIC"
          GLCDPrint 2,15, "2026"
          Box 0,0,63,31
          line 0,0,63,31
        GLCD_Close_PageTransaction
    
        Wait 2 s
        // GLCDCLS   //! GLCDCLS is not really needed as the Transactions will clear the screen anyway
    
        GLCD_Open_PageTransaction 0,3
          GLCDPrint 2,2, "GCBASIC"
          GLCDPrint 2,15, "Page 2"
          Box 0,0,63,31
          GLCD_Close_PageTransaction
    
     

    Last edit: Anobium 2026-07-28
  • Anobium

    Anobium - 2026-07-28

    Here is simple clock on the 64x32.

    How it works: Hours/Minutes/Seconds are plain bytes that get incremented once per loop iteration, gated by Wait 1 s — same tick mechanism as your example. Each pass builds a zero-padded HH:MM:SS string and redraws it inside a GLCD_Open_PageTransaction/Close block.

    A few notes since you'll want to double-check against your GCBASIC version's docs:

    Set the starting Hours/Minutes/Seconds values near the top, since there's no RTC here — it's a free-running software clock that will drift over time.

    If you have a real RTC (DS1307/DS3231 etc.) wired up, it'd be more accurate to read the time from that each loop instead of incrementing in software — you can adapt this if you're using one.

    #Chip 16F1937, 32
    #Option Explicit
    #include <glcd.h>
    
    // Display configuration
    #DEFINE GLCD_TYPE         GLCD_TYPE_SSD1306_64x32
    #DEFINE GLCD_I2C_Address  0x78
    
    // I2C Software settings
    #DEFINE I2C_MODE Master
    #DEFINE I2C_DATA    PORTC.4
    #DEFINE I2C_CLOCK   PORTC.5
    #DEFINE I2C_DISABLE_INTERRUPTS ON
    
        #define GLCD_TYPE_SSD1306_CHARACTER_MODE_ONLY
        #define GLCD_TYPE_SSD1306_LOWMEMORY_GLCD_MODE
    
    // ---- Clock variables ----
    Dim Hours   As Byte
    Dim Minutes As Byte
    Dim Seconds As Byte
    
    Dim TimeString As String
    Dim HH As String
    Dim MM As String
    Dim SS As String
    
    // ---- Set the starting time here ----
    Hours   = 12
    Minutes = 0
    Seconds = 0
    
    Do
    
        // Build zero-padded strings for each field
        If Hours < 10 Then
            HH = "0" + Str(Hours)
        Else
            HH = Str(Hours)
        End If
    
        If Minutes < 10 Then
            MM = "0" + Str(Minutes)
        Else
            MM = Str(Minutes)
        End If
    
        If Seconds < 10 Then
            SS = "0" + Str(Seconds)
        Else
            SS = Str(Seconds)
        End If
    
        TimeString = HH + ":" + MM + ":" + SS
    
        GLCD_Open_PageTransaction 0,3
          GLCDPrint 10,10, TimeString
          Box 0,0,63,31
        GLCD_Close_PageTransaction
    
        Wait 1 s
    
        // ---- Increment the clock by one second ----
        Seconds = Seconds + 1
        If Seconds = 60 Then
            Seconds = 0
            Minutes = Minutes + 1
            If Minutes = 60 Then
                Minutes = 0
                Hours = Hours + 1
                If Hours = 24 Then
                    Hours = 0
                End If
            End If
        End If
    
    Loop
    
     
  • Anobium

    Anobium - 2026-07-28

    Here is a RTC Clock using external clock on this little GLCD!

    Enjoy

     
  • Joe Tannenbaum

    Joe Tannenbaum - 2026-07-28

    Will try these when I get home. Thank you.

     
  • Anobium

    Anobium - 2026-07-28

    Chose your chip but these should work even on that old chip.

     
  • Roger Jönsson

    Roger Jönsson - 2026-07-28

    Cool little simple clock project!

     
  • Anobium

    Anobium - 2026-07-28

    Even cooler... you can set the time on the OLED via two switches and a POT.

    This is highly customization.

     
    👍
    2

    Last edit: Anobium 2026-07-28
  • Joe Tannenbaum

    Joe Tannenbaum - 2026-07-28

    I have some pic16f1938's on order.

     

    Last edit: Joe Tannenbaum 2026-07-28
  • Anobium

    Anobium - 2026-07-29

    Some really nice bits in the RTC demo. A few worth highlighting:

    1. Freezing the clock during editing instead of fighting it. Setting PIE1.TMR1IE = 0 while in a SET state stops the ISR from incrementing Hours/Minutes behind your back while the pot is also writing to them. That's a real race condition avoided with one line, no mutex/critical-section gymnastics needed.

    2. CommitAndRun doubling as a time-sync button. Pressing SW_EXIT doesn't just leave set mode — it resets Seconds to :00 and reloads Timer1 at that exact instant. That turns it into a poor-man's "sync to the pips" feature: hold for the top of the minute, release, and you're dead-on.

    3. Change-gated redraw (LastShown). The set screen only repaints when the pot's mapped value actually changes, not every loop pass. Small detail, but on a bit-banged I2C display it's the difference between a responsive knob and a stuttery one.

    4. One state machine, one loop, no duplication. ClockMode (RUN / SET_HOURS / SET_MINUTES) lets the same Do...Loop drive three different behaviors without three separate loops or a tangle of flags — it reads almost like a tiny UI framework for a 3-line display.

    5 Using the ADC to set the time. Turning a linear pot reading straight into a wall-clock field with one multiply-divide (ADCValue * Range / 1024) skips the usual up/down-button tedium entirely — you get analog, direct-mapped control instead of stepping through 23 hours one click at a time. It also reads naturally: turn the knob a little, the hour barely moves; turn it a lot, it sweeps the whole range.

    6. Function PotToRange(Range As Byte) As Byte. One small function does double duty for both fields just by changing its argument — PotToRange(24) for hours, PotToRange(60) for minutes. No copy-pasted scaling math, no separate "hours version" and "minutes version" of the same logic. That's the kind of tiny abstraction that makes the rest of the code (ShowSetScreen too) easy to extend if you ever add a seconds-set or a day/date field later.

     
  • Joe Tannenbaum

    Joe Tannenbaum - 2026-07-29

    I tried these (the first two), but my compiler still gets error 64_32 low memory not tested. Update to program or library?

     

    Last edit: Joe Tannenbaum 2026-07-29
  • Anobium

    Anobium - 2026-07-29

    Did you you update your installation wiht the new library above? The .h file.

     
  • Joe Tannenbaum

    Joe Tannenbaum - 2026-07-29

    How do you update a library?
    I didn't see any update options.

     
    • Anobium

      Anobium - 2026-07-29

      Replace the existing file in GCSTUDIO\GCBASIC\INCLUDE folder.

       
  • Joe Tannenbaum

    Joe Tannenbaum - 2026-07-29

    I figured that. Where do I get the updated library? Google and github no help.

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.