PDA

View Full Version : SSD1306 INCLUDE for PBP3



richard
- 4th December 2017, 11:31
Features :-
Pic 16 or 18
Tiny size about 1.5k words for soft i2c 1.3k for hw i2c
64X128 OR 32X128 DISPLAYS
SOFT I2C OR HARDWARE I2C
NORMAL OR DOUBLE SIZE CHAR
HORIZ and VERT LINES
Speed for hw i2c tested up to 2,666,666 clock rate, makes soft i2c look like a snail
Simple Usercommand Commands

richard
- 7th May 2018, 02:40
update include
added inline const string capability for pic16 chips

pedja089
- 7th May 2018, 12:53
Looks good. I don't have lcd to try it out.
I hope that you didn't write all user command wrapper manually.
I posted app for that
http://www.picbasic.co.uk/forum/showthread.php?t=20208

richard
- 8th May 2018, 01:44
I hope that you didn't write all user command wrapper manually.
I posted app for that

I am aware of your app but the base code for this preceded it , so yes it was a manual work:frown:
I haven't done anything pbp wise with enough user command code in it to use your app yet .it seems that
I have spent most of my time coming to terms with the mcc and xc8 lately . I don't see myself coming back
from that exercise now . development wise C is just so much easier, I will still keep hacking away at pbp
for now anyway.

Ioannis
- 8th May 2018, 11:08
Nice work, thanks Richard for sharing.

Ioannis

Mike, K8LH
- 21st June 2018, 15:42
Thank you for posting an SSD1306 example, Richard. I'd like to bring up my 128x32 OLED display using a 16F1823 and XC8 with a 'retro' TIL311 type font.

Cheerful regards, Mike

Mike, K8LH
- 13th July 2018, 00:36
Richard, may I ask if you did anything special to run the SSD1306 display and I2C interface at ~2.6-MHz, please? I'm amazed that my setup (on a solderless breadboard) is running without any problems at 1-MHz but when I tried a 2-MHz I2C clock the display doesn't come up. I'm using 3.6 kOhm pull-up resistors on the I2C bus.

Cheerful regards, Mike

richard
- 13th July 2018, 01:52
mike
I had "setup" the display at a lower rate and kept increasing the i2c baud rate till the display failed to update .
only one of my 6 displays could exceed 1mhz , one had issues above 400khz. I did not look at the pull up resistors .just trusted that the modules were fitted out appropriately. vcc was 3.3 v
the data sheet specs give a ic2 clock of 2.5uS 400khz so its probably not the best idea I have had.
i'm running them a 400k for reliability

Mike, K8LH
- 13th July 2018, 04:48
I didn't realize there were pull-up resistors already installed on the display module. I pulled the 3.6k resistors and the display works fine. My circult and display are running on 5v.

Thank you again for new info'...

Hope you and family are well and enjoying a wonderful summer.

Cheerful regards, Mike

louislouis
- 5th April 2020, 20:53
Hi Richard,

it's any possibilities to drawing a line like a progress bar?
For example, I had ADVAL value from 0 to 120, and I want to draw line on OLED.
I try this:


GLCDDHL 0,0,adval,1

This didn't work because GLCDDHL accept only numbers not variables like ADVAL.

It there any way to do it with your include?

richard
- 6th April 2020, 00:27
This didn't work because GLCDDHL accept only numbers not variables like ADVAL.


It there any way to do it with your include?


EASY , Just add the highlighted macro's to the include file


;----------------------HORIZ LINE------------------------------------ GLCDDHL?CCCC macro Xin ,Yin , Win ,Cin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Win ,_gl
MOVE?CB Cin ,_glcdData
L?CALL _xyx
endm


GLCDDHL?CCBC macro Xin ,Yin , Win ,Cin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?BB Win ,_gl
MOVE?CB Cin ,_glcdData
L?CALL _xyx
endm


GLCDDHL?CCWC macro Xin ,Yin , Win ,Cin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?WB Win ,_gl
MOVE?CB Cin ,_glcdData
L?CALL _xyx
endm

louislouis
- 6th April 2020, 01:15
Thanks Richard, tomorrow I try it.

And this probably for vertical lines:


;----------------------VERT LINE------------------------------------
GLCDDVL?CCC macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Hin ,_gl
L?CALL _xyy
endm

GLCDDVL?BCC macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Hin ,_gl
L?CALL _xyy
endm

GLCDDVL?WCC macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Hin ,_gl
L?CALL _xyy
endm

Right?

richard
- 6th April 2020, 01:22
And this probably for vertical lines:


no , the Hin is what you would change



;----------------------VERT LINE------------------------------------
GLCDDVL?CCC macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Hin ,_gl
L?CALL _xyy
endm


GLCDDVL?CCB macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?BB Hin ,_gl
L?CALL _xyy
endm


GLCDDVL?CCW macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?WB Hin ,_gl
L?CALL _xyy
endm

louislouis
- 6th April 2020, 17:23
I tried it, and it works for drawing smooth line from variable 0 to 120 for example, but if the value decreasing from 120 to 0 then I'm not able to clean the line without clearing the whole display and it causes flickering.
Why I need that? I'm trying to make a voltmeter with bargraph.
Here are the code snipet:


gosub glcd_init
GLCD_CLR

do
for n=0 to 120 step 1
GLCDDHL 0,0,n,1
next n

for n=120 to 0 step -1
GLCD_CLR
GLCDDHL 0,0,n,1
next n
loop

It would be good to have variable option in all options like:


GLCDDHL var1,0,var2,0
GLCDDVL var1,0,var2,0
GLCD_CLR var1,0,var2,0

It's that possible?

richard
- 6th April 2020, 23:10
I Think a new command is easier
USERCOMMAND "GLCD_BAR" ;clear/SET area x,y,X1,Y1,COLOUR


eg

GLCD_BAR 0,0,var1,3,1 ;draw a horiz bar from 0,0 to var1 . three pixels wide
GLCD_BAR 0,0,var1,3,0 ;clear a bar from 0,0 to var1 . three pixels wide

or

GLCD_BAR 0,0,3,var1,1 ;draw a vert bar from 0,0 to var1 . three pixels wide
GLCD_BAR 0,0,3,var1,0 ;clear a bar from 0,0 to var1 . three pixels wide


i don't have anything setup so this is untested, caveat emptor



ps if GLCD_BAR 0,0,3,var1,1 is not right then
GLCD_BAR 0,0,3,var1,255 might be needed

richard
- 6th April 2020, 23:33
an improvement if bar cmd fails

gosub glcd_init
GLCD_CLR


do
for n=0 to 120 step 1
GLCDDHL 0,0,n,1
next n


for n=120 to 0 step -1
GLCD_CLR 0,0,120,1 ;is a lot more efficient
GLCDDHL 0,0,n,1
next n
loop

louislouis
- 7th April 2020, 00:31
Thanks for reply,
It doesn't work quite well. It draw four lines instead one line. For me is more suitable to have variables in usercommands like I wrote before.


GLCDDHL var1,0,var2,0
GLCDDVL var1,0,var2,0
GLCD_CLR var1,0,var2,0

because in this case I can point exactly what and where I want to clear the line, or draw a for example 10pixel wide line and move it horizontally wherever I want with changing variables.


do
for n=0 to 120 step 1
GLCDDHL 0,0,n,1
next n


for n=120 to 0 step -1
GLCD_CLR 0,0,120,1 ;is a lot more efficient
GLCDDHL 0,0,n,1
next n
loop

This solution I tried before as well, it still flicker if line goes from 120 to 0.

richard
- 7th April 2020, 00:52
i can't follow what your saying
show some code of what you try an describe what you get or post a pic

did you try new include file like this for narrow bar?
GLCD_BAR 0,0,var,1,1 ;draw a horiz bar from 0,0 to var . 1 pixels wide ;//or GLCD_BAR 0,0,var,1,255 ;draw a horiz bar from 0,0 to var . 1 pixels wide

louislouis
- 7th April 2020, 01:08
I want to create this just with straight one pixel line.
https://www.youtube.com/watch?v=R0YfQ6O7H3E

richard
- 7th April 2020, 01:34
i understand what you are trying to do.
i don't follow how you are trying to implement it

richard
- 7th April 2020, 04:43
while usercmd helps alleviate the turpitude of pbp's immutable condition when it comes to
support for any peripheral devices/hardware module less than 20 years old.
usercmd is by no means perfect, a macro needs to exist for each and every permutation of input term/s
and that can be lots and lots of macros. i create only the ones i require ,its not difficult to
add more . a close look at the error messages when compiling tells you whats missing if there is an issue


pedja089 made this if you want an easy way to cover many bases


http://www.picbasic.co.uk/forum/showthread.php?t=20208&highlight=usercmd

Ioannis
- 7th April 2020, 12:09
I suppose you are aware of the Darrel's Bargraph include file (http://dt.picbasic.co.uk/CODEX/LCDBARgraphs). Isn't this enough for your needs?

Ioannis

louislouis
- 7th April 2020, 21:22
It took a little while to figure out how to do it, but finally I made it.
Thanks for help to Richard. He pointed me how to modify usercomands for my needs. Endless possibilities to create a bargraphs, progress bars etc. On camera looks a bit flickery, but in real life no flicker whatssoever.
Here a little demo how it works:
https://www.youtube.com/watch?v=6hfGOawnZ-M

richard
- 8th April 2020, 03:34
looks good

Ioannis
- 8th April 2020, 11:09
Very nice! Congratulations for the conquer of the Usercommand. Never could find how to make use of it.

Ioannis

MUC
- 30th April 2020, 21:21
Hello,

I need help getting this to work. My oled display does not respond at all and appears off. I'm running the sd1306_demo_16.pbp program. Everything compiles fine. I'm using a 16F1619. Here is what I've tried so far.

1. I tried both the old and newer i2c.inc files
2. Confirmed the oled works by using it on an Arduino
3. Confirmed the proper oled address with the Arduino (0x3C). I made the change in the demo.pbp file
4. Ran blink LED program on the PIC16F1619 to verify functionality
5. Tried at lower 4Mhz clock speed
6. Checked Clock and Data pins with scope to make sure data was being output to the display, it is
7. Tried two other oled

I'm not sure what else to try. I've never used an include file before so maybe I'm doing something wrong. I put all the include files and font files in the same folder as the .pbp file location.



'************************************************* ***************
'* Name : ssd1306_DEMO.PBP *
'* Author : richard *
'* Notice : *
'* : *
'* Date : 19/11/2017 *
'* Version : *
'* Notes : *
'* :FOR pic 16F1619 SSD1306 *
'************************************************* ***************
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCD_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_HI & _LVP_ON
__config _CONFIG3, _WDTCPS_WDTCPS6 & _WDTE_OFF & _WDTCWS_WDTCWS100 & _WDTCCS_LFINTOSC
#ENDCONFIG


define OSC 32
'define OSC 4

; --- *** Oscillator *** ---------------------------------------------------
OSCCON = %11110000 ;32 MHz,
'OSCCON = %01101000 ;4 MHz,
ANSELb = 0
ANSELA = 0
ANSELC = 0

char var byte
x var byte
y var byte
BUFF VAR BYTE[16]
;use this define for hw i2c
;#define hwi2c 1
#DEFINE PIC16 1
;set and uncomment these to use softi2c
SCL var PortB.6 ' I2C Clock PICpin 11
SDA var PortB.4 ' I2C Data PICpin 13

;set these to match display
ssdheight con 7 ; 7 = 8 PAGES 64*128 , 3 = 4 pages 32*128
ssdwidth con 127 ; 128 PIXELS WIDE
'sdd1306_addr con $78
sdd1306_addr con $3C
Include "ssd1306_I2C.INC" ' bring it in
include "font7x5_16.bas"
'========================== MAIN Routine ==============================

gosub glcd_init
BIG_TEXT = 0


looper:
GLCD_CLR
GLCDDHL 0,0,75,1 ;x,y,len,patten
GLCDDHL 0,2,75,128
GLCDDVL 0,0,3 ;x,y,height [in pages]
GLCDDVL 75,0,3
;GLCDSTR 5,1,"--SSD1306--" ;x,y, cont string PIC 18 ONLY
ARRAYWRITE BUFF,["--SSD1306--",0]
GLCDSTR 5,1,BUFF
ARRAYWRITE BUFF,["ABCDEF",0]
CHAR="!"
GLCDC 100,1,CHAR ;x,y , chr
BIG_TEXT = 1
if ssdheight > 3 then
GLCDSTR 2,4,BUFF
ARRAYWRITE BUFF,["@12456-=#",0]
BIG_TEXT = 0
GLCDSTR 2,7,BUFF ;x,y ,str buffer [null terminated]
else
pause 1000
GLCD_CLR
GLCDSTR 2,0,BUFF
ARRAYWRITE BUFF,["@12456-=#",0]
BIG_TEXT = 0
GLCDSTR 2,3,BUFF
endif
PAUSE 3000
GOTO looper

END

richard
- 30th April 2020, 23:08
3. Confirmed the proper oled address with the Arduino (0x3C). I made the change in the demo.pbp file

arduino use a 7 bit address pbp uses an 8 bit addresss , correct address to use is (arduino address)<<1
0x3c<<1 = 0x78

MUC
- 1st May 2020, 00:31
thanks Richard,

I had no idea. I changed the address back to 0x78 just now and I still don't get anything on the screen. I get this ASM Warning in the results window after compiling. Not sure if it matters

[ASM WARNING] SD1306_DEMO_16.ASM (400) : Found label after column 1. (GLCD_BAR?CCBWC)
[ASM WARNING] SD1306_DEMO_16.ASM (432) : Found label after column 1. (GLCD_BAR?CCBWC)

richard
- 1st May 2020, 00:52
I get this ASM Warning in the results window after compiling. Not sure if it matters

[ASM WARNING] SD1306_DEMO_16.ASM (400) : Found label after column 1. (GLCD_BAR?CCBWC)
[ASM WARNING] SD1306_DEMO_16.ASM (432) : Found label after column 1. (GLCD_BAR?CCBWC)

it does matter, it means you are not compiling the code you posted.
Found label after column 1 means the macro you are trying to compile does not exist.

the GLCD_BAR usercommand does not exist in the original include it was added to for louis' setup and only a small subset of input var combinations are
catered for. i have not tested the added code and am not sure what louis wound up with.

get the demo working first

MUC
- 1st May 2020, 01:38
thanks, I went back and used the original ssd1306_I2C.inc. Now no warning when I compile. With no changes to the demo I still can't get anything to show on the oled. To make sure the oled hardware is still good I just checked it with the arduino and it's working fine. I've triple checked my wiring and don't see any mistakes.

richard
- 1st May 2020, 02:00
i havent used one of those displays for some time ,my other demo for a pic16f1619 used the mssp i2c module
try this ,it worked on my curiosity board , plugged straight in to click socket

'************************************************* ***************
'* Name : ssd1306_DEMO.PBP *
'* Author : richard *
'* Notice : *
'* : *
'* Date : 19/11/2017 *
'* Version : *
'* Notes : plugs into click port note !!!!sda/scl swapped on click skt*
'* :FOR pic 16F1619 SSD1306 *
'************************************************* ***************
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & _ZCD_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_HI & _LVP_ON
__config _CONFIG3, _WDTCPS_WDTCPS6 & _WDTE_OFF & _WDTCWS_WDTCWS100 & _WDTCCS_LFINTOSC
#ENDCONFIG




define OSC 32



; --- *** Oscillator *** ---------------------------------------------------
OSCCON = %11110000 ;32 MHz,
ANSELb = 0
ANSELA = 0
ANSELC = 0


char var byte
x var byte
y var byte
BUFF VAR BYTE[16]
;use this define for hw i2c
#define hwi2c 1
#DEFINE PIC16 1
;set and uncomment these to use softi2c
'SCL var PortB.4 ' I2C Clock
'SDA var PortB.6 ' I2C Data
RB VAR WORD
;set these to match display
ssdheight con 7 ; 7 = 8 PAGES 64*128 , 3 = 4 pages 32*128
ssdwidth con 127 ; 128 PIXELS WIDE
sdd1306_addr con $78
Include "ssd1306_I2C.INC" ' bring it in
include "font7x5_16.bas"
'========================== MAIN Routine ==============================
TRISB = $F0;
PPSLOCK = $55;
PPSLOCK = $AA;
PPSLOCK = 0 ; unlock PPS
SSPCLKPPS = $0C; //RB4->MSSP:SCL;
SSPDATPPS = $0E; //RB6->MSSP:SDA;
RB6PPS = $11; //RB6->MSSP:SDA;
RB4PPS = $10; //RB4->MSSP:SCL;
PPSLOCK = $55;
PPSLOCK = $AA;
PPSLOCK = 1; ; lock PPS


gosub glcd_init
GLCD_CLR
BIG_TEXT = 0
ARRAYWRITE BUFF,["READY",0]
GLCDSTR 10,1,BUFF

MUC
- 1st May 2020, 02:19
unfortunately I don't get anything on the oled

Ioannis
- 1st May 2020, 18:18
Maybe it is nonsense this but, is there a contrast control? I had an issue once on LCD with this.

Ioannis

MUC
- 1st May 2020, 20:00
thanks but no, there is no contrast control. if anyone has any ideas let me know. i'll post if I ever figure it out

wizard
- 30th September 2020, 12:52
Hi Guys
Can anyone help! I am trying to get this code to work with a 16f88 and a 128x32 OLED.

HenrikOlsson
- 13th March 2021, 14:36
I'm using Richards code with a small 0.96" 128x32 OLED display, soft I2C (because the 18F46K42 doesn't have the "old" MSSP module).
I've managed to print text and variables on the screen but in order to update those values without clearing the whole screen I'm trying to figure out how to use the GLCD_CLR command to clear an area.

I can make it do something but what it does doesn't make much sense to me. It seems to be pixel by row based but still, it's acting weirdly on me.
For example, with the following screen as a starting point:
9033

GLCD_CLR 0,0,5,1 or GLCD_CLR 0,0,10,1 does absolutely nothing while GLCD_CLR 0,0,10,2 does this:

9032

GLCD_CLR 10,0,40,1 does this (which is reasonable, clearing a section of 30pixels wide, 1 row high):

9031

While GLCD_CLR 10,0,41,1 does this:

9030

I'm also getting strange results with the GLCD_BAR command. Anyone knows/understands what's going on here? Am I using it wrong or have I stumbled across an issue?

/Henrik.

HenrikOlsson
- 13th March 2021, 17:37
Well, it turns out I don't have to worry about manually blanking out "stuff" - it just works. Still curious about the GLCD_CLR though.

richard
- 14th March 2021, 01:52
henrik
there is a great probability i never tested it to any great extent , was just happy that it cleared to whole screen at a default setting

this works for one line as i intended things to [you need to work around the limited size of the data buffer glcd_buff]


gx=5:gx_=32:gy=0:gy_=0 ; clear from x=5 for 32 bits one line
gosub setxy
j=0
for i=0 to gx_
glcd_buff[i]=0 ;by default the buffer is 32 bytes so be wary
next
glcd_rad=gx_
gosub ssd_data



two lines


gx=5:gx_=32:gy=0:gy_=1
gosub setxy
j=0
for i=0 to gx_
glcd_buff[i]=0
next
glcd_rad=gx_
gosub ssd_data
gosub ssd_data




you may be able to figure out why the command fails , i'm just not seeing it at the present time

richard
- 14th March 2021, 03:01
try this


glcd_clrxy: ' clear area x1y1 to x2 y2
FOR GRX = 0 TO 31
glcd_buff[GRX] = glcdData
NEXT
CTEMP = (1 + GX_ - GX)*(1 + GY_ - GY)
gosub setxy
glcd_rad=32
for GRX = 0 to CTEMP/32
gosub ssd_data
next
glcd_rad = CTEMP//32
IF glcd_rad THEN
gosub ssd_data
ENDIF
return

HenrikOlsson
- 14th March 2021, 10:53
Thank you Richard!
Replacing the glcd_clrxy subroutine with that from post #38 seems to have fixed it.
It also seems to have made GLCD_BAR more predictable but I have not looked into how they're interconnected.

I also got the two Label after column 1 warnings (GLCDS_BAR_?CCBWC) etc but it turns out that there's a whitespace infront of those two macro labels on the include file. There was also an ELSE in column 1 causing another warning.

I need to spend some time trying to figure out how it does it's things, would like to be able to add a slightly larger font for example. Guessing I need to replace/change the unpack routine - at the very least.

This SSD1306-driver saved me alot of time, much appreciated Richard!

/Henrik.

richard
- 14th March 2021, 13:38
I also got the two Label after column 1 warnings (GLCDS_BAR_?CCBWC) etc but it turns out that there's a whitespace infront of those two macro labels on the include file. There was also an ELSE in column 1 causing another warning.



i had a look at the org file i posted and it has the same errors, i always have trouble with white space


also found 2017 version where the glcd_clrxy routine was ok, so i must have broken it when i added the bar stuff



this is better


glcd_clrxy: ' clear area x1y1 to x2 y2
FOR GRX = 0 TO 31
glcd_buff[GRX] = glcdData
NEXT
CTEMP = (1 + GX_ - GX)*(1 + GY_ - GY)
gosub setxy
glcd_rad=32
GRX = CTEMP/32
while grx
gosub ssd_data
grx=grx-1
wend
glcd_rad = CTEMP//32
IF glcd_rad THEN
gosub ssd_data
ENDIF
return

richard
- 20th March 2021, 08:08
alternate method for ssd1306
http://www.picbasic.co.uk/forum/showthread.php?t=24218&p=146741#post146741

CuriousOne
- 15th August 2021, 18:56
I'm trying to run this on 16F886
and getting error
ASM Symbol not previously defined FSR1L Error 113

Any ideas?

Ioannis
- 15th August 2021, 23:10
Wrong MCU selected on the IDE?

Ioannis

richard
- 16th August 2021, 00:29
I'm trying to run this on 16F886
and getting error
ASM Symbol not previously defined FSR1L Error 113


my expectation is that old clunker chips with only one FSR register will likely not have enough Flash and/or Sram
to be useful with this sort of display, the code makes no allowance for them

CuriousOne
- 16th August 2021, 06:16
Well, as author stated, this code is suited for 16F series and fits under 4K. 886 has 8K.

Ioannis
- 16th August 2021, 17:06
I have not found FSR1L register on 886 chip...

Ioannis

CuriousOne
- 16th August 2021, 21:21
OK, will try with 18F2550 later and write back.

CuriousOne
- 22nd August 2021, 21:09
Had no chance to test it yet on PBP, connected to Arduino uno for testing and launched adafruit library demos. Adjusted some speeds and quite impressed. Should I expect same speed on PIC18F2550 or it will be significantly slower?

Ioannis
- 25th November 2021, 14:52
Can these LCD's show custom characters?

I have a request to make a display that will show chess pieces like this ♟️ -> A4.

Unfortunately character LCD do not have enough resolution with 5x7 characters so this 1306 may be a good alternative.

Ioannis

richard
- 25th November 2021, 14:59
Yes any font can be created in fixed or variable width

Ioannis
- 25th November 2021, 15:08
OK, thanks.

Will order then a few to play with.

Ioannis

Ioannis
- 19th December 2021, 22:07
How are fonts or special symbols to be designed for SSD1306?

I could not figure out studying the font7x5 include files.

As I posted above I need to design some chess pieces and 5x7 is not enough space.

Ioannis

richard
- 19th December 2021, 22:42
i use MikroElektronika GLCD Font Creator

here is example pawns as 16x16 font [variable width C code output new type ]
chars A,B,C,D have been mapped to black pawn on black square , black pawn on white square
and white pawn on black square , white pawn on white square



PAWNS.BAS



;//Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0;//MikroElektrnika 2011
;//http://www.mikroe.com


;//GLCD FontName : pawns16x16
;//GLCD FontSize : 16 x 16


;const unsigned short pawns16x16[] = {
goto overpawns
pawns:
@ db 0X00,0
@ db 0X41,0X00
@ db 0X44,0X00
@ db 0X10,0
@ db 0XF,0X18,0X00,0X00
@ db 0XF,0X38,0X00,0X00
@ db 0XF,0X58,0X00,0X00
@ db 0XF,0X78,0X00,0X00
@ db 0XC0,0X01,0X20,0X02,0X10,0X04,0X10,0X04,0X20,0X02, 0X40,0X01,0X78,0X0F,0X08,0X08,0X78,0X0F,0X40,0X01, 0X20,0X02,0X10,0X04,0X08,0X08,0XFC,0X1F,0X00,0X00, 0XFE,0X3F; // Code for char num 65
@ db 0XC0,0X01,0XE0,0X03,0XF0,0X07,0XF0,0X07,0XE0,0X03, 0XC0,0X01,0XF8,0X0F,0XF8,0X0F,0XF8,0X0F,0XC0,0X01, 0XE0,0X03,0XF0,0X07,0XF8,0X0F,0XFC,0X1F,0X00,0X00, 0XFE,0X3F; // Code for char num 66
@ db 0X3F,0XFE,0X1F,0XFC,0X0F,0XF8,0X0F,0XF8,0X1F,0XFC, 0X3F,0XFE,0X07,0XF0,0X07,0XF0,0X07,0XF0,0X3F,0XFE, 0X1F,0XFC,0X0F,0XF8,0X07,0XF0,0X03,0XE0,0XFF,0XFF, 0X01,0XC0; // Code for char num 67
@ db 0X3F,0XFE,0XDF,0XFD,0XEF,0XFB,0XEF,0XFB,0XDF,0XFD, 0XBF,0XFE,0X87,0XF0,0XF7,0XF7,0X87,0XF0,0XBF,0XFE, 0XDF,0XFD,0XEF,0XFB,0XF7,0XF7,0X03,0XE0,0XFF,0XFF, 0X01,0XC0; // Code for char num 68
; };
overpawns:

richard
- 20th December 2021, 03:17
http://www.picbasic.co.uk/forum/showthread.php?t=24218&p=147363#post147363

use ssd1306 code from here , it can use variable width fonts that do not have to be hand coded
makes life easy

i have a ver that can do bmp like images too if interested

Ioannis
- 20th December 2021, 08:55
Thank you very much. Your support and help is beyond words.

The selection of pixel columns and lines is really slow process. Seems you cannot numerically define lines and columns. Just adding one at a time waiting to complete.

Then, what are your settings for export?

Be blessed,
Ioannis

richard
- 20th December 2021, 09:36
step 1 create a font
9121
step 2 edit it to taste
9122
step 3 create blank include file
and export
9123
step 4 paste export in suitable format into include
9124

do some editing to get it to pbp format
remembering never allow a odd number of bytes on a line
never change order or number of data bytes to encode

Ioannis
- 20th December 2021, 09:47
OK, thanks!

Ioannis

richard
- 20th December 2021, 09:53
BEFORE AFTER EXAMPLE




'//Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0
'//MikroElektrnika 2011
'//http://www.mikroe.com


'//GLCD FontName : pawns16x12
'//GLCD FontSize : 16 x 12


'const unsigned short pawns16x12[] = {
' 0x00,
' 0x00,
' 0x41,0x00,
' 0x44,0x00,
' 0x0C,
' 0x00,
' 0x10,0x18,0x00,0x00,
' 0x0D,0x30,0x00,0x00,
' 0x0D,0x48,0x00,0x00,
' 0x0D,0x60,0x00,0x00,
' 0x00,0x00,0x80,0x03,0x80,0x0F,0xC0,0x1F,0xC0,0x1F, 0xE0,0x07,0x30,0x04,0x1C,0x0C,0x04,0x18,0x04,0x30, 0x02,0x60,0x03,0xC0, // Code for char num 65
' 0xF0,0x00,0x10,0x03,0x10,0x0D,0x10,0x19,0x10,0x11, 0x30,0x17,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // Code for char num 66
' 0x00,0x00,0x00,0x00,0xC0,0x0F,0x60,0x18,0x60,0x10, 0xD0,0x1F,0x10,0x00,0x70,0x02,0xC0,0x03,0x00,0x00, 0x00,0x00,0x00,0x00, // Code for char num 67
' 0x00,0x00,0x80,0x01,0x80,0x00,0x80,0x1C,0x00,0x15, 0x00,0x1F,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00 // Code for char num 68
' };




'//Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0
'//MikroElektrnika 2011
'//http://www.mikroe.com


'//GLCD FontName : pawns16x12
'//GLCD FontSize : 16 x 12


'const unsigned short pawns16x12[] = {
goto overpawns
pawns:
@ DB 0x00,0x00
@ DB 0X41,0x00
@ DB 0X44,0x00
@ DB 0X0C,0x00
@ DB 0X10,0x18,0x00,0x00
@ DB 0X0D,0x30,0x00,0x00
@ DB 0X0D,0x48,0x00,0x00
@ DB 0X0D,0x60,0x00,0x00
@ DB 0X00,0x00,0x80,0x03,0x80,0x0F,0xC0,0x1F,0xC0,0x1F, 0xE0,0x07,0x30,0x04,0x1C,0x0C,0x04,0x18,0x04,0x30, 0x02,0x60,0x03,0xC0' // Code for char num 65
@ DB 0XF0,0x00,0x10,0x03,0x10,0x0D,0x10,0x19,0x10,0x11, 0x30,0x17,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00' // Code for char num 66



@ DB 0X00,0x00,0x00,0x00,0xC0,0x0F,0x60,0x18,0x60,0x10, 0xD0,0x1F,0x10,0x00,0x70,0x02,0xC0,0x03,0x00,0x00, 0x00,0x00,0x00,0x00' // Code for char num 67
@ DB 0X00,0x00,0x80,0x01,0x80,0x00,0x80,0x1C,0x00,0x15, 0x00,0x1F,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00' // Code for char num 68
overpawns:





ps , for a chess board all chrs need to be same size , the font creator will optimize the shit out of your creations it hates blank columns on either edge
its a battle of wits .

this ver may make fonts easier to but up to each other


'************************************************* ******************
'* Name : grx.pbpmod *
'* Author : richard *
'* Notice : Copyright (c) 2021 *
'* : *
'* Date : 21/11/2021 *
'* Version : 1.0B ;BMP ADDED *
'* Notes : generic graphics suite for pic18 *
'* : 1 bit /pixel/colour *
'* : uses variable width fonts up to 23 bits wide *
'* : Generated by MikroElektronika GLCD Font Creator *
'* : *
'* : *
'************************************************* ******************


; TO MAKE AUTO FLIP OF DISP USE
' #DEFINE DISPFLIP 1
' #DEFINE colours 3 ;1 mono 2 rg or 3 rgb
' width con 64
' height con 16



;buffers
fbr var byte[width/8 * height] ;frame buffer r 4x8x16 pixels row 0 to 31 col 0 to 15
black con 0
red con 1
#if colours = 3

;buffers
fbb var byte[width/8 * height] ;frame buffer b 4x8x16 pixels row 0 to 31 col 0 to 15
fbg var byte[width/8 * height] ;frame buffer g 4x8x16 pixels row 0 to 31 col 0 to 15
ccc con 3
green con 2
yellow con 3
blue con 4
purple con 5
aqua con 6
white con 7
#endif
#if colours = 2

;buffers
fbg var byte[width/8 * height] ;frame buffer g 4x8x16 pixels row 0 to 31 col 0 to 15
ccc con 2
green con 2
yellow con 3
#endif
#if colours = 1
ccc con 1
#endif



dmd_bigaddress var byte[3] BANK0 ;ALLOWS 128K SAFE CONST STRS
fbsb var byte[width/8 * height * ccc ] ;output buffer in scan order
fpx var byte ;work regs
tmp var word ;work regs
' ----------- General use variables used -------------------
gl_x var byte
gl_y var byte
gl_i var word ' General loop counter
gl_l var word ' used in Line subroutine
gl_m var word ' used in Line subroutine
gl_byte var BYTE ' Graphic byte
gl_char var BYTE ' Text byte
g_char var BYTE
' ----- Circle constants and variables
gl_pi con 2
glc_x var word ' Calculation var
glc_y var word ' Calculation var
glc_s var WORD ' Slope
glc_cx var word ' Center x
glc_cy var word ' Center y
glc_r var word ' Radius
g_num var WORD
' ----- Line variables
gl_x1 var BYTE
gl_x2 var BYTE
gl_y1 var BYTE
gl_y2 var BYTE
gl_inc1 var WORD
gl_inc2 var WORD
' ----- Chart Variables
s_xstart var BYTE
s_xend var BYTE
s_ystart var BYTE
s_yend var BYTE
' s_tick var BYTE


;cga stuff
fontaddr var WORD ;work regs
foffset var WORD ;work regs
f_start var WORD ;work regs
f_end var WORD ;work regs
f_height var WORD ;work regs
fw VAR BYTE ;work regs width of last chr
fchb var byte[4] ;work regs
fchd var byte[4] ;work regs
fbp VAR BYTE ;work regs
fbo var WORD ;work regs
fbc VAR BYTE ;work regs
hght VAR BYTE ;work regs
fbrow VAR BYTE ;work regs
fbrc var byte ;work regs
fbfp VAR BYTE ;work regs
fbbpr VAR BYTE ;work regs
fbscn VAR word ;work regs
fbinx VAR BYTE ;work regs
fbpx VAR word ;work regs
dssh VAR BYTE ;work regs
x0 var BYTE ;work regs
x1 var BYTE ;work regs
y0 var BYTE ;work regs
y1 var BYTE ;work regs
BMPLABEL VAR word EXT
;user
fx VAR BYTE
fy VAR BYTE
fch VAR BYTE
colour VAR BYTE ;0-7
bgcolour VAR BYTE ;0-7

@BMPLABEL= _dmd_bigaddress

goto Jumpover_grx_Lib



USERCOMMAND "SETFONT" ;font must be located in first 64k block
USERCOMMAND "FILLRECT" ;X,Y,W,H
USERCOMMAND "DRAWRECT" ;X,Y,W,H
USERCOMMAND "DMDSTR" ;{X,Y},{buffer|const str}, {colour} is 128k safe
USERCOMMAND "DRAWLINE" ;X1,Y1,X2,Y2 , {colour}
USERCOMMAND "DRAWCIRCLE" ;X,Y,R
USERCOMMAND "DMDBMP" ;X,Y,LABEL







sfnt:
readcode fontaddr + 2,f_start
readcode fontaddr + 4,f_end
readcode fontaddr + 6,f_height
return


flip:
fbpx = width/8 * height - 1
while fbpx >width/8 * height/2-1
#if colours = 2
fbscn = fbg[fbpx] rev 8
#endif
fbrc = fbr[fbpx] rev 8
#if colours = 3
fbrow = fbb[fbpx] rev 8
#endif
#if colours = 2
fbg[fbpx] = fbg[width/8 * height - 1 - fbpx] rev 8
#endif
fbr[fbpx] = fbr[width/8 * height - 1 - fbpx] rev 8
#if colours = 3
fbb[fbpx] = fbb[width/8 * height - 1 - fbpx] rev 8
#endif
#if colours = 2
fbg[width/8 * height - 1 - fbpx] = fbscn
#endif
fbr[width/8 * height - 1 - fbpx] = fbrc

#if colours = 3
fbb[width/8 * height - 1 - fbpx] = fbrow
#endif
fbpx = fbpx - 1
wend
return


drawch: ;set fw to -1 if chr out of range or width of chr if successful
; needs h/w check
fw=-1
if ((fch<f_start)||(fch>f_end)) then return
readcode fontaddr + (Fch - f_start)*4 + 8 ,fw
readcode fontaddr + (Fch - f_start)*4 + 9 ,foffset
if (fx+fw) > width then
fw=-1
return
endif
for dssh = 0 to 3 ;fchb = ~0
fchb[dssh] = 255
next
fbp = fx//8
fbo = fy*width/8 + fx/8
for dssh = 1 to (31 - fw) ; fchb = fchb>>(32 - fw)
asm
bcf STATUS,0
banksel _fchb
rrcf _fchb +3
rrcf _fchb +2
rrcf _fchb +1
rrcf _fchb
banksel 0
endasm
next
for dssh = 1 to fbp ;fchb = fchb<<fbp;
asm
bcf STATUS,0
banksel _fchb
rlcf _fchb
rlcf _fchb +1
rlcf _fchb +2
rlcf _fchb +3
banksel 0
endasm
next
for dssh = 0 to 3 ; fchb = ~fchb
fchb[dssh] = ~fchb[dssh]
next
foffset = foffset
for fbc = 1 to f_height
for dssh = 0 to 3
fchd[dssh] = 0
next
for dssh=0 to fw/8
readcode fontaddr + foffset,fchd[dssh]
foffset = foffset + 1
next
for dssh = 1 to fbp ;fchd = fchd << fbp;
asm
bcf STATUS,0
banksel _fchd
rlcf _fchd
rlcf _fchd +1
rlcf _fchd +2
rlcf _fchd +3
banksel 0
endasm
next
fbr[fbo] = fbr[fbo]&fchb[0]
fbr[fbo+1] = fbr[fbo+1]&fchb[1]
fbr[fbo+2] = fbr[fbo+2]&fchb[2]
fbr[fbo+3] = fbr[fbo+3]&fchb[3]
#if colours <> 1
fbg[fbo] = fbg[fbo]&fchb[0]
fbg[fbo+1] = fbg[fbo+1]&fchb[1]
fbg[fbo+2] = fbg[fbo+2]&fchb[2]
fbg[fbo+3] = fbg[fbo+3]&fchb[3]
#endif
#if colours = 3
fbb[fbo] = fbb[fbo]&fchb[0]
fbb[fbo+1] = fbb[fbo+1]&fchb[1]
fbb[fbo+2] = fbb[fbo+2]&fchb[2]
fbb[fbo+3] = fbb[fbo+3]&fchb[3]
#endif
#if colours <> 1
if (bgcolour & 1) then
fbr[fbo] = fbr[fbo]|~fchb[0]
fbr[fbo+1] = fbr[fbo+1]|~fchb[1]
fbr[fbo+2] = fbr[fbo+2]|~fchb[2]
fbr[fbo+3] = fbr[fbo+3]|~fchb[3]
endif
if (bgcolour & 2) then
fbg[fbo] = fbg[fbo]|~fchb[0]
fbg[fbo+1] = fbg[fbo+1]|~fchb[1]
fbg[fbo+2] = fbg[fbo+2]|~fchb[2]
fbg[fbo+3] = fbg[fbo+3]|~fchb[3]
endif
#endif
#if colours = 3
if (bgcolour & 4) then
fbb[fbo] = fbb[fbo]|~fchb[0]
fbb[fbo+1] = fbb[fbo+1]|~fchb[1]
fbb[fbo+2] = fbb[fbo+2]|~fchb[2]
fbb[fbo+3] = fbb[fbo+3]|~fchb[3]
endif
#endif
if (colour &1)then
fbr[fbo] = fbr[fbo] | fchd[0]
fbr[fbo + 1] = fbr[fbo + 1]| fchd[1]
fbr[fbo + 2] = fbr[fbo + 2]| fchd[2]
fbr[fbo + 3] = fbr[fbo + 3]| fchd[3]
else
fbr[fbo] = fbr[fbo] & ~fchd[0]
fbr[fbo + 1] = fbr[fbo + 1]& ~fchd[1]
fbr[fbo + 2] = fbr[fbo + 2]& ~fchd[2]
fbr[fbo + 3] = fbr[fbo + 3]& ~fchd[3]
endif
#if colours <> 1
if (colour&2) then
fbg[fbo] = fbg[fbo] | fchd[0]
fbg[fbo + 1] = fbg[fbo + 1]| fchd[1]
fbg[fbo + 2] = fbg[fbo + 2]| fchd[2]
fbg[fbo + 3] = fbg[fbo + 3]| fchd[3]
else
fbg[fbo] = fbg[fbo] & ~fchd[0]
fbg[fbo + 1] = fbg[fbo + 1]& ~fchd[1]
fbg[fbo + 2] = fbg[fbo + 2]& ~fchd[2]
fbg[fbo + 3] = fbg[fbo + 3]& ~fchd[3]
endif
#endif
#if colours = 3
if (colour&4) then
fbb[fbo] = fbb[fbo] | fchd[0]
fbb[fbo + 1] = fbb[fbo + 1]| fchd[1]
fbb[fbo + 2] = fbb[fbo + 2]| fchd[2]
fbb[fbo + 3] = fbb[fbo + 3]| fchd[3]
else
fbb[fbo] = fbb[fbo] & ~fchd[0]
fbb[fbo + 1] = fbb[fbo + 1]& ~fchd[1]
fbb[fbo + 2] = fbb[fbo + 2]& ~fchd[2]
fbb[fbo + 3] = fbb[fbo + 3]& ~fchd[3]
endif
#endif
fbo = fbo + (width)/8
next
return

sbmp:
readcode BMPLABEL, fw ;width
readcode BMPLABEL+1 ,f_height ;height
DEBUG 13,10, HEX4 BMPLABEL ,9,#fw ,9,#f_height
foffset=2
f_height=f_height+Y0
' fw=(fw/16)-1
fw=(fw/8)-1
DEBUG 13,10
WHILE y0 < f_height
fbo = y0*width/8 + x0
DEBUG #Y0,9
for dssh = 0 to fw ;width
readcode BMPLABEL+foffset ,FBC'gl_inc1
DEBUG HEX2 FBC,9
fbr[fbo] = FBC REV 8
fbo=fbo+1
foffset=foffset+1
' fbr[fbo+1] =(gl_inc1>>8) REV 8
' fbr[fbo] = gl_inc1 REV 8
' fbo=fbo+2
' foffset=foffset+2
next
DEBUG 13,10
Y0=Y0+1
WEND
return

' void lcdBitmap(char x, char y, char w, char h, const char *bd) {
' char tm, bm, lastrow, row, col, db, rb, i = 0, pos;
' char *Findex;
' const char *Dindex;
' lastrow = ((y + h) / 8) - y / 8;
' for (row = 0; row <= lastrow; row++) {
' Findex = gFrame + (y / 8 + row)*84 + x;
' if (row == lastrow) {
' Dindex = bd + (row - 1) * w;
' pos = w;
' while (pos--) {
' db = *Dindex++;
' if (gMODE == 255)db = ~db;
' rb = *Findex;
' db = mask_b(rb, db, y + h);
' *Findex++ = db;
' }
' } else if (row == 0) {
' Dindex = bd;
' pos = w;
' while (pos--) {
' db = *Dindex++;
' if (gMODE == 255)db = ~db;
' rb = *Findex;
' db = mask_t(rb, db, y);
' *Findex++ = db;
' }
' } else {
' Dindex = bd + (row - 1) * w;
' pos = w;
' while (pos--) {
' db = *Dindex++;
' if (gMODE == 255)db = ~db;
' rb = *Findex;
' db = mask_b(rb, db, y);
' *Findex++ = db;
' }
' Findex = gFrame + (y / 8 + row)*84 + x;
' Dindex = bd + row*w;
' pos = w;
' while (pos--) {
' db = *Dindex++;
' if (gMODE == 255)db = ~db;
' rb = *Findex;
' db = mask_t(rb, db, y);
' *Findex++ = db;
' }
' }
' }
'}


gl_setdot: 'Set a pixel to colour given gl_x,gl_y
; clrs pixels colours not selected
fpx = 1<< (gl_x//8)
fbo = gl_y* (width)/8 + gl_x/ 8
if (colour & 1)then
fbr[ fbo ] = fbr[ fbo ]|fpx
else
fbr[ fbo ] = fbr[ fbo ]&~fpx
endif
#IF colours <> 1
if (colour & 2)then
fbg[ fbo ] = fbg[ fbo ]|fpx
else
fbg[ fbo ] = fbg[ fbo ]&~fpx
endif
#endif
#if colours = 3
if (colour & 4)then
fbb[ fbo ] = fbb[ fbo ]|fpx
else
fbb[ fbo ] = fbb[ fbo ]&~fpx
endif
#endif
return


grf_clr:
tmp = width/8 * height
while tmp
tmp = tmp - 1
if bgcolour then
if bgcolour & 1 then fbr[tmp] = 255
#if colours = 2
if bgcolour & 2 then fbg[tmp] = 255
#endif
#if colours = 3
if bgcolour & 4 then fbb[tmp] = 255
#endif
else
fbr[tmp] = 0
#if colours = 2
fbg[tmp] = 0
#endif
#if colours = 3
fbb[tmp] = 0
#endif
endif
wend
return


set8: ;seems ok
gl_x = glc_x+glc_cx : gl_y=glc_y+glc_cy '1
gosub gl_setdot
gl_x = glc_cx-glc_x : gl_y=glc_y+glc_cy '2
gosub gl_setdot
gl_x = glc_cx+glc_x : gl_y=glc_cy-glc_y '3
gosub gl_setdot
gl_x = glc_cx-glc_x : gl_y=glc_cy-glc_y '4
gosub gl_setdot
gl_x = glc_y+glc_cx : gl_y=glc_x+glc_cy '5
gosub gl_setdot
gl_x = glc_cx-glc_y : gl_y=glc_cy+glc_x '6
gosub gl_setdot
gl_x = glc_cx+glc_y : gl_y=glc_cy-glc_x '7
gosub gl_setdot
gl_x = glc_cx-glc_y : gl_y=glc_cy-glc_x '8
gosub gl_setdot
return


'------------ gl_circle d = diameter r = radius x,y are point locations ----------
'***** Given Center = glc_cx,glc_cy and Radius = glc_r ***
d_circ: ;seems ok
glc_x = 0
glc_y = glc_r
glc_s = gl_pi-2*glc_r
while (glc_x <= glc_y)
gosub set8
if (glc_s.15 =1) then
glc_s = glc_s + (4*glc_x + 6)
else
glc_s = glc_s + (4*(glc_x-glc_y) + 10)
glc_y = glc_y - 1
endif
glc_x = glc_x + 1
wend
return


'----------------- 4 sided Star ---------------------
'***** Given Center = gl_cx,gl_cy and Radius = gl_r **********
d_star4: ;sus r must be ? 3 and multiple of 3
glc_x = 0
glc_y = glc_r
glc_s = gl_pi-2*glc_r
while (glc_x <= glc_y)
gosub set8
glc_s = glc_s + (4*(glc_x-glc_y) + 10)
glc_y = glc_y - 3
glc_x = glc_x + 1
wend
return


drect:
gl_x2 = gl_x1+x1
gl_y2 = gl_y1+y1-1
gl_rect: 'Rectangle subroutine given gl_x1,gl_x2,gl_y1, gl_y2
gosub chk_xy
for gl_i= gl_x1 to gl_x2
gl_x = gl_i
gl_y = gl_y1
gosub gl_setdot
gl_y = gl_y2
gosub gl_setdot
next gl_i
for gl_i= gl_y1 to gl_y2
gl_y = gl_i
gl_x = gl_x1
gosub gl_setdot
gl_x = gl_x2
gosub gl_setdot
next gl_i
return


'*** gl_gl_square45 turned 45 degrees ***
'***** Given Center = gl_cx,gl_cy and Radius = gl_r *
d_square45: ;seems ok
glc_x = 0
glc_y = glc_r
glc_s = gl_pi-2*glc_r
while (glc_x <= glc_y)
gosub set8
glc_s = glc_s + (4*(glc_x-glc_y) + 10)
glc_y = glc_y - 1
glc_x = glc_x + 1
wend
return
chk_xy: ;seems ok
if gl_x1 > gl_x2 then
swap gl_x1,gl_x2
endif
if gl_y1 > gl_y2 then
swap gl_y1,gl_y2
endif
return




dline:
gl_inc1 = 0
if abs(s_yend - s_ystart) > abs(s_xend - s_xstart) then
swap s_xstart , s_ystart
swap s_xend , s_yend
gl_inc1 = 1
endif
if s_xstart > s_xend then
swap s_xstart , s_xend
swap s_ystart , s_yend
endif
gl_inc2 = s_xend - s_xstart
gl_l = abs(s_yend - s_ystart )
glc_s = gl_inc2.15
gl_m = abs(gl_inc2)/2
if glc_s then gl_m = -gl_m
if s_ystart < s_yend then
glc_s = 1
else
glc_s = -1
endif
while s_xstart <= s_xend
if gl_inc1>0 then
gl_x = s_ystart
gl_y = s_xstart
gosub gl_setdot
else
gl_x = s_xstart
gl_y = s_ystart
gosub gl_setdot
endif
gl_m = gl_m - gl_l
if gl_m.15 = 1 then
s_ystart = s_ystart + glc_s
gl_m = gl_m + gl_inc2
endif
s_xstart = s_xstart + 1
wenD
return












'dline:
' gl_inc1=0
' if abs(s_yend - s_ystart) > abs(s_xend - s_xstart) then
' gl_m = s_xstart;
' s_xstart = s_ystart;
' s_ystart = gl_m;
' gl_m = s_xend;
' s_xend = gl_y2;
' s_yend= gl_m;
' gl_inc1 = 1;
' endif
' if s_xstart > s_xend then
' gl_m = s_xstart;
' s_xstart = s_xend;
' s_xend = gl_m;
' gl_m = s_ystart;
' s_ystart = gl_y2;
' s_yend= gl_m;
' endif
' gl_inc2 = s_xend - s_xstart;
' gl_l = abs(s_yend- s_ystart);
' glc_s = gl_inc2.15
' gl_m = abs(gl_inc2) / 2;
' if glc_s then gl_m = ~gl_m;
' if s_ystart < s_yend then
' glc_s = 1;
' else
' glc_s = -1;
' endif
' while s_xstart <= s_xend
' if gl_inc1 > 0 then
' gl_x = s_ystart : gl_y= s_xstart
' else
' gl_x = s_xstart : gl_y= s_ystart
' endif
' gosub gl_setdot
' gl_m = gl_m - gl_l;
' if gl_m.15 then
' s_ystart = s_ystart+glc_s;
' gl_m = gl_m+gl_inc2;
' endif
' s_xstart = s_xstart +1;
' wend
'return










frect:
s_ystart=y0
s_yend=y0
while y1
s_xstart=x0
s_xend=x0+s_xend-1
gosub dLine
s_ystart=s_ystart+1
s_yend=s_ystart
y1=y1-1
wend
return






ASM
dmd_pmstr_out
tblrd *+
movf TABLAT,w
bz dmd_exit_pmstrout ; EXIT ON Null char
banksel _fch
MOVWF _fch
banksel 0
movff TBLPTRU,_dmd_bigaddress
movff TBLPTRH,_dmd_bigaddress+1
movff TBLPTRL,_dmd_bigaddress+2
L?CALL _drawch
banksel _fw
movf _fw, W
bn dmd_exit_pmstrout
banksel _fx
addwf _fx,f
incf _fx,f
banksel 0
movff _dmd_bigaddress ,TBLPTRU
movff _dmd_bigaddress+1 ,TBLPTRH
movff _dmd_bigaddress+2 ,TBLPTRL
bra dmd_pmstr_out
dmd_exit_pmstrout
RST?RP
return

dmd_str_out
movf POSTINC1, W ; Get a character
bz dmd_exit_strout ; EXIT ON Null char
banksel _fch
MOVWF _fch
banksel 0
L?CALL _drawch
banksel _fw
movf _fw, W
bn dmd_exit_strout
banksel _fx
addwf _fx,f
incf _fx,f
bra dmd_str_out
dmd_exit_strout
banksel 0
return


DMDBMP?CCL macro X0in ,Y0in,Lin
;MOVE?CW Lin , _dmd_bigaddress
MOVE?CB X0in ,_x0
MOVE?CB Y0in ,_y0
BANKSEL _dmd_bigaddress
movlw UPPER Lin
movwf _dmd_bigaddress+2
movlw HIGH Lin
movwf _dmd_bigaddress+1
movlw LOW Lin
movwf _dmd_bigaddress
BANKSEL 0
L?CALL _sbmp
endm




SETFONT?L macro Lin
MOVE?CW Lin , _fontaddr
L?CALL _sfnt
endm
FILLRECT?WWWW macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_x0
MOVE?WB X1in ,_x1
MOVE?WB Y0in ,_y0
MOVE?WB Y1in ,_y1
L?CALL _frect
endm
FILLRECT?WWBW macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_x0
MOVE?BB X1in ,_x1
MOVE?WB Y0in ,_y0
MOVE?WB Y1in ,_y1
L?CALL _frect
endm


FILLRECT?WWBB macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_x0
MOVE?BB X1in ,_x1
MOVE?WB Y0in ,_y0
MOVE?BB Y1in ,_y1
L?CALL _frect
endm
FILLRECT?WWCC macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_x0
MOVE?CB X1in ,_x1
MOVE?WB Y0in ,_y0
MOVE?CB Y1in ,_y1
L?CALL _frect
endm
FILLRECT?WWWB macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_x0
MOVE?WB X1in ,_x1
MOVE?WB Y0in ,_y0
MOVE?BB Y1in ,_y1
L?CALL _frect
endm
FILLRECT?BBBB macro X0in ,Y0in ,X1in ,Y1in
MOVE?BB X0in ,_x0
MOVE?BB X1in ,_x1
MOVE?BB Y0in ,_y0
MOVE?BB Y1in ,_y1
L?CALL _frect
endm
FILLRECT?CCCC macro X0in ,Y0in ,X1in ,Y1in
MOVE?CB X0in , _x0
MOVE?CB X1in , _x1
MOVE?CB Y0in, _y0
MOVE?CB Y1in, _y1
L?CALL _frect
endm
FILLRECT?BBCC macro X0in ,Y0in ,X1in ,Y1in
MOVE?BB X0in , _x0
MOVE?CB X1in , _x1
MOVE?BB Y0in , _y0
MOVE?CB Y1in, _y1
L?CALL _frect
endm
;dr
DRAWRECT?WWWW macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_gl_x1
MOVE?WB X1in ,_x1
MOVE?WB Y0in ,_gl_y1
MOVE?WB Y1in ,_y1
L?CALL _drect
endm
DRAWRECT?WWBW macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_gl_x1
MOVE?BB X1in ,_x1
MOVE?WB Y0in ,_gl_y1
MOVE?WB Y1in ,_y1
L?CALL _drect
endm


DRAWRECT?WWBB macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_gl_x1
MOVE?BB X1in ,_x1
MOVE?WB Y0in ,_gl_y1
MOVE?BB Y1in ,_y1
L?CALL _drect
endm
DRAWRECT?WWCC macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_gl_x1
MOVE?CB X1in ,_x1
MOVE?WB Y0in ,_gl_y1
MOVE?CB Y1in ,_y1
L?CALL _drect
endm
DRAWRECT?WWWB macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_gl_x1
MOVE?WB X1in ,_x1
MOVE?WB Y0in ,_gl_y1
MOVE?BB Y1in ,_y1
L?CALL _drect
endm
DRAWRECT?BBBB macro X0in ,Y0in ,X1in ,Y1in
MOVE?BB X0in ,_gl_x1
MOVE?BB X1in ,_x1
MOVE?BB Y0in ,_gl_y1
MOVE?BB Y1in ,_y1
L?CALL _drect
endm
DRAWRECT?CCCC macro X0in ,Y0in ,X1in ,Y1in
MOVE?CB X0in ,_gl_x1
MOVE?CB X1in ,_x1
MOVE?CB Y0in ,_gl_y1
MOVE?CB Y1in ,_y1
L?CALL _drect
endm
DRAWRECT?BBCC macro X0in ,Y0in ,X1in ,Y1in
MOVE?BB X0in ,_gl_x1
MOVE?CB X1in ,_x1
MOVE?BB Y0in ,_gl_y1
MOVE?CB Y1in ,_y1
L?CALL _drect
endm
;CIRC
DRAWCIRCLE?WWW macro X0in ,Y0in ,Rad
MOVE?WW X0in , _glc_cx
MOVE?WW Rad , _glc_r
MOVE?WW Y0in , _glc_cy
L?CALL _d_circ
endm
DRAWCIRCLE?WWB macro X0in ,Y0in ,Rad
MOVE?WW X0in , _glc_cx
MOVE?BW Rad , _glc_r
MOVE?WW Y0in , _glc_cy
L?CALL _d_circ
endm
DRAWCIRCLE?WWC macro X0in ,Y0in ,Rad
MOVE?WW X0in , _glc_cx1
MOVE?CW Rad , _glc_r
MOVE?WW Y0in , _glc_cy1
L?CALL _d_circ
endm

DRAWCIRCLE?BBB macro X0in ,Y0in ,Rad
MOVE?BW X0in , _glc_cx
MOVE?BW Rad , _glc_r
MOVE?BW Y0in , _glc_cy
L?CALL _d_circ
endm
DRAWCIRCLE?CCC macro X0in ,Y0in ,Rad
MOVE?CW X0in , _glc_cx
MOVE?CW Rad , _glc_r
MOVE?CW Y0in , _glc_cy
L?CALL _d_circ
endm
DRAWCIRCLE?BBC macro X0in ,Y0in ,Rad
MOVE?BW X0in , _glc_cx
MOVE?CW Rad , _glc_r
MOVE?BW Y0in , _glc_cy
L?CALL _d_circ
endm
;LINE
DRAWLINE?WWWW macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_s_xstart
MOVE?WB X1in ,_s_xend
MOVE?WB Y0in ,_s_ystart
MOVE?WB Y1in ,_s_yend
L?CALL _dline
endm
DRAWLINE?WWBW macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_s_xstart
MOVE?BB X1in ,_s_xend
MOVE?WB Y0in ,_s_ystart
MOVE?WB Y1in ,_s_yend
L?CALL _dline
endm
DRAWLINE?WWBB macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_s_xstart
MOVE?BB X1in ,_s_xend
MOVE?WB Y0in ,_s_ystart
MOVE?BB Y1in ,_s_yend
L?CALL _dline
endm
DRAWLINE?WWCC macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_s_xstart
MOVE?CB X1in ,_s_xend
MOVE?WB Y0in ,_s_ystart
MOVE?CB Y1in ,_s_yend
L?CALL _dline
endm
DRAWLINE?WWWB macro X0in ,Y0in ,X1in ,Y1in
MOVE?WB X0in ,_s_xstart
MOVE?WB X1in ,_s_xend
MOVE?WB Y0in ,_s_ystart
MOVE?BB Y1in ,_s_yend
L?CALL _dline
endm
DRAWLINE?BBBB macro X0in ,Y0in ,X1in ,Y1in
MOVE?BB X0in ,_s_xstart
MOVE?BB X1in ,_s_xend
MOVE?BB Y0in ,_s_ystart
MOVE?BB Y1in ,_s_yend
L?CALL _dline
endm
DRAWLINE?CCCC macro X0in ,Y0in ,X1in ,Y1in
MOVE?CB X0in ,_s_xstart
MOVE?CB X1in ,_s_xend
MOVE?CB Y0in ,_s_ystart
MOVE?CB Y1in ,_s_yend
L?CALL _dline
endm
DRAWLINE?CCCB macro X0in ,Y0in ,X1in ,Y1in
MOVE?CB X0in ,_s_xstart
MOVE?CB X1in ,_s_xend
MOVE?CB Y0in ,_s_ystart
MOVE?BB Y1in ,_s_yend
L?CALL _dline
endm
DRAWLINE?CCCW macro X0in ,Y0in ,X1in ,Y1in
MOVE?CB X0in ,_s_xstart
MOVE?CB X1in ,_s_xend
MOVE?CB Y0in ,_s_ystart
MOVE?WB Y1in ,_s_yend
L?CALL _dline
endm
DRAWLINE?BBCC macro X0in ,Y0in ,X1in ,Y1in
MOVE?BB X0in ,_s_xstart
MOVE?CB X1in ,_s_xend
MOVE?BB Y0in ,_s_ystart
MOVE?CB Y1in ,_s_yend
L?CALL _dline
endm
DRAWLINE?CCCCC macro X0in ,Y0in ,X1in ,Y1in,Col
MOVE?CB Col ,_colour
MOVE?CB X0in ,_s_xstart
MOVE?CB X1in ,_s_xend
MOVE?CB Y0in ,_s_ystart
MOVE?CB Y1in ,_s_yend
L?CALL _dline
endm

;----------------------Strings------------------------------------
DMDSTR?CBB macro Xin ,Yin ,Bin
MOVE?CB Xin ,_fx
MOVE?BB Yin ,_fy
MOVE?CB high Bin, FSR1H ;load highbyte
MOVE?CB low Bin, FSR1L ;load low byte
L?CALL dmd_str_out
endm
DMDSTR?CCB macro Xin ,Yin ,Bin
MOVE?CB Xin ,_fx
MOVE?CB Yin ,_fy
MOVE?CB high Bin, FSR1H ;load highbyte
MOVE?CB low Bin, FSR1L ;load low byte
L?CALL dmd_str_out
endm
DMDSTR?CCBC macro Xin ,Yin ,Bin,Col
MOVE?CB Xin ,_fx
MOVE?CB Yin ,_fy
MOVE?CB Col ,_colour
MOVE?CB high Bin, FSR1H ;load highbyte
MOVE?CB low Bin, FSR1L ;load low byte
L?CALL dmd_str_out
endm
DMDSTR?BBB macro Xin ,Yin ,Bin
MOVE?BB Xin,_fx
MOVE?BB Yin,_fy
MOVE?CB high (Bin), FSR1H ;load highbyte
MOVE?CB low (Bin), FSR1L ;load low byte
L?CALL dmd_str_out
endm
DMDSTR?WBB macro Xin ,Yin ,Bin
MOVE?WB Xin,_fx
MOVE?BB Yin,_fy
MOVE?CB high (Bin), FSR1H ;load highbyte
MOVE?CB low (Bin), FSR1L ;load low byte
L?CALL dmd_str_out
endm
DMDSTR?WWB macro Xin ,Yin ,Bin
MOVE?WB Xin,_fx
MOVE?WB Yin,_fy
MOVE?CB high (Bin), FSR1H ;load highbyte
MOVE?CB low (Bin), FSR1L ;load low byte
L?CALL dmd_str_out
endm
;----[const String]---------------------------------------------------------------
DMDSTR?S macro Cin
local TheString, OverStr
goto OverStr
TheString
data Cin, 0
OverStr
movlw UPPER TheString
movwf TBLPTRU
movlw HIGH TheString
movwf TBLPTRH
movlw LOW TheString
movwf TBLPTRL
L?CALL dmd_pmstr_out
endm
DMDSTR?CCS macro Xin ,Yin, Cin
local TheString, OverStr
goto OverStr
TheString
data Cin, 0
OverStr
MOVE?CB Xin ,_fx
MOVE?CB Yin ,_fy
movlw UPPER TheString
movwf TBLPTRU
movlw HIGH TheString
movwf TBLPTRH
movlw LOW TheString
movwf TBLPTRL
L?CALL dmd_pmstr_out
endm
DMDSTR?CCSC macro Xin ,Yin,Bin,Col
local TheString, OverStr
goto OverStr
TheString
data Bin, 0
OverStr
MOVE?CB Xin ,_fx
MOVE?CB Yin ,_fy
MOVE?CB Col ,_colour
movlw UPPER TheString
movwf TBLPTRU
movlw HIGH TheString
movwf TBLPTRH
movlw LOW TheString
movwf TBLPTRL
L?CALL dmd_pmstr_out
endm


ENDASM


Jumpover_grx_Lib:

Ioannis
- 23rd December 2021, 20:59
It seems that ssd1306_i2c.inc file is not compatible with 18F4550 in regard I2C routines. Either hardware I2C because SSPCON3 does not exist or in software IC2 because SSP1STAT, SSP1CON2 do not exist also.

I am very reluctant to touch the include file, so any idea how to handle this please?

I just used software I2C finally and commented out the two lines that had the problem. Then it compiled OK and first time I got the demo text on the tiny LCD! Is it safe what I did?

Ioannis

richard
- 24th December 2021, 00:23
not sure what you are trying to do
but ssd1306_18.inc is needed for pic 18 along with font7x5_18.bas
that system is a "light version" it has a fixed 5x7 width, the only way to change the font size is to alter the include


the other version "grx.pbpmod" is more generic, pic18 only and uses variable width fonts and has drivers for multiple display types

Ioannis
- 24th December 2021, 09:24
Well, lets clear what I 've done so far. Just received my OLED display and started to experiment.

At the start of this thread there were the initial files. Downloaded to a folder.
Post #2 had and update so I replaced the ssd1306_18.inc with the ssd1306_I2C.inc that says on top of this file, it is for PIC16/18. Is this wrong?

Replaced again from post #15

And again with that from post #41 (after Henrik's posts).

So, the final test was done on a 18F4550 chip, with a 64x128 oled LCD, soft I2C and files sd1306_demo.pbp, font7x5_18.bas and latest ssd1306_I2C.inc from post #41.

Nothing else added or changed.

After compilation errors, I selected soft I2C and commented out the lines in the include file that referred to SSP1STAT, SSP1CON2 and got the demo message on screen.

Also as a second step, have not sorted out how, the font file that will be created, is working with the main program. I mean, OK there is a new character. How is this chosen to be displayed?

Ioannis

P.S. By the way, the font include files, what do describe? It seems not fonts anyway.

richard
- 24th December 2021, 10:15
So, the final test was done on a 18F4550 chip, with a 64x128 oled LCD, soft I2C and files sd1306_demo.pbp, font7x5_18.bas and latest ssd1306_I2C.inc from post #41.
sorry I'm lost, i need to restore some old backup files to get back to speed with this.
i forgot i did actually make a 16/18 version, i have not used that pbp code for quite sometime and my laptop that
held all that code died bigtime. i only use the grx.pbpmod ver or C ver these days, so i'm a bit rusty on the old pbp stuff.

the old code should work with a 18F4550 and the pic18 font posted with hw or soft i2c, the new font format previously discussed will not work with this code
as it stands. i do have a 18F4550 proto board so i could check it out. post the whole lot, includes too i have lost most of the originals and am not absolutely sure we have the same thing.
i would just the new code.

Ioannis
- 24th December 2021, 10:29
OK. Later I will do that. But all what I described is from this thread starting from post #1 and on.

Ioannis

richard
- 24th December 2021, 10:47
i see the prob

4550 has only 1 mssp try this


'************************************************* ***************'* Name : ssd1306_I2C.INC *
'* Author : richard *
'* Notice : *
'* : *
'* Date : 7/5/2018 *
'* Version : 1.1 *
'* Notes : const str added for pic16 *
'* :FOR pic 16/18 SSD1306 *
'************************************************* ***************

goto overglcd
; adjust to suit and place these in main prg
;use this define for hw i2c
;#define hwi2c 1
;#DEFINE PIC16 1 ;IF PIC 16 USED [USE PIC16 FONT TOO}
' ssdheight con 7 ; 7 = 8 PAGES 64*128 , 3 = 4 pages 32*128
' ssdwidth con 127 ; 128 PIXELS WIDE
' SCL var PortC.3 ' I2C Clock
' SDA var PortC.4 ' I2C Data
' sdd1306_addr con $78

USERCOMMAND "GLCDC" ; X,Y,CHR 0 < X < 127 , 0 < Y < 7 31 < CHR > 127
USERCOMMAND "GLCD_CLR" ;clear area x,y,W,H
USERCOMMAND "GLCDSTR" ;STRING @ X,Y or Constant String
USERCOMMAND "GLCDDHL" ; x,y,L ,bit-patten
USERCOMMAND "GLCDDVL" ; x,y,H
USERCOMMAND "SSDC" ;cmd BYTE TO SSD1306
USERCOMMAND "SSDBM" ;x,y,w,h,label


ASM


;----------------------VERT LINE------------------------------------
GLCDDVL?CCC macro Xin ,Yin , Hin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Hin ,_gl
L?CALL _xyy
endm

;----------------------HORIZ LINE------------------------------------
GLCDDHL?CCCC macro Xin ,Yin , Win ,Cin
MOVE?CB Xin ,_gx
MOVE?CB Yin,_gy
MOVE?CB Win ,_gl
MOVE?CB Cin ,_glcdData
L?CALL _xyx
endm

;----[const String]---------------------------------------------------------------
GLCDSTR?CCS macro Xin ,Yin,Cin
IFNDEF TBLPTRL
local TheString, OverStr ; define local labels so you can call macro multiple times
goto OverStr ; goto over string stored in FLASH, so processor can't execute that
TheString ;label to get address of your string
da Cin, 0 ;add string to flash at TheString address and end string with 0
OverStr
MOVE?CW TheString, _glcd_bigaddress
MOVE?CB Xin , _gx
MOVE?CB Yin , _gy
L?GOTO _GlcdUnpackStr
ELSE
local TheString, OverStr ; define local labels so you can call macro multiple times
goto OverStr ; goto over string stored in FLASH, so processor can't execute that
TheString ;label to get address of your string
data Cin, 0 ;add string to flash at TheString address and end string with 0
OverStr
movlw UPPER TheString
movwf TBLPTRU
movlw HIGH TheString
movwf TBLPTRH
movlw LOW TheString
movwf TBLPTRL
MOVE?CB Xin , _gx
MOVE?CB Yin , _gy
L?CALL GLCD_Cstr_out
ENDIF
endm


SSDBM?CCCCL macro Xin ,Yin ,Win,Hin,BMin
IFNDEF TBLPTRL
ERROR BITMAPS ONLY SUPPORTED ON PIC18
ENDIF
MOVE?CB Xin , _gx
MOVE?CB Yin , _gy
MOVE?CB Hin/8-1 , _gy_
MOVE?CB Win+Xin-1 , _gx_
MOVE?CW Win*Hin/8 , _glcd_rad
banksel _glcdbm
movlw low BMin
movwf _glcdbm
movlw high BMin
movwf _glcdbm +1
BANKSEL 0
L?CALL _ssd_bitmap
endm




;----------------------Strings------------------------------------
GLCDSTR?CBB macro Xin ,Yin ,Bin
MOVE?CB Xin , _gx
MOVE?BB Yin , _gy
MOVE?CB high Bin, FSR1H ;load highbyte
MOVE?CB low Bin, FSR1L ;load low byte
L?CALL GLCD_str_out
endm
GLCDSTR?CCB macro Xin ,Yin ,Bin
MOVE?CB Xin , _gx
MOVE?CB Yin ,_gy
MOVE?CB high (Bin), FSR1H ;load highbyte
MOVE?CB low (Bin), FSR1L ;load low byte
L?CALL GLCD_str_out
endm
GLCDSTR?BBB macro Xin ,Yin ,Bin
MOVE?B Xin, _gx
MOVE?B Yin, _gy
MOVE?CB high Bin, FSR1H ;load highbyte
MOVE?CB low Bin, FSR1L ;load low byte
L?CALL GLCD_str_out
endm
GLCDSTR?WBB macro Xin ,Yin ,Bin
MOVE?WB Xin, _gx
MOVE?BB Yin, _gy
MOVE?CB high Bin, FSR1H ;load highbyte
MOVE?CB low Bin, FSR1L ;load low byte
L?CALL GLCD_str_out
endm
GLCDSTR?WWB macro Xin ,Yin ,Bin
MOVE?WB Xin, _gx
MOVE?WB Yin, _gy
MOVE?CB high Bin, FSR1H ;load highbyte
MOVE?CB low Bin, FSR1L ;load low byte
L?CALL GLCD_str_out
endm


SSDC?C macro Cin
MOVE?CB Cin , _glcdData
L?CALL _cmd_byte
endm
SSDC?B macro Cin
MOVE?BB Cin , _glcdData
L?CALL _cmd_byte
endm


GLCD_CLR? macro
MOVE?CB 0, _gx
MOVE?CB 0, _gy
MOVE?CB _ssdwidth, _gx_
MOVE?CB _ssdheight, _gy_
L?CALL _glcd_clrxy
endm


GLCD_CLR?CCCC macro Xin ,Yin,X1in ,Y1in
MOVE?CB Xin, _gx
MOVE?CB Yin, _gy
MOVE?CB X1in, _gx_
MOVE?CB Y1in, _gy_
L?CALL _glcd_clrxy
endm

;----------------------Character @ X,Y ------------------------------------
GLCDC?BBB macro Xin ,Yin , Bin
MOVE?BB Xin, _gx
MOVE?BB Yin, _gy
MOVE?BB Bin, _glcdCh
L?CALL _gcga
endm
GLCDC?WBB macro Xin ,Yin , Bin
MOVE?WB Xin, _gx
MOVE?BB Yin, _gy
MOVE?BB Bin, _glcdCh
L?CALL _gcga
endm
GLCDC?WWB macro Xin ,Yin , Bin
MOVE?WB Xin, _gx
MOVE?WB Yin, _gy
MOVE?BB Bin, _glcdCh
L?CALL _gcga
endm

GLCDC?BBC macro Xin ,Yin , Cin
MOVE?BB Xin, _gx
MOVE?BB Yin, _gy
MOVE?CB Cin ,_glcdCh
L?CALL _gcga
endm
GLCDC?WBC macro Xin ,Yin , Cin
MOVE?WB Xin, _gx
MOVE?BB Yin, _gy
MOVE?CB Cin ,_glcdCh
L?CALL _gcga
endm
GLCDC?CCC macro Xin ,Yin ,Cin
MOVE?CB Xin , _gx
MOVE?CB Yin, _gy
MOVE?CB Cin, _glcdCh
L?CALL _gcga
endm
GLCDC?CCB macro Xin ,Yin ,Bin
MOVE?CB Xin , _gx
MOVE?CB Yin, _gy
MOVE?BB Bin, _glcdCh
L?CALL _gcga
endm




GLetAddress macro Label, Wout
CHK?RP Wout
movlw low Label ; get low byte
movwf Wout
movlw High Label ; get high byte
movwf Wout + 1
BANKSEL 0
endm

IFDEF TBLPTRL

GLCD_Cstr_out
tblrd *+
movf TABLAT,w
bz GLCD_exit_Cstr_out ; EXIT ON Null char
CHK?RP _glcdCh
MOVWF _glcdCh
CHK?RP _glcd_bigaddress
movff TBLPTRU,_glcd_bigaddress
movff TBLPTRH,_glcd_bigaddress+1
movff TBLPTRL,_glcd_bigaddress+2
L?CALL _gcga
CHK?RP _glcd_bigaddress
movff _glcd_bigaddress ,TBLPTRU
movff _glcd_bigaddress+1 ,TBLPTRH
movff _glcd_bigaddress+2 ,TBLPTRL
bra GLCD_Cstr_out
GLCD_exit_Cstr_out
BANKSEL 0
return




GLCD_str_out
movf POSTINC1, W ; Get a character
bz GLCD_exit_strout ; EXIT ON Null char
CHK?RP _glcdCh
MOVWF _glcdCh
BANKSEL 0
L?CALL _gcga
bra GLCD_str_out
GLCD_exit_strout
BANKSEL 0
return
ELSE



GLCD_str_out
IFDEF BSR
MOVIW FSR1++ ; Get a character
BTFSC STATUS,Z
BRA GLCD_exit_strout ; EXIT ON Null char
ELSE
movf INDF, W ; Get a character
BTFSC STATUS,Z
GOTO GLCD_exit_strout ; EXIT ON Null char
INCF FSR,F
ENDIF
CHK?RP _glcdCh
MOVWF _glcdCh
MOVE?BB FSR1L,_glcd_bigaddress
MOVE?BB FSR1H,_glcd_bigaddress+1
BANKSEL 0
L?CALL _gcga
MOVE?BB _glcd_bigaddress,FSR1L
MOVE?BB _glcd_bigaddress+1,FSR1H
GOTO GLCD_str_out
GLCD_exit_strout
BANKSEL 0
return
ENDIF
endasm

glcd_bigaddress VAR BYTE[3]
glcd_buff VAR BYTE[32]
BIG_TEXT var byte
glcd_rad var word
glcdCh var byte 'chr DATA
glcdData VAR byte 'DATA
glcdBC VAR word 'gca var
glcdDC VAR BYTE 'gca var
glcdFont var word 'font address
glcdOffset VAR word 'font offset
glcdbm VAR word 'bitmap offset
gl var byte 'width/height
gy var byte 'gca pg address
gy_ var byte 'gca pg address
gx var byte 'gca row address
gx_ var byte 'gca row address
GRX var byte 'DATA
ctemp var word
ctemp1 var word
ssd_add var byte
glcdStrAddr var word ext
@glcdStrAddr = _glcd_bigaddress


GlcdUnpackStr:
readcode glcdStrAddr,CTEMP
glcd_bigaddress[2] = CTEMP&$7f
ctemp=ctemp<<1
glcdCh = CTEMP.HIGHBYTE
glcdStrAddr=glcdStrAddr+1
if glcdCh then
gosub gcga
glcdCh = glcd_bigaddress[2]
else
return
endif
if glcdCh then
gosub gcga
else
return
endif
goto GlcdUnpackStr:
return



glcd_init:
#ifdef hwi2c
SSPSTAT = 0 'High Speed Filter
SSPADD = $13'400 kHz @32 MHz
SSPCON1 = %00101000 'I2C Master Mode Enable
' SSPCON3 = 0

#endif
@ GLetAddress _font7x5,_glcdFont
ssd_add = sdd1306_addr
SSDc $AE ' Display OFF
SSDc $d5
SSDc $80
SSDc $a8 : SSDc $3f
SSDc $D3 : SSDc $00 ; Set Display Offset Mode Set 0
if ssdheight > 3 then
SSDc $40 ' Set display start line 0
else
SSDc $60 ' Set display start line 4
endif
SSDc $8D : SSDc $14 ' Set Charge Pump Internal
SSDc $20 : SSDc $00 ' Adressing mode Horizontal
SSDc $A1 ' set segment remap column 127 as start
SSDc $C8 ' Com Scan Direction, Flip display vertically
SSDc $DA ' set COM pins
if ssdheight > 3 then
SSDc$12 ' set COM pins = 128x64=$12
else
SSDc$02 ' set COM pins = 128x32=$02
endif
SSDc $81 : SSDc$7F ' Set brightness to $01 to $FF ($7F is default, $01 is faint)
SSDc $DB : SSDc$40 ' Set VCOM Deselect Level
SSDc $B0 ' Set Page Address From $B0 to $B7
SSDc $2e ; scroll off
SSDc $A4 ' display ON continue
SSDc $A6 ' $A6=NORMAL MODE; $A7=INVERSE MODE
SSDc $AF ' Display ON
return




xyx: ;draw HORIZ LINE @X,Y for W len 0<X>127 1<W>127
FOR GRX = 0 TO 31
glcd_buff[GRX] = glcdData ;uses this var to set which bit/s is used to generate line
NEXT
gx = gx&ssdwidth
gx_= gx + gl
gy = gy&ssdheight
gy_= gy
gosub setxy
GRX = gl/32
glcd_rad = 32
WHILE GRX
gosub ssd_data
GRX = GRX-1
WEND
glcd_rad = gl//32
IF glcd_rad THEN
gosub ssd_data
ENDIF
return




xyy: ;draw VERT LINE @X,Y for W len @X 0<X>127 1<W>7
FOR GRX = 0 TO ssdheight
glcd_buff[GRX] = 255
NEXT
gx = gx&ssdwidth
gx_= gx
gy = gy&ssdheight
gy_= gy+GL
gosub setxy
glcd_rad = gl
gosub ssd_data
return


glcd_clrxy: ' clear area x1y1 to x2 y2
FOR GRX = 0 TO 31
glcd_buff[GRX] = 0
NEXT
CTEMP = (1 + GX_ - GX)*(1 + GY_ - GY)
gosub setxy
GRX = CTEMP/32
glcd_rad=32
WHILE GRX
gosub ssd_data
GRX = GRX-1
WEND
glcd_rad = CTEMP//32
IF GRX THEN
gosub ssd_data
ENDIF
return


gcga: ;draw a chr
GY = gy&ssdheight
GY_= gy + BIG_TEXT
gx = gx&ssdwidth
#ifdef PIC16
glcdOffset = (glcdch-32)*3 + glcdFont ; point to cga data
#ELSE
glcdOffset = (glcdch-32)*6 + glcdFont ; point to cga data
#ENDIF
gosub unpack
IF BIG_TEXT THEN
GOSUB SSD_BIG
glcd_rad = 24
gx_= gx + 11
ELSE
glcd_rad = 6
gx_= gx + 5
ENDIF
gosub setxy
gosub ssd_data
gx = gx_+ 1 + BIG_TEXT
IF GX > 121 THEN gx=0 ;wrap
return


ssd_data: ;send data block
#ifdef hwi2c
glcdBC=0
SSPCON2.0 = 1 ; SEN - Start Condition Enable Bit
WHILE SSPCON2.0 = 1 : WEND ; Wait for Start to complete
SSPBUF = ssd_add ; Move data to SSPBUF
WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave
SSPBUF = $40 ; Move data to SSPBUF
WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave
while glcdBC < glcd_rad
SSPBUF = glcd_buff[glcdBC] ; Move data to SSPBUF
WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave
glcdBC=glcdBC+1
wend
SSPCON2.2 = 1 ; PEN - send stop bit
While SSPCON2.2 = 1 : Wend ; Wait for SSP to complete
#else
i2Cwrite SDA,SCL,ssd_add,[$40,str glcd_buff\ glcd_rad]
#endif
return
#ifndef PIC16
ssd_bitmap: ;send graphic block from flash
gosub setxy
glcdBC=0
SSPCON2.0 = 1 ; SEN - Start Condition Enable Bit
WHILE SSPCON2.0 = 1 : WEND ; Wait for Start to complete
SSPBUF = ssd_add ; Move data to SSPBUF
WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave
SSPBUF = $40 ; Move data to SSPBUF
WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave
while glcdBC < glcd_rad
readcode glcdbm+glcdBC,CTEMP
SSPBUF = ctemp.LOWBYTE ; Move data to SSPBUF
WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave
SSPBUF = ctemp.highBYTE ; Move data to SSPBUF
WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave
glcdBC=glcdBC+2
wend
SSPCON2.2 = 1 ; PEN - send stop bit
While SSPCON2.2 = 1 : Wend ; Wait for SSP to complete
return
#endif

SSD_BIG: ;create a big chr from a small one
for glcddc = 5 to 0 STEP -1
ctemp = 0
ctemp1 = 3
gL = glcd_buff[glcddc]
for glcdBc = 0 to 7
IF GL & 1 THEN ctemp = ctemp|ctemp1
ctemp1 = ctemp1<<2
GL = GL>>1
NEXT
gL = glcddc*2
glcd_buff[GL] =ctemp.LOWBYTE
glcd_buff[GL+1] =ctemp.LOWBYTE
glcd_buff[GL+12]=ctemp.HIGHBYTE
glcd_buff[GL+13]=ctemp.HIGHBYTE
NEXT
RETURN


unpack: ;unpack font from flash
for glcddc = 0 to 2
GL = glcddc<<1
readcode glcdOffset,CTEMP
#ifdef PIC16
glcd_buff[gl] = CTEMP&$7f
ctemp=ctemp<<1
glcd_buff[gl+1]= CTEMP.HIGHBYTE
glcdOffset = glcdOffset + 1
#else
glcd_buff[gl] = CTEMP
glcd_buff[gl+1]= CTEMP.HIGHBYTE
glcdOffset = glcdOffset + 2
#endif
next
return


cmd_byte: 'send command sequence "glcdData "
#ifdef hwi2c
;hw i2c
SSPCON2.0 = 1 ; SEN - Start Condition Enable Bit
WHILE SSPCON2.0 = 1 : WEND ; Wait for Start to complete
SSPBUF = ssd_add ; Move data to SSPBUF
WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave
SSPBUF = 0 ; Move data to SSPBUF
WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave
SSPBUF = glcdData ; Move data to SSPBUF
WHILE SSPSTAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSPCON2.6 = 1 : WEND ; Wait for Acknowledge from slave
SSPCON2.2 = 1 ; PEN - send stop bit
While SSPCON2.2 = 1: Wend ; Wait for SSP to complete
#else
;soft i2c
I2Cwrite SDA,SCL,ssd_add,[0,glcdData]
#ENDIF
return




setxy: ;set PAGE WINDOW
SSDc $22
SSDc gy
SSDc gy_
SSDc $21
SSDc gx
SSDc gx_
return






overglcd :

richard
- 24th December 2021, 10:51
OK. Later I will do that. But all what I described is from this thread starting from post #1 and on.

Ioannis
i know but some errors crept in and some posted files are not right and i cannot fix them nor remember which ones they are
its best to be dealing from the same deck

Ioannis
- 24th December 2021, 10:57
Yes you are right. Will post that later today.

Ioannis

Ioannis
- 25th December 2021, 15:13
Merry Xmas to all.

here are the files I used to test the SSD1306 lcd.

Ioannis

Ioannis
- 25th December 2021, 15:34
Just tested the new include you post and works with soft I2C as expected. But not on hardware I2C...

My code with new include:



#CONFIG
CONFIG PLLDIV = 1 ; Divide by 5 (20 MHz oscillator input)
CONFIG CPUDIV = OSC1_PLL2 ; [Primary Oscillator Src: /1][96 MHz PLL Src: /2]
CONFIG USBDIV = 2 ; USB clock source comes from the 96 MHz PLL divided by 2
CONFIG FOSC = ECPLLIO_EC ; HSPLL_HS ; HS oscillator, PLL enabled (HSPLL)
CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor disabled
CONFIG IESO = OFF ; Oscillator Switchover mode disabled
CONFIG PWRT = OFF ; PWRT disabled
CONFIG BOR = ON ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
CONFIG BORV = 3 ; Minimum setting
CONFIG VREGEN = ON ; USB voltage regulator enabled
CONFIG WDT = ON ; WDT enabled
CONFIG WDTPS = 512 ; 1:512
CONFIG CCP2MX = ON ; CCP2 input/output is multiplexed with RC1
CONFIG PBADEN = OFF ; PORTB<4:0> pins are configured as digital I/O on Reset
CONFIG LPT1OSC = OFF ; Timer1 configured for higher power operation
CONFIG MCLRE = ON ; MCLR pin enabled; RE3 input pin disabled
CONFIG STVREN = ON ; Stack full/underflow will cause Reset
CONFIG LVP = OFF ; Single-Supply ICSP disabled
CONFIG ICPRT = OFF ; ICPORT disabled
CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
CONFIG DEBUG = OFF ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
CONFIG CP0 = OFF ; Block 0 (000800-001FFFh) is not code-protected
CONFIG CP1 = OFF ; Block 1 (002000-003FFFh) is not code-protected
CONFIG CP2 = OFF ; Block 2 (004000-005FFFh) is not code-protected
CONFIG CP3 = OFF ; Block 3 (006000-007FFFh) is not code-protected
CONFIG CPB = OFF ; Boot block (000000-0007FFh) is not code-protected
CONFIG CPD = OFF ; Data EEPROM is not code-protected
CONFIG WRT0 = OFF ; Block 0 (000800-001FFFh) is not write-protected
CONFIG WRT1 = OFF ; Block 1 (002000-003FFFh) is not write-protected
CONFIG WRT2 = OFF ; Block 2 (004000-005FFFh) is not write-protected
CONFIG WRT3 = OFF ; Block 3 (006000-007FFFh) is not write-protected
CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) are not write-protected
CONFIG WRTB = OFF ; Boot block (000000-0007FFh) is not write-protected
CONFIG WRTD = OFF ; Data EEPROM is not write-protected
CONFIG EBTR0 = OFF ; Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
CONFIG EBTR1 = OFF ; Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
CONFIG EBTR2 = OFF ; Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
CONFIG EBTR3 = OFF ; Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks
CONFIG EBTRB = OFF ; Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
#ENDCONFIG


DEFINE OSC 48

LATA = %00000000
LATB = %00000000
LATC = %00000000
LATD = %00000000
LATE = %00000000

TRISA = %00100001
TRISB = %00010000
TRISC = %00000000
TRISD = %00000000
TRISE = %00000000

;************************************************* ********************
; ADC Settings
;************************************************* ********************
ADCON0=%00000001
ADCON1=%00001110
ADCON2=%10100111
cmcon=0

;************************************************* ********************

' Set LCD Data port
DEFINE LCD_DREG PORTD
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTD
' Set LCD Register Select bit
DEFINE LCD_RSBIT 0
' Set LCD Enable port
DEFINE LCD_EREG PORTD
' Set LCD Enable bit
DEFINE LCD_EBIT 1
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
'DEFINE LCD_COMMANDUS 1500
' Set data delay time in us
'DEFINE LCD_DATAUS 50

DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
DEFINE ADC_CLOCK 3

pause 100
t1con=0

char var byte
x var byte
y var byte
BUFF VAR BYTE[16]

;use this define for hw i2c
#define hwi2c 1

;set and uncomment these to use softi2c
SCL var Portb.1 ' I2C Clock
SDA var Portb.0 ' I2C Data

;set these to match display
ssdheight con 7 ; 7 = 8 PAGES 64*128 , 3 = 4 pages 32*128
ssdwidth con 127 ; 128 PIXELS WIDE
sdd1306_addr con $78
Include "ssd1306_I2C_16_18.INC" ' bring it in
include "font7x5_18.bas"
'========================== MAIN Routine ==============================


gosub glcd_init
BIG_TEXT = 0


looper:
GLCD_CLR
GLCDDHL 0,0,75,1 ;x,y,len,patten
GLCDDHL 0,2,75,128
GLCDDVL 0,0,3 ;x,y,height [in pages]
GLCDDVL 75,0,3
GLCDSTR 5,1,"--SSD1306--" ;x,y, cont string
ARRAYWRITE BUFF,["JBCDEF",0]
CHAR="!"
GLCDC 100,2,CHAR ;x,y , chr
BIG_TEXT = 1
if ssdheight > 3 then
GLCDSTR 2,4,BUFF
ARRAYWRITE BUFF,["@12456-=#",0]
BIG_TEXT = 0
GLCDSTR 2,7,BUFF ;x,y ,str buffer [null terminated]
else
pause 1000
GLCD_CLR
GLCDSTR 2,0,BUFF
ARRAYWRITE BUFF,["@12456-=#",0]
BIG_TEXT = 0
GLCDSTR 2,3,BUFF
endif
PAUSE 3000
GOTO looper


Ioannis

richard
- 26th December 2021, 01:29
it works for me with
TRISB = % 00010011

most pic modules that switch pin directions like to control tris themselves, the data sheet for this chip is totally not clear
at all re i2c tris requirements

Ioannis
- 26th December 2021, 12:17
Yes, you are right. I took it for granted that this was taken care in the include file. Now it works OK with hard I2C also.

Next, how to import the 16x16 characters into the 5x7 library.

Can these co-exist?

I tried to add your pawn example after the 5x7 data but obviously this does not work if one wants to print character 128...

I attach my failed try.

Ioannis

richard
- 27th December 2021, 01:34
I took it for granted that this was taken care in the include file
it is to some extent , the correct tris setting for sda and scl is the power on default of input for both hw and software i2c
if the user decides to overwrite those settings its extremely difficult to rectify in an include file since the pins can be virtually
anywhere on any port depending on chip used


Next, how to import the 16x16 characters into the 5x7 library.

you cannot , the font is 5x7 hard coded


Can these co-exist?
not as a font


I tried to add your pawn example after the 5x7 data but obviously this does not work if one wants to print character 128...
i see no impediment to 5x7 chrs being added to the font to a byte sized quantity, the upper font boundary is not enforced
mixed font heights is not implemented

I attach my failed try.
if you want 16x16 fonts see here, its a completely different strategy
http://www.picbasic.co.uk/forum/showthread.php?t=24218
if you want to persist with this code, the chess pieces will need to be bitmaps
bitmaps in an array would be fairly straight forward, two for each piece type , one as solid the other an outline, with a blank w and blk too
the board could also be a bit map a piece could then be or-ed or exor-ed into a square depending piece colour and square colour

richard
- 27th December 2021, 06:03
looks like a 4550 just hasn't the resources for graphics work

here is a look a my 16x16 pawn font on a 26k22
9129

its still a bit clunky @ 16x16

bmp 48x51
9130

Ioannis
- 27th December 2021, 09:21
The thing is getting more and more complicated...

I am considering to switch over to a 3,5" Nextion display. Much easier, preloaded images. Even a 12F could handle that! Still I have to use the USB port, so 4550 is the least to use.

The last try of 48x51 looks great! I do not care about white or black pieces or even the board. White pieces is just fine. But if the resources needed are too much, I don't know if it is worth to keep on trying...

Thanks a lot for the efforts,
Ioannis

richard
- 27th December 2021, 09:31
Bitmaps take very modest resources, that one just 48 x 8 bytes of flash

Ioannis
- 27th December 2021, 09:51
That is nice! Is there any post on the forum how this can be done?

This needs 2304 bytes for 6 pieces and I think this can be managed.

Ioannis

richard
- 27th December 2021, 10:40
LCDAssistant.exe
GLCDtool.exe

will get you close [keep height to multiple of 8]

richard
- 27th December 2021, 10:54
found this example



'************************************************* ***************
'* Name : ssd1306_DEMO.PBP *
'* Author : richard *
'* Notice : *
'* : *
'* Date : 19/11/2017 *
'* Version : *
'* Notes : *
'* :FOR pic 18F26K22 SSD1306 *
'************************************************* ***************
#CONFIG
CONFIG FOSC = INTIO67
CONFIG PLLCFG = OFF
CONFIG PRICLKEN = OFF
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRTEN = OFF
CONFIG BOREN = SBORDIS
CONFIG BORV = 190
CONFIG WDTEN = ON
CONFIG WDTPS = 32768
CONFIG CCP2MX = PORTC1
CONFIG PBADEN = OFF
CONFIG CCP3MX = PORTB5
CONFIG HFOFST = ON
CONFIG T3CMX = PORTC0
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

char var byte
x var byte
y var byte
BUFF VAR BYTE[16]
NCO_INT VAR WORD


OSCCON = %01110000
ANSELb = 0
ANSELA = 0
ANSELC = 0
OSCTUNE.6=1
;use this define for hw i2c
#define hwi2c 1

;set and uncomment these to use softi2c
'SCL var PortC.3 ' I2C Clock
'SDA var PortC.4 ' I2C Data

;set these to match display
ssdheight con 7 ; 7 = 8 PAGES 64*128 , 3 = 4 pages 32*128
ssdwidth con 127 ; 128 PIXELS WIDE
sdd1306_addr con $78
Include "ssd1306_I2C.INC" ' bring it in
include "font7x5_18.bas"


gosub glcd_init
BIG_TEXT = 0


looper:
GLCD_CLR
SSDBM 30,0,64,64 ,kooka
PAUSE 1000
GLCD_CLR
SSDBM 30,0,61,64 ,surfer64
PAUSE 1000
GLCD_CLR
SSDBM 30,0,64,64 ,lizard64
PAUSE 1000

GLCD_CLR
GLCDDHL 0,0,75,1 ;x,y,len,patten
GLCDDHL 0,2,75,128
GLCDDVL 0,0,3 ;x,y,height [in pages]
GLCDDVL 75,0,3
GLCDSTR 5,1,"--SSD1306--" ;x,y, cont string
ARRAYWRITE BUFF,["ABCDEF",0]
CHAR="!"
GLCDC 100,1,CHAR ;x,y , chr
BIG_TEXT = 1
if ssdheight > 3 then
GLCDSTR 2,4,BUFF
ARRAYWRITE BUFF,["@12456-=#",0]
BIG_TEXT = 0
GLCDSTR 2,7,BUFF ;x,y ,str buffer [null terminated]
else
pause 1000
GLCD_CLR
GLCDSTR 2,0,BUFF
ARRAYWRITE BUFF,["@12456-=#",0]
BIG_TEXT = 0
GLCDSTR 2,3,BUFF
endif
PAUSE 1000
GOTO looper

END
kooka:
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128
@ db 224, 240, 248, 248, 248, 248, 252, 220, 220, 220, 220, 28, 28, 28, 28, 28
@ db 124, 248, 248, 248, 240, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 64, 224, 240, 240, 216, 248, 248, 232, 236, 172, 183
@ db 183, 183, 183, 159, 191, 191, 159, 31, 63, 63, 28, 62, 62, 63, 28, 28
@ db 0, 128, 225, 255, 255, 255, 255, 124, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0
@ db 0, 0, 1, 3, 15, 63, 143, 0, 0, 0, 0, 0, 0, 140, 30, 214
@ db 231, 227, 243, 251, 249, 252, 252, 252, 254, 254, 255, 124, 240, 240, 192, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 128, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 3, 15, 248, 128, 6, 62, 255, 255, 191, 191, 255
@ db 207, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
@ db 252, 128, 0, 0, 0, 24, 248, 252, 255, 255, 15, 7, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 192, 112, 248, 248, 248, 248, 248, 248, 254
@ db 254, 254, 254, 246, 254, 252, 248, 193, 15, 30, 252, 240, 225, 199, 207, 158
@ db 63, 127, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
@ db 255, 255, 254, 62, 30, 31, 31, 15, 15, 15, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 31, 31, 7, 7, 15, 63
@ db 127, 63, 7, 15, 15, 127, 255, 247, 198, 192, 248, 124, 29, 31, 159, 159
@ db 223, 254, 252, 253, 249, 51, 247, 239, 255, 255, 255, 255, 255, 255, 255, 255
@ db 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 224, 127, 15, 128, 224, 248, 252, 127, 31, 15, 15
@ db 7, 7, 7, 7, 3, 0, 0, 0, 0, 3, 63, 254, 255, 255, 125, 251
@ db 255, 223, 222, 254, 206, 224, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 12, 31, 63, 112, 252, 255, 127, 31, 1, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 63, 126, 127
@ db 127, 255, 189, 223, 255, 55, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0


surfer64 :
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 252
@ db 254, 254, 255, 254, 254, 254, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 192, 224, 240, 248, 252, 248, 255, 255, 255
@ db 255, 253, 249, 240, 248, 240, 240, 224, 224, 192, 192, 192, 192, 192, 128, 192
@ db 128, 192, 128, 192, 192, 192, 192, 192, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 128, 252, 255, 95, 15, 7, 63, 255, 255, 255, 255, 255, 255, 255, 63
@ db 31, 2, 0, 0, 1, 1, 1, 1, 1, 3
@ db 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 170, 255, 255, 225, 128, 0, 0, 253, 255
@ db 255, 255, 255, 255, 255, 240, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 1, 0, 0, 0, 1, 3, 7
@ db 7, 31, 63, 127, 255, 255, 255, 255, 255, 254, 252, 240, 224, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 192, 192, 0, 112, 240, 240, 0, 0, 96, 184, 28, 224, 192, 128, 224
@ db 224, 0, 0, 84, 255, 255, 255, 31, 1, 7, 63, 127, 255, 255, 248, 64
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 16, 16, 145, 147, 83, 182, 117, 165, 53, 43, 77, 106, 235, 227, 231, 252, 243
@ db 239, 240, 224, 255, 255, 255, 193, 192, 192, 192, 128, 192, 131, 223, 255, 255, 248
@ db 192, 128, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 4, 14, 6, 6, 6, 6, 5, 13, 29, 26, 22, 22, 21, 21, 21
@ db 21, 21, 13, 91, 123, 87, 87, 87, 215, 87, 255, 87, 255, 87, 207, 95, 191
@ db 223, 159, 159, 159, 95, 159, 95, 127, 95, 95, 95, 95, 95, 79, 87, 47, 23
@ db 27, 27, 9, 5, 4, 4, 4, 4, 4, 4

lizard64 :
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192
@ db 0, 0, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 128, 253, 192
@ db 112, 158, 65, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 128, 192, 224, 248, 224, 80, 88, 76, 32
@ db 16, 0, 0, 128, 192, 224, 240, 240, 240, 248, 252, 60, 16, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 127, 127, 127
@ db 127, 105, 116, 240, 240, 248, 248, 248, 248, 152, 128, 192, 192, 192, 192, 224
@ db 192, 224, 228, 238, 255, 255, 255, 255, 253, 251, 251, 241, 241, 241, 241, 248
@ db 248, 252, 124, 63, 31, 15, 7, 7, 7, 3, 1, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 192, 224, 240, 240
@ db 248, 252, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
@ db 127, 63, 63, 63, 63, 63, 31, 31, 31, 15, 95, 255, 255, 255, 223, 207
@ db 195, 128, 128, 128, 192, 160, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 128, 240, 248, 252, 254, 127, 31, 15, 7, 7, 3
@ db 1, 1, 1, 0, 6, 7, 7, 7, 7, 15, 31, 31, 31, 63, 31, 63
@ db 21, 23, 21, 21, 21, 20, 20, 20, 20, 0, 0, 0, 0, 0, 1, 1
@ db 1, 3, 3, 7, 15, 31, 39, 14, 3, 10, 2, 0, 0, 0, 0, 0
@ db 0, 0, 0, 224, 255, 255, 255, 15, 1, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 128, 192, 96, 96, 48, 16, 16, 16, 8, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 7, 63, 127, 248, 240, 192, 192, 128, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 192, 192, 64, 96, 48, 24
@ db 28, 6, 7, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 7, 3, 7, 6
@ db 7, 6, 7, 6, 7, 3, 7, 3, 3, 1, 1, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

CuriousOne
- 31st December 2021, 12:04
Got some genuine, 128x128 pixels, 16 shades of grey, OLED displays from Futaba. They use SSD1327. Any chances to adapt all above to that controller?

richard
- 1st January 2022, 09:50
no, my tft code would be a closer fit, a full redesign would be needed for the greyscale nibbles. full colour oleds are about the same price so i doubt if i would be interested in grey scale code anyway for such tiny displays.

lester
- 6th February 2024, 15:49
Test Message - Please disregard

richard
- 7th February 2024, 01:08
if you wish to run the display in inverse colour mode at any time :
use one of these "usercommands" that are part of the include

to invert entire display
SSDC $A7
to restore it USE
SSDC $A6

fethiye
- 7th February 2024, 18:40
Thanks for information

spcw1234
- 21st February 2024, 00:13
Richard, I am hoping you can help me with an issue I am having making your SSD1306 driver work. Everything is working well except when I display a bitmap with the y axis not set at 0 it cuts the image in half. I have tried with every version of the ssd1306_I2C.INC found in this thread with the same result. Posted here is the code with a simple 16x16 bitmap icon and an image of it displayed at both y=0 and y=4. Any chance you can help sort what is going on here?



'************************************************* ***************
'* Name : ssd1306_DEMO.PBP *
'* Author : richard *
'* Notice : *
'* : *
'* Date : 19/11/2017 *
'* Version : *
'* Notes : *
'* :FOR pic 18F26K22 SSD1306 *
'************************************************* ***************
#CONFIG
CONFIG FOSC = INTIO67
CONFIG PLLCFG = ON
CONFIG PRICLKEN = OFF
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRTEN = OFF
CONFIG BOREN = SBORDIS
CONFIG BORV = 190
CONFIG WDTEN = ON
CONFIG WDTPS = 32768
CONFIG CCP2MX = PORTC1
CONFIG PBADEN = OFF
CONFIG CCP3MX = PORTB5
CONFIG HFOFST = ON
CONFIG T3CMX = PORTC0
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
OSCCON = %11110000

char var byte
x var byte
y var byte
BUFF VAR BYTE[16]

ANSELb = 0
ANSELA = 0
ANSELC = 0

;use this define for hw i2c
#define hwi2c 1 'SCL=C.3 & SDA=C.4

;set and uncomment these to use softi2c
'SCL var PortC.3 ' I2C Clock
'SDA var PortC.4 ' I2C Data

;set these to match display
ssdheight con 7 ; 7 = 8 PAGES 64*128 , 3 = 4 pages 32*128
ssdwidth con 127 ; 128 PIXELS WIDE
sdd1306_addr con $78
Include "ssd1306_I2C.INC" ' bring it in
include "font7x5_18.bas"


'========================== MAIN Routine ==============================

pause 100
gosub glcd_init
GLCD_CLR
BIG_TEXT = 0

main:
SSDBM 112,0,16,16 ,StallIcon ;x,y,w,h,label Y=0 (DISPLAYS OK)
' pause 100
' SSDBM 112,0,16,16 ,BlankIcon ;x,y,w,h,label

' SSDBM 112,2,16,16 ,StallIcon ;x,y,w,h,label Y>0 (DISPLAYS HALF OF IMAGE)
' pause 100
' SSDBM 112,2,16,16 ,BlankIcon ;x,y,w,h,label

SSDBM 112,4,16,16 ,StallIcon ;x,y,w,h,label Y>0 (DISPLAYS HALF OF IMAGE)
pause 1000
' SSDBM 112,4,16,16 ,BlankIcon ;x,y,w,h,label

' SSDBM 112,6,16,16 ,StallIcon ;x,y,w,h,label Y>0 (DISPLAYS HALF OF IMAGE)
' pause 100
' SSDBM 112,6,16,16 ,BlankIcon ;x,y,w,h,label
goto main
end

StallIcon: '16x16 BMP image
@ db 248, 4, 226, 241, 57, 25, 25, 193, 241, 121, 25, 25, 241, 226, 4, 248
@ db 15, 16, 35, 71, 78, 76, 78, 71, 67, 64, 76, 78, 71, 35, 16, 15


BlankIcon: '16x16 BMP image
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0


9622

richard
- 21st February 2024, 02:40
Any chance you can help sort what is going on here?

yep, i never did test with other than 64x64 bmps, that masked the fault
now we know it works with 64x64 and 16x16 bmps at least

there is a defect in the include file, the bmp usercommand macro is not quite right

in the include file the bit in red needs to be added in


SSDBM?CCCCL macro Xin ,Yin ,Win,Hin,BMin
IFNDEF TBLPTRL
ERROR BITMAPS ONLY SUPPORTED ON PIC18
ENDIF
MOVE?CB Xin , _gx
MOVE?CB Yin , _gy
MOVE?CB Hin/8+Yin-1 , _gy_
MOVE?CB Win+Xin-1 , _gx_
MOVE?CW Win*Hin/8 , _glcd_rad
banksel _glcdbm
movlw low BMin
movwf _glcdbm
movlw high BMin
movwf _glcdbm +1
BANKSEL 0
L?CALL _ssd_bitmap
endm

richard
- 21st February 2024, 02:50
latest version

spcw1234
- 21st February 2024, 13:53
Thank you, Richard! That works perfectly! You have no idea how much time I spent attempting to fix that.

One other request. I am struggling to understand the macros but would like one that can do a point to point line. Something that would do x1,y1 to x2,y2. Can you assist with adding a macro to accomplish this?

richard
- 21st February 2024, 21:27
One other request. I am struggling to understand the macros but would like one that can do a point to point line.

not possible with this small footprint method , horizontal and vertical lines is the best it can do

if you want full graphics use this
https://www.picbasic.co.uk/forum/showthread.php/24218-Graphical-Displays-with-PBP3?p=146741#post146741

spcw1234
- 21st February 2024, 23:24
I was afraid that would be the case. I have spent time playing with that version and can't figure out how to display a bitmap image, which is a requirement for this project. That's using DMDBMP command.

If I copy in the macro from this version and add the SSDBM command, I can display an image, but not correctly. Likely due to the difference in how the height differs from both drivers.

richard
- 21st February 2024, 23:41
post what you have tried and i will have a look

spcw1234
- 22nd February 2024, 00:37
When I use SSDBM it shows the top half of the image twice, and seems to lock the display as I can't clear or alter what is displayed afterwards.


Using the DMDBMP format, it displays a black screen, but if I attempt to display something afterwards it goes nuts. I assume I'm not addressing the BMP data location correctly, but don't see an example or instructions on using a bitmap.


DMDBMP 0,0,logo64 'X,Y,LABEL (HOW DO I SPECIFY SIZE???)
gosub show


Here is the code I am running right now with the bmp. Doing it this way seems to get stuck right after the image is displayed, and it looks like the picture below.


#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 = ON
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
OSCCON=%01110000 ' SET TO 16 MHZ internal oscillator
OSCTUNE.6=1 ' 4xPLL
DEFINE OSC 64
;set these to match display
ssd1306_addr con $78
#DEFINE colours 1 ;1 mono 2 rg or 3 rgb
width con 128
height con 64
h_offset con 0 ;28 for 40x72

include "grx.pbpMOD"
include "SSD1306.pbpMOD"
include "font.bas"
include "bignum.bas"
include "bigchr.bas"
BUFF VAR BYTE[10]
J VAR BYTE

BGCOLOUR=0
ANSELB=0
ANSELC=0
ANSELA=0
OSCCON=$70


gosub glcd_init
gosub grf_clr
gosub show
SETFONT FONT5x7

main:


'DMDBMP 128,64,logo64 'X,Y,LABEL (HOW DO I SPECIFY SIZE???)
'gosub show

'pause 5000
'gosub grf_clr
'gosub show

ARRAYWRITE BUFF,["STRING OF TEXT",0]
DMDSTR 10,5,buff,1
gosub show

pause 5000
gosub grf_clr
gosub show

SSDBM 31,0,64,64 ,logo64 'This displays the top half of the image ok, and repeats the top half on lower half of screen
'Using this MACRO inside of grx.pbpmod
'SSDBM?CCCCL macro Xin ,Yin ,Win,Hin,BMin
' IFNDEF TBLPTRL
' ERROR BITMAPS ONLY SUPPORTED ON PIC18
' ENDIF
' MOVE?CB Xin , _gx
' MOVE?CB Yin , _gy
' MOVE?CB Hin/8+Yin-1 , _gy_
' MOVE?CB Win+Xin-1 , _gx_
' MOVE?CW Win*Hin/8 , _glcd_rad
' banksel _glcdbm
' movlw low BMin
' movwf _glcdbm
' movlw high BMin
' movwf _glcdbm +1
' BANKSEL 0
' L?CALL _ssd_bitmap
' endm


pause 1000 'WE GET STUCK HERE!!!
gosub grf_clr
gosub show
pause 1000

goto main


end

logo64: '64x64 image
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 112, 60, 28, 6, 7, 3
@ db 3, 7, 6, 14, 28, 112, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 248, 254, 7, 7, 3, 3, 3, 3
@ db 3, 6, 2, 6, 4, 12, 136, 184, 23, 33, 64, 64, 0, 128, 0, 0
@ db 0, 0, 0, 128, 64, 32, 33, 23, 120, 136, 12, 4, 4, 6, 2, 3
@ db 3, 3, 3, 3, 7, 6, 254, 252, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 2, 7, 60, 224, 128, 128, 128, 128
@ db 0, 64, 0, 64, 0, 64, 110, 0, 32, 0, 64, 32, 32, 8, 33, 2
@ db 6, 9, 32, 16, 0, 32, 128, 32, 0, 21, 96, 0, 64, 64, 0, 64
@ db 128, 128, 128, 128, 224, 28, 15, 1, 0, 0, 0, 0, 0, 0, 0, 0
@ db 192, 224, 120, 24, 28, 4, 6, 2, 3, 0, 1, 0, 1, 6, 8, 16
@ db 32, 0, 192, 0, 32, 154, 4, 0, 1, 128, 224, 248, 248, 252, 252, 254
@ db 252, 252, 252, 252, 248, 224, 64, 1, 2, 0, 73, 16, 64, 128, 0, 64
@ db 32, 8, 6, 1, 1, 1, 1, 3, 2, 6, 12, 12, 56, 112, 240, 192
@ db 3, 15, 30, 24, 60, 96, 96, 64, 192, 128, 128, 128, 128, 64, 60, 12
@ db 2, 1, 0, 2, 0, 0x2C, 144, 0, 0, 0, 15, 31, 31, 63, 127, 63
@ db 127, 63, 63, 31, 31, 15, 1, 128, 0, 32, 0x94, 8, 2, 0, 1, 2
@ db 8, 16, 96, 128, 0, 128, 128, 64, 64, 96, 96, 60, 24, 14, 15, 3
@ db 0, 0, 0, 0, 0, 0, 0, 0, 128, 240, 56, 7, 1, 1, 1, 0
@ db 3, 0, 2, 2, 4, 2, 234, 4, 0, 1, 4, 4, 0, 12, 144, 64
@ db 64, 36, 152, 0, 4, 2, 0, 4, 0, 178, 6, 0, 2, 2, 2, 2
@ db 0, 1, 1, 1, 7, 28, 240, 128, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 31, 127, 240, 192, 192, 192, 192, 192
@ db 192, 192, 32, 96, 32, 16, 16, 31, 248, 132, 4, 2, 1, 0, 0, 0
@ db 0, 0, 0, 1, 2, 4, 132, 120, 31, 16, 60, 32, 32, 96, 64, 192
@ db 192, 192, 192, 192, 224, 112, 127, 63, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 14, 60, 60, 112, 224, 192
@ db 192, 224, 112, 112, 24, 30, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0


9624

richard
- 22nd February 2024, 00:52
there is no need to modify the include

the correct usage is


DMDBMP 0,0,logo64

bmp's need a header to set width and height



logo64: '64x64 image
@ db 64,64 // header width,height
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 112, 60, 28, 6, 7, 3
@ db 3, 7, 6, 14, 28, 112, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 248, 254, 7, 7, 3, 3, 3, 3
@ db 3, 6, 2, 6, 4, 12, 136, 184, 23, 33, 64, 64, 0, 128, 0, 0
@ db 0, 0, 0, 128, 64, 32, 33, 23, 120, 136, 12, 4, 4, 6, 2, 3
@ db 3, 3, 3, 3, 7, 6, 254, 252, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 2, 7, 60, 224, 128, 128, 128, 128
@ db 0, 64, 0, 64, 0, 64, 110, 0, 32, 0, 64, 32, 32, 8, 33, 2
@ db 6, 9, 32, 16, 0, 32, 128, 32, 0, 21, 96, 0, 64, 64, 0, 64
@ db 128, 128, 128, 128, 224, 28, 15, 1, 0, 0, 0, 0, 0, 0, 0, 0
@ db 192, 224, 120, 24, 28, 4, 6, 2, 3, 0, 1, 0, 1, 6, 8, 16
@ db 32, 0, 192, 0, 32, 154, 4, 0, 1, 128, 224, 248, 248, 252, 252, 254
@ db 252, 252, 252, 252, 248, 224, 64, 1, 2, 0, 73, 16, 64, 128, 0, 64
@ db 32, 8, 6, 1, 1, 1, 1, 3, 2, 6, 12, 12, 56, 112, 240, 192
@ db 3, 15, 30, 24, 60, 96, 96, 64, 192, 128, 128, 128, 128, 64, 60, 12
@ db 2, 1, 0, 2, 0, 0x2C, 144, 0, 0, 0, 15, 31, 31, 63, 127, 63
@ db 127, 63, 63, 31, 31, 15, 1, 128, 0, 32, 0x94, 8, 2, 0, 1, 2
@ db 8, 16, 96, 128, 0, 128, 128, 64, 64, 96, 96, 60, 24, 14, 15, 3
@ db 0, 0, 0, 0, 0, 0, 0, 0, 128, 240, 56, 7, 1, 1, 1, 0
@ db 3, 0, 2, 2, 4, 2, 234, 4, 0, 1, 4, 4, 0, 12, 144, 64
@ db 64, 36, 152, 0, 4, 2, 0, 4, 0, 178, 6, 0, 2, 2, 2, 2
@ db 0, 1, 1, 1, 7, 28, 240, 128, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 31, 127, 240, 192, 192, 192, 192, 192
@ db 192, 192, 32, 96, 32, 16, 16, 31, 248, 132, 4, 2, 1, 0, 0, 0
@ db 0, 0, 0, 1, 2, 4, 132, 120, 31, 16, 60, 32, 32, 96, 64, 192
@ db 192, 192, 192, 192, 224, 112, 127, 63, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 14, 60, 60, 112, 224, 192
@ db 192, 224, 112, 112, 24, 30, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0
@ db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

spcw1234
- 22nd February 2024, 01:11
That gets me closer, in the sense I figured it needed specified somewhere! But it doesn't correctly display the image. I have reverted back to non-edited include files. Thoughts? Thank you for your assistance!!!

9625

richard
- 22nd February 2024, 02:21
ah! the bmps are in a different format the byte are now laid out horizontally
i also discovered the dmp code upsets the font height [did have a shared variable]
i used lcdassistant to generate bmps

some files to play with

9628

richard
- 22nd February 2024, 02:49
glcd tools also works well in generating bmp's
and formats the data nicely
9629

spcw1234
- 22nd February 2024, 14:22
The only version of GLCD Tools I can find is 0.2. I have been using LCD Assistant, but I'm having mixed results. Do you have a link to download GLCD Tools 1.5?

This attached file has a few BMP's in it, the Logo64 opens successfully, except it takes 5+ seconds to display each image after the screen clear... The other 2 (StallIcon and OneIcon) both don't load and results in a bricked display until power cycle. I have tried other's and can't get them to open.
These were created with LCD Assistant set to horizontal and formatted appropriately.

I'm not sure the reason for the failed images to display,

I'm not sure the reason for the really slow load times to display the images

The SSD1306 driver this thread was created for loads images with excellent performance.

spcw1234
- 22nd February 2024, 15:02
I resolved the slow load times by commenting out the debug lines in the sbmp subroutine.

spcw1234
- 22nd February 2024, 16:45
I have found if I revise the first byte of the bitmap to = 0x00 instead of the value it should be, the image will display. Obviously missing the first 8 pixels worth of data though...

spcw1234
- 22nd February 2024, 20:10
I have everything working, but using the SSDBM version for bitmap. This obviously required modifying the include files, but everything seems to be getting along.

I can share the modified files, but won't if you prefer as to prevent confusion. If you find a fix for the DMDBMP version, I'm sure it is a better solution.

Thanks for your work on this Richard!

richard
- 23rd February 2024, 00:04
there was another bug in the include, the bpm height var was reading in the first byte of the image as its high.byte
when there was not meant to be a high.byte
and i did accidentally leave the debug messages active
i have updated the include in the proper thread

richard
- 23rd February 2024, 00:28
i cant find the gltools on the web any more
i did find my install version in my downloads folder
at your own risk

spcw1234
- 23rd February 2024, 19:47
Thanks Richard!