- The use of Proton_FontConverter.exe, so one is free to use the font needed
- Splitting the graphical part from the hardware part, so with a new display only the hardware part needs to change
- A new display 32x128pixels with the SSD1306
- Some problems/errors were repaired.
What are the changes:
- Only fonts generated with Proton_FontConverter.exe are accepted
- The DrawLine and DrawCircle (FillCircle) routines are “borrowed” from Les Johnson's ILI9325.inc. Les has already implemented the Bresenham's drawing algorithms for line and circle which I wanted to use. (Google the word “ Bresenham” for more information)
- The calling method is changed to preprocessor directives so parentheses are always required
- Instead of one Include you need four, SSD1306_Def, Graphic_Def, SSD1306_Sub and Graphic_Sub
Enclosed in the zip is demo_v0.4.bas with many of the possibilities for libraries. I have tested on a 18F26K22 and the result video is here: https://youtu.be/qMy_sTgiZs0
Command overview for the Graphic Library:
- [Graphic_]DrawPixel(x0, y0, color) : Draw a pixel
- [Graphic_]DrawLine(x0, y0, x1, y1, Color) : Draw a Line
- [Graphic_]DrawLinTo(x1, y1, Color) : Draw a Line from last DrawLine endpoint to x1, y1
- [Graphic_]DrawRectangle(x0, y0, x1, y1, Color) : Draw a rectangle
- [Graphic_]DrawCircle(xMP, yMP, Radius, Color) : Draw a circle MP=Center circle
- [Graphic_]FillRectangle(x0, y0, x1, y1, Color) : Draw a filled rectangle
- [Graphic_]FillCircle(xMP, yMP, Radius, Color) : Draw a filled circle MP=Center circle
- [Graphic_]GotoXY(x,y) : Position the cursor at x,y
- [Graphic_]SelectFont(FontLabel) : Select the font to be used for the next Proton PRINT
- [Graphic_]SetFont(Fontlabel) : Select the font to be used for the next Proton PRINT
Color = 0 = Black
You can omit Graphic_ so Graphic_SelectFont(Arial_9) is the same as SelectFont(Arial_9).
Proton commands output implemented in the Graphic Library:
- Cls : Clear the video buffer and refresh the display
- Cursor x, y : Position the cursor at x, y
- Print Item {, Item... } : Print item at the current cursor position
- Print At x, y, Item {, Item... } : Print item at cursor position x, y
- Print Inverse x : x=1 invert all the drawn pixels, x=0 not invert the pixels
- Print Xor x : x=1 print transparent (background of character is not printed), =0 not transparent
- SSD1306_Init() : Initialize the SSD1306 controller (will be executed automatic when SSD1306_Sub.inc is started)
- [SSD1306_]ClearVideoMem() : Clear video buffer (PIC RAM)
- [SSD1306_]RefreshDisplay() : Send video buffer (PIC RAM) to the display (SSD1306 GDDRAM)
- SSD1306_Contrast(x) : x=contrast value(0-255) 0=Grey display, 255=Sharp white display
- SSD1306_DisplayOff() : Switch the display Off
- SSD1306_DisplayOn() : Switch the display on
- SSD1306_DisplayInverse() : Inverse the whole display at once, GDDRAM and PIC RAM are NOT changed
- Difference: Print Inverse 1 writes inverse values to the PIC RAM
- SSD1306_DisplayNormal() : Normal display at once, GDDRAM and PIC RAM are NOT changed
OLED Display
The default display is a 64x128 pixel OLED display (with SSD1306) and doesn't need to be defined in the program ($Define SSD1306_DisplayNormal is internally used). When you connect a 32x128 pixel OLED display (with SSD1306) you need to put $Define SSD1306_DisplayHalf in your program BEFORE the Include of the SSD1306_Def.inc. Of course in this case you can only use a 32x128 display space.
A New Graphic Display Controller
When you need to implement a new Graphic Display Controller (say a SH1106) you have to change only the SSD1306 library. The graphic routines (which you don’t need to change) exit the graphic library via the Graphic_DrawPixel routine which calls the entry routine in a hardware library named Graphic_Plot. When you need to write your own display library, you start with Graphic_Plot and implement your own hardware. Make your own Controller_Def.inc and Controller_Sub.inc (for the SH1106: SH1106_Def.inc and SH1106_Sub.inc). The existing Graphic library (wihout changes) will automatic use your Included library with your new Graphic_Plot routine in it.
Proton_FontConverter
The Proton_FontConverter.exe generates a Proton usable piece of code from every Windows font on a Windows computer. Only the printable characters are generated (32-127) The layout of the generated fonts is:
- Two bytes with Font height and the bytes for one vertical line of the font
- An address table (word size) with 96 relative addresses for the starting point of the character images
- 96 character images each starting with the number of vertical lines in the character (=width) followed with all the data of the image (=width * bytes per line)
Generate Numbers Only spreadsheet usage:
- The Numbers only spreadsheet generates fonts for +,-./0123456789:
- All the other images are 0 bytes wide. The size of the font is roughly 20% of the original.
- Use Proton_FontConverter.exe to generate a font
- Start Excell FontConverterNumbersOnly
- Paste the generated font in Cell A1 of the Org sheet
- Push the button <Copy numbers from the font data>
- The xxx_NumOnly font will reside in the clipboard and can be pasted into the editor
- DO NOT SAVE the spreadsheet
The Graphic and SSD1306 libraries source code, demonstration program and spreadsheet can be downloaded from here: "
Graphic and SSD1306 Demo.zip
A new version (1.10) has not only support for hardware I2C (via MSSP1) but also SPI (via MSSP1 and MSSP2).
The SPI is implemented via the xxxxx-HSPI.inc libraries from AlbertoFS