Anobium - 2025-01-23

See KO-FI Post here


I am excited to share that I have added GCBASIC support for the Microchip PICDEM4 board's LCD, driven via an LCD IO Expander based on a PIC18LF72.

Part Number: DM163014 PICDEM 4 DEMONSTRATION BOARD

Background:

When I first received the PICDEM4 board, the LCD IO Expander based on a PIC18LF72 came without proper documentation, leaving me with only ASM code to work with. The complexity of the original ASM was quite baffling. However, I managed to simplify the implementation using GCBASIC, making the LCD IO Expander protocol far less complex and more accessible.

Simplified Protocol with GCBASIC:

The LCD IO Expander protocol is actually straightforward, and I believe it could be emulated in the future. Here is how it works:

  • The LCD IO Expander expects two bytes via SPI for each byte of LCD data.

  • The first byte is the high nibble, and the second byte is the low nibble.

  • If the byte being sent is a COMMAND, then bit 4 of the SPI byte(s) is set to high.

  • To latch the transmission, bit 6 of the SPI byte(s) is set to high.

All this complexity is managed in the LCD.H file and is transparent to a GCBASIC developer. Just set up the LCD as shown below.

For more details, you can refer to the GCBASIC documentation on LCD.IO constants.

Development Insights:

During development and testing, I discovered an important aspect regarding the IO Expander. Sometimes it may need a power reset to truly reset. The IO Expander lacks a separate reset function, which means it can occasionally get "out of sync." This issue arises during programming, for instance, when the IO Expander is mid-byte reception and the protocol halts. Unfortunately, I found no method other than power cycling the whole board to reset the IO Expander.

Setting Up with GCBASIC:

Setting up the GCBASIC for the PICDEM4 LCD IO Expander is quite simple:

    // Constants - LCD connectivity type
    #DEFINE LCD_IO 16

    // PIN MAPPINGS FOR PIC18LF72 LCD IO SPI EXPANDER
        // CONSTANT IS MANDATED - DATA LINE
                #DEFINE LCD_SPI_DO PORTB.2
        // CONSTANT IS MANDATED - CLOCK LINE
                #DEFINE LCD_SPI_SCK PORTB.5

    // Main program

    Print "GCBASIC Rocks!"
    End

With this setup, all GCBASIC LCD commands are supported, making it very user-friendly and efficient to get your projects up and running.

Reflecting on the new capability:

It has been an interesting journey working on this integration. The original ASM code's complexity was a challenge, but breaking it down and simplifying it with GCBASIC was incredibly satisfying. The ease of use and powerful capabilities of GCBASIC make it a great choice for both beginners and experienced developers. Plus, the PICDEM4 board, combined with the GCBASIC support, opens up a world of possibilities for microcontroller-based projects.

Final Thoughts:

I hope you find this LCD update useful and enjoy working with GCBASIC on a PICDEM4 board. As always, thank you for your continued support and feedback. I am always striving to improve the GCBASIC compiler and make your coding experience smoother and more efficient.