PDA

View Full Version : Graphical Displays with PBP3



richard
- 20th March 2021, 07:05
i wrote this graphics lib to handle led dmd's [1/4 scan dot matrix displays] in mono, red/green or rgb in varing sizes up to 128x32 pixels.
it occured to me that with a little more effort it would make a general purpose graphic lib for nearly any display. so here it is.
it uses mikroe fonts that you can easily generate. the variable width fonts can be up to 23 bits wide if you like.

a driver for ssd1306, nokia and the ubiquitious 128x64 glcd are included with a small demo for each.
note this is pic18 pbp3 only and if a mssp port is warranted then its used. there are more functions in the lib than the USERCMDS
indicate, i never use them all. i could not be bothered making the usecmd code for everything
i might publish the led dmd stuff at sometime when i work out dma->spi transfers with a k42


and some fonts


and some demos

Jerson
- 20th March 2021, 11:30
You've done an excellent job. Would you consider posting a small video demo to visualize the results?

Warm wishes

richard
- 20th March 2021, 11:47
i dropped my camera and its not too happy, the phone makes ridiculous high res movies too big to use online
so how about a sim still shot
9046

9047

nokia 7110 too

Ioannis
- 20th March 2021, 23:25
That is awesome!

Thanks for sharing,
Ioannis

rocket_troy
- 22nd March 2021, 02:20
Fantastic work again Richard!

Would you have any particular recommendations for a display to purchase for a newbie just as a play-around learning tool ?

Regards,

Troy

richard
- 22nd March 2021, 02:40
if you don't mind waiting a few weeks the nokia 5110 from china is <$5 . the 7110 have a weird connector and are best avoided imo ,both are good size
not too many pins needed, 3-5v ok.
the ssd1306 are about $8 locally but they are pretty small need only two pins if you get i2c variant, 3-5v ok.
if you catch a special at https://www.rockby.com.au/Index2012.cfm the 128x64 glcd can be real cheap < $5 but need heaps of pins to drive them 5v only.
they all work .

rocket_troy
- 22nd March 2021, 04:39
Thanks Richard,
Ordered a 5110 from Ebay. Looking forward to having a play.

Cheers,

Troy

rocket_troy
- 1st April 2021, 16:07
Richard,
Received my 5110 display today and have just started to have a play. The nokia demo appears to display perfectly - excellent. I'm a bit stumped on one thing I'm trying to do. The nokia demo draws a circle:

DRAWCIRCLE 64,15,12

which I assume is a circle located a x=64, y=15 and radius of 12 yeah?

so I'm trying to draw a line from the centre of the circle to the top of the circle (or vice versa) so I tried:

DRAWLINE 64,3,64,15,1

which I assume is drawing a line from starting point X=64, Y=3 to ending point X=64, Y=15

And indeed the line starts at the correct point (top centre) but only extends down 7 or 8 pixels ie not to centre of the circle?

Any ideas?

Regards,

Troy

rocket_troy
- 1st April 2021, 17:20
So, what's happening (for me) is for a line that's wider than it is higher (or equal), it appears from very initial testing to draw correctly. But if it's higher than it is wider, it doesn't?

Troy

richard
- 1st April 2021, 21:57
it appears there was a bug in drawing vertical lines. this now works

rocket_troy
- 2nd April 2021, 00:51
Excellent! Hats off again Richard. This looked like a lot of work in putting it all together. If we ever meet, the drinks will definitely be on me!

Troy

rocket_troy
- 3rd April 2021, 12:39
Richard,
Another question: can we pass variables as parameters to these geometric routines?

Like:

DRAWLINE My_x1, My_y1, My_x2, My_y2, 1

So far I'm trying to pass byte size variables but getting illegal opcode messages at compile?

Troy

richard
- 3rd April 2021, 12:57
Another question: can we pass variables as parameters to these geometric routines?

EASY , Just add the needed macro's to the include file, you can dial up whatever you like

http://www.picbasic.co.uk/forum/showthread.php?t=23758&highlight=ssd1306
http://www.picbasic.co.uk/forum/showthread.php?t=20208&highlight=usercmd
http://support.melabs.com/forum/picbasic-pro-compiler-3-0-and-later/usercommand

rocket_troy
- 3rd April 2021, 13:55
EASY , Just add the needed macro's to the include file, you can dial up whatever you like

oookay :confused:

richard
- 3rd April 2021, 14:18
DRAWLINE My_x1, My_y1, My_x2, My_y2, 1



You need a macro like
DRAWLINE?BBBBC
the error message will tell you this does not exist

the existing drawline macros

;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




you could add this




DRAWLINE?BBBBC macro X0in ,Y0in ,X1in ,Y1in,Col
MOVE?BB X0in ,_s_xstart
MOVE?BB X1in ,_s_xend
MOVE?BB Y0in ,_s_ystart
MOVE?BB Y1in ,_s_yend
MOVE?CB Col ,_colour
L?CALL _dline
endm



or set the colour manually
eg colour=1

and use
DRAWLINE My_x1, My_y1, My_x2, My_y2
which already exists
DRAWLINE?BBBB
with a mono display you probably wont change the colour too often

richard
- 3rd April 2021, 14:27
a 5 input user command has the potential to need 5 raised to the 7th power of macros to cover every input permutation possible
a ridiculous number, i only ever create what seems useful to me. it's trivially easy to add any other combination you app calls for
and the compiler error virtually spells it out for you

rocket_troy
- 3rd April 2021, 14:58
a 5 input user command has the potential to need 5 raised to the 7th power of macros to cover every input permutation possible
a ridiculous number, i only ever create what seems useful to me. it's trivially easy to add any other combination you app calls for
and the compiler error virtually spells it out for you

Yeah, I did get that part from reading the links you provided - which makes it understandable (I guess) why you don't include that broad functionality.

Thanks for the example though. I now get it :)

Cheers,

Troy

rocket_troy
- 23rd April 2021, 06:58
Richard,
with the Nokia 5110 demo settings, the "width" constant is set at 88 instead of 84. Can you explain the reason for that? Like, with other displays, is it just a case of trial & error to gather this parameter or is available in documentation or from standard formula?

Thanks,

Troy

richard
- 23rd April 2021, 07:35
needs to multiple of 8 for the rotation to work properly

rocket_troy
- 23rd April 2021, 15:03
okay, that was simpler than I expected. Thx

rocket_troy
- 26th April 2021, 01:41
Richard,
would your drivers (with some tweaking of the input pins) be compatible with the jlx12864g-086 display? Someone online mentioned it would be a good substitute for the 5110 but they seem (to me) to be quite different interfaces?

Troy

richard
- 26th April 2021, 02:30
don't see why not. they look pretty much like a 128x64 glcd with a serial i/f
do you have a data sheet ? , i can't locate an English version

rocket_troy
- 26th April 2021, 03:14
Unfortunately I can't find one. Amazon says the IC is a UC1701X which there are English data sheets for. Attached is an online translation if that's any use?

9051

TP

richard
- 26th April 2021, 05:52
looking at that ds i expect it would require its own driver to be written to use it with my graphics lib, should be easy enough. i don't have a display to experiment with and
my simulator does not include a model for the display either so don't hold your breath.

rocket_troy
- 26th April 2021, 05:57
No probs.

Troy

richard
- 23rd October 2021, 04:29
Driver for st7920 display for my system

notes
you need to change in/out of graphics mode to use lcdout commands on the display if you have the need, i don't

it doesn't need the r/w pin when used with frame buffering but i did not test it

richard
- 24th October 2021, 23:47
serial i/f and busy flag check added for st7920



'************************************************* ***************'* Name : ST7920-LCD_DEMO.PBP *
'* Author : RICHARD *
' *
'* Date : 4/8/2017 *
'* Version : 1.0 *
'* Notes : pic18f26k22 *
'* : ST7920-LCD 128X64 *
'************************************************* ***************
#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 = OFF
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

DEFINE OSC 64



#DEFINE colours 1 ;1 mono 2 rg or 3 rgb
width con 128 ;
height con 64 ;
'use serial i/f
#define stserial 1
include "grx.pbpMOD"
include "st7920.pbpmod"
include "font.bas"
include "bignum.bas"
include "bigchr.bas"
BUFF VAR BYTE[32]
ani_h var word bank0
ani_r var byte
ani_c var byte
OSCCON=$70
OSCTUNE.6=1
while ! osccon2.7 :WEND ;wait for pll
ANSELB=0
ANSELC=0
ANSELA=0

trisc = %11010101 ;cs,sck,sdo are output




gosub st7920_init 'graphic mode
SETFONT FONT5x7
gosub grf_clr


ani_r=%10101011
ARRAYWRITE BUFF,[bin8 ani_r ,0]
DMDSTR 3,4,buff,1
for ani_c=0 to 7
ani_h=ani_h<<2
if ani_r.7 then ani_h=ani_h+3
ani_r=ani_r<<1
next
ARRAYWRITE BUFF,[bin16 ani_h ,0]
DMDSTR 3,12,buff,1




ani_r=%10101011
ARRAYWRITE BUFF,[bin8 ani_r ,0]
DMDSTR 3,20,buff,1


X VAR WORD




x = ani_r;
x = (x ^ (x << 4)) & $0f0f;
x = (x ^ (x << 2)) & $3333;
x = (x ^ (x << 1)) & $5555;
ani_h = x | (x << 1);




ARRAYWRITE BUFF,[bin16 ani_h ,0]
DMDSTR 3,28,buff,1

gosub show



stop


'************************************************* ***************'* Name : st7920.pbpmod *
'* Author : richard *
'* Notice : Copyright (c) 2021 caveat emptor *
'* : All Rights Reserved *
'* Date : 23/10/2021 *
'* Version : 1.0 *
'* Notes : R/W NOT USED, HAS FRAME BUFFER INSTEAD *
'* : LEVERAGES PBP LCD ROUTINES *
'************************************************* ***************
'SCREEN MAP 128X64
'ROW COLUMNS [WORDS]
' 0 | 0 1... 6 7
' . |
' . |
' . |
' 30|
' 31| 0 1... 6 7
' 0 | 8 9...14 15
' . |
' . |
' 30|
' 31| 8 9...14 15


' usual LCD defines are used eg


' DEFINE LCD_BITS 4 'defines the number of data interface lines (4 or 8)
' DEFINE LCD_DREG PORTB 'defines the port where data lines are connected to
' DEFINE LCD_DBIT 0 'defines the position of data lines for 4-bit interface (0 or 4)
' DEFINE LCD_RSREG PORTB 'defines the port where RS line is connected to
' DEFINE LCD_RSBIT 6 'defines the pin where RS line is connected to
' DEFINE LCD_EREG PORTB 'defines the port where E line is connected to
' DEFINE LCD_EBIT 4 'defines the pin where E line is connected
' DEFINE LCD_COMMANDUS 1000 'defines the delay after LCDOUT statement
' DEFINE LCD_DATAUS 40 'delay in micro seconds
' DEFINE LCD_RWREG PORTB ' LCD read/write port
' DEFINE LCD_RWBIT 5 ' LCD read/write pin bit
''END of LCD DEFINES




st7920_page var byte
st7920_gli var byte
st7920_inx var word
st7920_tmx var word
st7920_lfx var word
st7920_bf var byte






goto overst7920
#ifndef stserial
'4 or 8 bit parallel normsl pbp lcd defs
st7920_init:
lcdout $FE,$24 'In same instruction cannot alter DL, RE and G at once. Make sure that change DL or G first and then RE.
lcdout $FE,$26
bgcolour = 0
colour = 1
return


st7920_send: 'd in R3
@ L?CALL lcdsend
return





st7920_busy:
TRISB=TRISB&240
ASM
MOVLW 0X0F
IORWF LCD_DREG+0X12,F
bsf LCD_RWREG ,LCD_RWBIT
NOP
bcf LCD_RSREG ,LCD_RSBIT
NOP
bsf LCD_EREG ,LCD_EBIT
NOP
NOP
NOP
NOP
MOVFF LCD_DREG ,_st7920_bf
MOVF LCD_DREG,W
BANKSEL _st7920_bf
MOVWF _st7920_bf
bcf LCD_EREG ,LCD_EBIT
NOP
NOP
NOP
NOP
bsf LCD_EREG ,LCD_EBIT
NOP
NOP
NOP
NOP
bcf LCD_EREG ,LCD_EBIT
NOP
NOP
NOP
NOP
bsf LCD_RSREG ,LCD_RSBIT
bcf LCD_RWREG ,LCD_RWBIT
NOP
NOP
MOVLW 0XF0
ANDWF LCD_DREG+0X12,F
BANKSEL 0
ENDASM
RETURN

setxy:
GOSUB st7920_busy
IF st7920_bf.3 THEN GOTO setxy
ASM
MOVLW 128
BANKSEL _st7920_gli
IORWF _st7920_gli,W
BANKSEL R3
MOVWF R3
bcf LCD_RSREG ,LCD_RSBIT
MOVE?CT 1,FLAGS ,0
L?CALL _st7920_send
MOVLW 128
BANKSEL _st7920_page
IORWF _st7920_page,W
BANKSEL R3
MOVWF R3
bcf LCD_RSREG ,LCD_RSBIT
MOVE?CT 1,FLAGS ,0
L?CALL _st7920_send
BANKSEL 0
ENDASM
return
senddat16:
GOSUB st7920_busy
IF st7920_bf.3 THEN GOTO setxy
asm
MOVE?BB _st7920_tmx ,R3
bsf LCD_RSREG ,LCD_RSBIT
MOVE?CT 1,FLAGS ,0
L?CALL _st7920_send
bsf LCD_RSREG ,LCD_RSBIT
MOVE?BB _st7920_tmx+1 ,R3
MOVE?CT 1,FLAGS ,0
L?CALL _st7920_send
BANKSEL 0
ENDASM


return
show: 'SEE MAP
for st7920_GLi = 0 to 31
st7920_page = 0
gosub setxy
st7920_inx = st7920_gli*16
for st7920_page = 0 TO 7 ;IS WORDS 0-7 IN TOP HALF
st7920_tmx.lowbyte = fbr[st7920_inx] REV 8
st7920_inx = st7920_inx + 1
st7920_tmx.highbyte = fbr[st7920_inx] REV 8
st7920_inx = st7920_inx + 1
gosub senddat16
next
st7920_inx = st7920_gli*16+512
for st7920_page = 0 TO 7 ;IS WORDS 8-15 IN BOTTOM HALF
st7920_tmx.lowbyte = fbr[st7920_inx] REV 8
st7920_inx = st7920_inx + 1
st7920_tmx.highbyte = fbr[st7920_inx] REV 8
st7920_inx = st7920_inx + 1
gosub senddat16
next
next
return


;spi
#else
st7920_dat var byte
'spi pins used
st7920_cs var latc.1
'st7920_sck is latc.3
'st7920_sdi is latc.4
'st7920_sdo is latc.5


st7920_init:
SSP1CON1=$22 ;$22 fastest that works @64m
SSP1STAT=$40
st7920_cs=1
st7920_dat = %00001100
gosub ST7920Command
st7920_cs=0
pause 20
st7920_cs=1
st7920_dat = %00100100 ; //EXTENDED INSTRUCTION SET
gosub ST7920Command
st7920_dat = %00100110 ; //EXTENDED INSTRUCTION SET
gosub ST7920Command
st7920_cs=0
bgcolour = 0
colour = 1
return


setxy:
st7920_dat = st7920_gli| 128
gosub ST7920Command
st7920_dat = st7920_page| 128
gosub ST7920Command
return




ST7920Data:
PIR1.3=0
SSP1BUF = %11111010
WHILE !PIR1.3 : wend
PIR1.3=0
SSP1BUF = (st7920_dat & %11110000)
WHILE !PIR1.3 : wend
PIR1.3=0
SSP1BUF = (st7920_dat<< 4)
WHILE !PIR1.3 : wend
pauseus 50
return


ST7920Command:
PIR1.3=0
SSP1BUF = %11111000
WHILE !PIR1.3 : wend
PIR1.3=0
SSP1BUF = st7920_dat & %11110000
WHILE !PIR1.3 : wend
PIR1.3=0
SSP1BUF = (st7920_dat<< 4)
WHILE !PIR1.3 : wend
pauseus 100
return


show: 'SEE MAP
for st7920_GLi = 0 to 31
st7920_cs=1
st7920_page = 0
gosub setxy
st7920_inx = st7920_gli*16
for st7920_page = 0 TO 7 ;IS WORDS 0-7 IN TOP HALF
st7920_dat = fbr[st7920_inx] REV 8
gosub ST7920data
st7920_inx = st7920_inx + 1
st7920_dat = fbr[st7920_inx] REV 8
gosub ST7920data
st7920_inx = st7920_inx + 1
next
st7920_inx = st7920_gli*16+512
for st7920_page = 0 TO 7 ;IS WORDS 8-15 IN BOTTOM HALF
st7920_dat = fbr[st7920_inx] REV 8
gosub ST7920data
st7920_inx = st7920_inx + 1
st7920_dat = fbr[st7920_inx] REV 8
gosub ST7920data
st7920_inx = st7920_inx + 1
next
st7920_cs=0
next
return


senddat16:
st7920_dat = st7920_tmx REV 8
gosub ST7920data
st7920_dat = (st7920_tmx>>8) REV 8
gosub ST7920data
return
#endif






overst7920:

rocket_troy
- 5th September 2022, 01:23
Hi Richard,
Ordered a couple of st7920 displays for this and in the mean time I'm revisiting the Nokia display. 1 question: you're driving the 18F26K22 @64MHz for the sample codes; is that necessary? Can I drive the display using the same processor at, say, 16 MHz?

Thanks,

Troy

richard
- 5th September 2022, 02:54
1 question: you're driving the 18F26K22 @64MHz for the sample codes; is that necessary? Can I drive the display using the same processor at, say, 16 MHz?
no not essential any speed will work, its just slower. the hw 12c / spi speeds can be tweaked in some cases to compensate

rocket_troy
- 20th September 2022, 00:58
Hi Richard,
I've received my "st7920" displays from China (at least they're supposed to be) but I can't get anything from them from running your original code attachments in post #26. I haven't tried any of the code in #27 yet as I'm having problems with the "st7920.pbpmod" code having duplicate subroutines???
Anyway, can you possibly post a link or example of the wiring to this display. So far, I've connected all the 4 data lines, E bit, RS & RW bits to the declared PortB pins in your code. I've connected the V0 pin via a 10K pot and I've pulled up the serial/parallel selection pin to parallel selection and of course connected the power rails.

Thanks,

Troy

richard
- 20th September 2022, 01:48
for parallel i/f the connections are as defined
'LCD defines begin here
' DEFINE LCD_BITS 4 'defines the number of data interface lines (4 or 8)
' DEFINE LCD_DREG PORTB 'defines the port where data lines are connected to
' DEFINE LCD_DBIT 0 'defines the position of data lines for 4-bit interface (0 or 4)
' DEFINE LCD_RSREG PORTB 'defines the port where RS line is connected to
' DEFINE LCD_RSBIT 6 'defines the pin where RS line is connected to
' DEFINE LCD_EREG PORTB 'defines the port where E line is connected to
' DEFINE LCD_EBIT 4 'defines the pin where E line is connected
' DEFINE LCD_COMMANDUS 1500 'defines the delay after LCDOUT statement
' DEFINE LCD_DATAUS 60 'delay in micro seconds
' DEFINE LCD_RWREG PORTB ' LCD read/write port
' DEFINE LCD_RWBIT 5 ' LCD read/write pin bit
' 'END of LCD DEFINES

for serial i/f the connections are the mssp sdi sdo sck pins plus what you pick for st7920_cs
the st7920_rst pin was not required in my tests.

for a 26k22 i used
'spi pins used
'st7920_rst var latc.0
st7920_cs var latc.1
'st7920_sck is latc.3
'st7920_sdi is latc.4
'st7920_sdo is latc.5


I'm having problems with the "st7920.pbpmod" code having duplicate subroutines???
there is no problem pbp just doesn't understand conditional compilation, ignore the warnings

rocket_troy
- 20th September 2022, 02:46
there is no problem pbp just doesn't understand conditional compilation, ignore the warnings

Maybe it's because I thought I needed to compile that include file (on its own) where I probably don't?

Anyway... hmmm... I'll recheck everything and maybe try the serial option if I can't get the parallel working. So far I can't see anything I was doing wrong.

Cheers,

Troy

richard
- 20th September 2022, 04:16
Maybe it's because I thought I needed to compile that include file (on its own)

include files will seldom if ever compile on their own

rocket_troy
- 20th September 2022, 23:28
include files will seldom if ever compile on their own

Cool. I think the parallel version did which probably gave me the wrong assumptions. Anyway... couldn't get the parallel option working after trying both displays and throwing everything at it. I'm guessing there was a jumper fuse on the display that needed soldering closed to configure the data lines from 8 to 4, but I couldn't find any datasheet for the display so gave up that and went to serial. Took a bit of head scratching to match up the I2C lines to completely different labelled pads on the display, and then I finally got something from the display - a bunch of plain (non graphical looking) 1s and 0s. Took me 5-10 mins to figure out that's actually what was supposed to be there for the serial code - I was expecting demo graphics and large text - but that simply required copying over that stuff from the parallel code.
So, good stuff again Richard. Hats off and thanks again for the assistance.

Cheers,

Troy

richard
- 20th September 2022, 23:46
glad you got something to work

for parallel mode there is a pin PSB that needs to be set high on the display low for serial

i used this ds for reference

rocket_troy
- 21st September 2022, 00:03
for parallel mode there is a pin PSB that needs to be set high on the display low for serial

yeah, I knew about that - that's actually what I was referring to in my post #30, BUT what I didn't know (from glancing over the datasheet you just provided) was that I might have needed to pull data line #5 to ground to configure 4 line mode . Damn.

Cheers,

Troy

richard
- 21st September 2022, 00:50
i don't remember doing that and there was no pin on the 20 pin connector to do that. maybe there was a jumper on the display but i thought it was a software selection.
the parallel conn is on d3 - d7 with d0 - d3 grounded
the display is off in another project and no longer available to me for confirmation

rocket_troy
- 21st September 2022, 02:32
Well, there's 2 things I never considered - (1) using the upper 4 data lines for transfer and (2) grounding the unused.
It's probably worth mentioning (for a heads up to others) the display I'm using has a serial/parallel 3 pad jumper on the back that was soldered to parallel setting as purchased. I needed to change that to serial in order to operate in serial mode. Whether that eliminates the need to pull/push the PSB pad I never bothered finding out - I just assumed the PSB pad still needed setting.

edit: just after posting that I realised that jumper is probably a direct link to the PSB pad to push or pull - duh.

Troy

rocket_troy
- 3rd October 2022, 23:31
Richard,
Is it a big deal adding a character like a colon to the large font table? Working out the dot matrix for the character should be pretty straight forward, but not sure about the indexing and whatnot?

Thanks,

Troy

richard
- 4th October 2022, 01:16
you can use your own fonts Generated by MikroElektronika GLCD Font Creator 1.2.0.0
the font headers have some basic details on how to pbp-ify MikroElektronika fonts



;//Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0
;//MikroElektrnika 2011
;//http://www.mikroe.com
;
;//GLCD FontName : Comic_Sans_MS10x14
;//GLCD FontSize : 10 x 14
; needs a few tweaks for pbp weaknesses
;no odd data lines allowed ,shift bytes up to even lines out , no commas on line ends
;do not add or remove any bytes
;const char bignum[] = {

rocket_troy
- 4th October 2022, 02:18
I've just tried that but I'm confused: I can pick a standard font and make something up from that using the tool, but what do I do then? Do I "export" it? Exporting, produces the matrix of hex codes for the font graphics but that's all it produces. The largenum and bigchar files you included have many lines of headers? footers? whatever... above and below the font dot matrix codes and the export button that I'm clicking doesn't appear to generate any of that and it's not really clear what those lines are?

Regards,

Troy

richard
- 4th October 2022, 02:49
have a look here
http://www.picbasic.co.uk/forum/showthread.php?t=24171

rocket_troy
- 6th October 2022, 04:47
Thanks. That link eventually lead to the TFT export option needing to be visible to click on. Alas, that appears not useful without some kind of description of what those headers represent. Intuitively I would've thought they'd be some kind of memory addressing but they can't be. The 1st column looks like the font width but no idea what the second byte represents?

Regards,

Troy

richard
- 6th October 2022, 05:20
you need to be more explicit, i cannot see the problem

here is the raw " C " code as exported for chrs 48 to 60 as 11 x 16 sized font

you simply need to make it comply with pbp limitations , thats it you don't have to understand it
its pretty simple anyway

0x00, unused
0x00, unused
0x30,0x00, first chr
0x3C,0x00, last chr
0x10, height
0x00,

0x0B,0x3C,0x00,0x00, width of chr1. offset to font data for chr 1
0x0A,0x5C,0x00,0x00, width of chr2. offset to font data for chr2
0x0B,0x7C,0x00,0x00, width of chr3. offset to font data for chr 3
...






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


//GLCD FontName : Terminal11x16
//GLCD FontSize : 11 x 16


const unsigned short Terminal11x16[] = {
0x00,
0x00,
0x30,0x00,
0x3C,0x00,
0x10,
0x00,
0x0B,0x3C,0x00,0x00,
0x0A,0x5C,0x00,0x00,
0x0B,0x7C,0x00,0x00,
0x0B,0x9C,0x00,0x00,
0x0B,0xBC,0x00,0x00,
0x0B,0xDC,0x00,0x00,
0x0B,0xFC,0x00,0x00,
0x0B,0x1C,0x01,0x00,
0x0B,0x3C,0x01,0x00,
0x0B,0x5C,0x01,0x00,
0x06,0x7C,0x01,0x00,
0x06,0x8C,0x01,0x00,
0x09,0x9C,0x01,0x00,
0xF8,0x00,0xFE,0x03,0x06,0x03,0x03,0x07,0x83,0x07, 0xC3,0x06,0x63,0x06,0x33,0x06,0x1B,0x06,0x0F,0x06, 0x07,0x06,0x06,0x03,0xFE,0x03,0xF8,0x00,0x00,0x00, 0x00,0x00, // Code for char num 48
0x60,0x00,0x70,0x00,0x7C,0x00,0x7C,0x00,0x60,0x00, 0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x00, 0x60,0x00,0x60,0x00,0xFC,0x03,0xFC,0x03,0x00,0x00, 0x00,0x00, // Code for char num 49
0xFC,0x01,0xFE,0x03,0x07,0x07,0x03,0x06,0x03,0x07, 0x80,0x03,0xC0,0x01,0xE0,0x00,0x70,0x00,0x38,0x00, 0x1C,0x00,0x0E,0x00,0xFF,0x07,0xFF,0x07,0x00,0x00, 0x00,0x00, // Code for char num 50
0xFC,0x01,0xFE,0x03,0x07,0x07,0x03,0x06,0x00,0x06, 0x00,0x07,0xF8,0x03,0xF8,0x01,0x00,0x03,0x00,0x06, 0x03,0x06,0x07,0x07,0xFE,0x03,0xFC,0x01,0x00,0x00, 0x00,0x00, // Code for char num 51
0xC0,0x01,0xE0,0x01,0xF0,0x01,0xB8,0x01,0x9C,0x01, 0x8E,0x01,0x87,0x01,0x83,0x01,0xFF,0x07,0xFF,0x07, 0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x00,0x00, 0x00,0x00, // Code for char num 52
0xFF,0x07,0xFF,0x07,0x03,0x00,0x03,0x00,0x03,0x00, 0xFF,0x01,0xFE,0x03,0x00,0x07,0x00,0x06,0x00,0x06, 0x03,0x06,0x07,0x07,0xFE,0x03,0xFC,0x01,0x00,0x00, 0x00,0x00, // Code for char num 53
0xE0,0x01,0xF0,0x01,0x38,0x00,0x1C,0x00,0x0E,0x00, 0x06,0x00,0xFF,0x01,0xFF,0x03,0x07,0x07,0x03,0x06, 0x03,0x06,0x07,0x07,0xFE,0x03,0xFC,0x01,0x00,0x00, 0x00,0x00, // Code for char num 54
0xFF,0x07,0xFF,0x07,0x00,0x03,0x00,0x03,0x80,0x01, 0x80,0x01,0xC0,0x00,0xC0,0x00,0x60,0x00,0x60,0x00, 0x30,0x00,0x30,0x00,0x18,0x00,0x18,0x00,0x00,0x00, 0x00,0x00, // Code for char num 55
0xF8,0x00,0xFC,0x01,0x8E,0x03,0x06,0x03,0x06,0x03, 0x8E,0x03,0xFC,0x01,0xFE,0x03,0x07,0x07,0x03,0x06, 0x03,0x06,0x07,0x07,0xFE,0x03,0xFC,0x01,0x00,0x00, 0x00,0x00, // Code for char num 56
0xFC,0x01,0xFE,0x03,0x07,0x07,0x03,0x06,0x03,0x06, 0x07,0x07,0xFE,0x07,0xFC,0x07,0x00,0x03,0x80,0x03, 0xC0,0x01,0xE0,0x00,0x7C,0x00,0x3C,0x00,0x00,0x00, 0x00,0x00, // Code for char num 57
0x00,0x00,0x00,0x00,0x38,0x38,0x38,0x00,0x00,0x00, 0x38,0x38,0x38,0x00,0x00,0x00, // Code for char num 58
0x00,0x00,0x00,0x00,0x38,0x38,0x38,0x00,0x00,0x00, 0x38,0x38,0x38,0x30,0x30,0x18, // Code for char num 59
0x80,0x01,0xC0,0x01,0xE0,0x00,0x70,0x00,0x38,0x00, 0x1C,0x00,0x0E,0x00,0x0E,0x00,0x1C,0x00,0x38,0x00, 0x70,0x00,0xE0,0x00,0xC0,0x01,0x80,0x01,0x00,0x00, 0x00,0x00 // Code for char num 60
};




becomes




;//Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0
;//MikroElektrnika 2011
;//http://www.mikroe.com
;
;//GLCD FontName : Terminal11x16
;//GLCD FontSize : 11 x 16
;
;const unsigned short Terminal11x16[] = {
0x00,0x00

0x30,0x00
0x3C,0x00
0x10,0x00

0x0B,0x3C,0x00,0x00
0x0A,0x5C,0x00,0x00
0x0B,0x7C,0x00,0x00
0x0B,0x9C,0x00,0x00
0x0B,0xBC,0x00,0x00
0x0B,0xDC,0x00,0x00
0x0B,0xFC,0x00,0x00
0x0B,0x1C,0x01,0x00
0x0B,0x3C,0x01,0x00
0x0B,0x5C,0x01,0x00
0x06,0x7C,0x01,0x00
0x06,0x8C,0x01,0x00
0x09,0x9C,0x01,0x00
0xF8,0x00,0xFE,0x03,0x06,0x03,0x03,0x07,0x83,0x07, 0xC3,0x06,0x63,0x06,0x33,0x06,0x1B,0x06,0x0F,0x06, 0x07,0x06,0x06,0x03,0xFE,0x03,0xF8,0x00,0x00,0x00, 0x00,0x00 ; Code for char num 48
0x60,0x00,0x70,0x00,0x7C,0x00,0x7C,0x00,0x60,0x00, 0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x00, 0x60,0x00,0x60,0x00,0xFC,0x03,0xFC,0x03,0x00,0x00, 0x00,0x00 ; Code for char num 49
0xFC,0x01,0xFE,0x03,0x07,0x07,0x03,0x06,0x03,0x07, 0x80,0x03,0xC0,0x01,0xE0,0x00,0x70,0x00,0x38,0x00, 0x1C,0x00,0x0E,0x00,0xFF,0x07,0xFF,0x07,0x00,0x00, 0x00,0x00 ; Code for char num 50
0xFC,0x01,0xFE,0x03,0x07,0x07,0x03,0x06,0x00,0x06, 0x00,0x07,0xF8,0x03,0xF8,0x01,0x00,0x03,0x00,0x06, 0x03,0x06,0x07,0x07,0xFE,0x03,0xFC,0x01,0x00,0x00, 0x00,0x00 ; Code for char num 51
0xC0,0x01,0xE0,0x01,0xF0,0x01,0xB8,0x01,0x9C,0x01, 0x8E,0x01,0x87,0x01,0x83,0x01,0xFF,0x07,0xFF,0x07, 0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x00,0x00, 0x00,0x00 ; Code for char num 52
0xFF,0x07,0xFF,0x07,0x03,0x00,0x03,0x00,0x03,0x00, 0xFF,0x01,0xFE,0x03,0x00,0x07,0x00,0x06,0x00,0x06, 0x03,0x06,0x07,0x07,0xFE,0x03,0xFC,0x01,0x00,0x00, 0x00,0x00 ; Code for char num 53
0xE0,0x01,0xF0,0x01,0x38,0x00,0x1C,0x00,0x0E,0x00, 0x06,0x00,0xFF,0x01,0xFF,0x03,0x07,0x07,0x03,0x06, 0x03,0x06,0x07,0x07,0xFE,0x03,0xFC,0x01,0x00,0x00, 0x00,0x00 ; Code for char num 54
0xFF,0x07,0xFF,0x07,0x00,0x03,0x00,0x03,0x80,0x01, 0x80,0x01,0xC0,0x00,0xC0,0x00,0x60,0x00,0x60,0x00, 0x30,0x00,0x30,0x00,0x18,0x00,0x18,0x00,0x00,0x00, 0x00,0x00 ; Code for char num 55
0xF8,0x00,0xFC,0x01,0x8E,0x03,0x06,0x03,0x06,0x03, 0x8E,0x03,0xFC,0x01,0xFE,0x03,0x07,0x07,0x03,0x06, 0x03,0x06,0x07,0x07,0xFE,0x03,0xFC,0x01,0x00,0x00, 0x00,0x00 ; Code for char num 56
0xFC,0x01,0xFE,0x03,0x07,0x07,0x03,0x06,0x03,0x06, 0x07,0x07,0xFE,0x07,0xFC,0x07,0x00,0x03,0x80,0x03, 0xC0,0x01,0xE0,0x00,0x7C,0x00,0x3C,0x00,0x00,0x00, 0x00,0x00 ; Code for char num 57
0x00,0x00,0x00,0x00,0x38,0x38,0x38,0x00,0x00,0x00, 0x38,0x38,0x38,0x00,0x00,0x00 ; Code for char num 58
0x00,0x00,0x00,0x00,0x38,0x38,0x38,0x00,0x00,0x00, 0x38,0x38,0x38,0x30,0x30,0x18 ; Code for char num 59
0x80,0x01,0xC0,0x01,0xE0,0x00,0x70,0x00,0x38,0x00, 0x1C,0x00,0x0E,0x00,0x0E,0x00,0x1C,0x00,0x38,0x00, 0x70,0x00,0xE0,0x00,0xC0,0x01,0x80,0x01,0x00,0x00, 0x00,0x00 ; Code for char num 60
; };

rocket_troy
- 6th October 2022, 05:28
Thanks Richard. DUH [slapping forehead again]. I didn't read them properly, nevertheless, you told me everything and more with that description and I'm once again eternally grateful.

Cheers,

Troy

richard
- 6th October 2022, 05:31
one more thing
both pbp and mpasm have limitations on line length , exceed them at your peril

and always have an even number of bytes ie not odd on every line line other wise pbp will pad the odd byte with an extra 00 the offset indexing will fail.
do not add or delete any byte to the file or else the offset indexing will fail.

rocket_troy
- 6th October 2022, 06:11
Got it and working perfectly :)

Thanks again,

Ioannis
- 6th October 2022, 07:48
and always have an even number of bytes ie not odd on every line line other wise pbp will pad the odd byte with an extra 00 the offset indexing will fail.
do not add or delete any byte to the file or else the offset indexing will fail.

Good info! Thanks.
Is this referred to somewhere?

Ioannis

rocket_troy
- 10th October 2022, 13:36
Richard,
I'm just starting to experiment with displaying a simple number count ie. clearing the screen, incrementing a number and displaying that number using the larger numerical font and looping that process. So, everything's good until I'm getting to either 6 or 7 loops (doesn't matter what number I start with) and then something happens. The count stops where it should be displayed and appears to continue... like... 20 or so pixels above the nominated location and the font is now only 1 pixel high.
Any ideas what's happening or what I'm doing wrong?



DEFINE OSC 64



#DEFINE colours 1 ;1 mono 2 rg or 3 rgb
width con 128 ;
height con 64 ;
'use serial i/f
#define stserial 1
include "grx.pbpMOD"
include "st7920b.pbpmod"
include "font.bas"
include "bignum.bas"
include "bigchr.bas"
BUFF VAR BYTE[4]
ani_h var word bank0
ani_r var byte
ani_c var byte
OSCCON=$70
OSCTUNE.6=1
while ! osccon2.7 :WEND ;wait for pll
ANSELB=0
ANSELC=0
ANSELA=0

'trisc = %11010101 ;cs,sck,sdo are output
trisc = %11010101 ;cs,sck,sdo are output
TRISB = %11111111
TRISA = %11111111


n var word

gosub st7920_init 'graphic mode

OSCCON=$70
OSCTUNE.6=1
while ! osccon2.7 :WEND ;wait for pll

ANSELB=0
ANSELC=0
ANSELA=0

Pause 500 ' LCD initialize time
lcdout $FE,1
gosub st7920_init 'graphic mode

n=0

main

gosub grf_clr
n= n+1
SETFONT bignum
ARRAYWRITE BUFF,[dec4 n]
DMDSTR 40,30, Buff,1
gosub show
pause 1000

goto main

richard
- 10th October 2022, 22:06
BUFF VAR BYTE[4] is too small to hold a 4 digit null terminated string it must be digits + 1

ARRAYWRITE BUFF,[dec4 n] is not a null terminated string ARRAYWRITE BUFF,[dec4 n,0] is


SETFONT bignum should not be in the loop , you only need to set the font once unless you want to change to another font

rather than clearing the whole screen you can "FILLRECT" with the background colour for a restricted area to clr







DEFINE OSC 64
#DEFINE colours 1 ;1 mono 2 rg or 3 rgb
width con 128 ;
height con 64 ;
'use serial i/f
#define stserial 1
include "grx.pbpMOD"
include "st7920b.pbpmod"
include "font.bas"
include "bignum.bas"
include "bigchr.bas"
BUFF VAR BYTE[32]
OSCCON=$70
OSCTUNE.6=1
while ! osccon2.7 :WEND ;wait for pll
ANSELB=0
ANSELC=0
ANSELA=0

'trisc = %11010101 ;cs,sck,sdo are output
trisc = %11010101 ;cs,sck,sdo are output
TRISB = %11111111
TRISA = %11111111



n var word


gosub st7920_init 'graphic mode


OSCCON=$70
OSCTUNE.6=1
while ! osccon2.7 :WEND ;wait for pll

ANSELB=0
ANSELC=0
ANSELA=0

Pause 500 ' LCD initialize time
lcdout $FE,1
gosub st7920_init 'graphic mode
gosub grf_clr
n=0
SETFONT bignum


main:
n= n+1
colour=bgcolour
fillrect 39,29,70,20 ; this is a guess about your font size
ARRAYWRITE BUFF,[dec4 n,0]
DMDSTR 40,30, Buff,1
gosub show
pause 1000

goto main

rocket_troy
- 11th October 2022, 01:29
Good suggestions thanks again. Yeah ARRAYWRITE BUFF,[dec4 n,0] was producing the same results so I changed it to see what happened and didn't get around to changing it back - will do though.

Troy

rocket_troy
- 11th October 2022, 01:33
One more thing - it's a monochrome LCD display, so the colour of the clearing rectangle would be 0 ?

Thanks,

Troy

richard
- 11th October 2022, 02:57
One more thing - it's a monochrome LCD display, so the colour of the clearing rectangle would be 0 ?


COLOUR [COLOUR] = 1 OR 0
BACKGROUND COLOUR [BGCOLOUR] = 1 OR 0

take your pick provided COLOUR <> BGCOLOUR for writing stuff that you can see

rocket_troy
- 11th October 2022, 03:49
Ah, got it. Glad I asked coz I never would've realized you can simply invert the display that simply :)

rocket_troy
- 11th October 2022, 11:40
Richard,
Unfortunately none of those suggestions fixed the issue:( In fact maybe the RECTFILL made it worse. If I remove all calls for screen clearing within the loop so there's only really the allocating the characters and the "show" call, the output (result) is the same so the issue appears to be with either the DMDSTR or gosub show calls I imagine?

Troy

rocket_troy
- 11th October 2022, 15:02
I've isolated the problem is somewhere within the "show" call. Not sure what it is, but that's definitely the issue. Also, I'm not totally convinced FILLRECT works properly either. DRAWRECT definitely works better for me.

Troy

richard
- 11th October 2022, 23:27
post your code and i will have a look
it works ok for me

https://youtu.be/Jxd4a4XmuDo





'************************************************* ***************
(https://youtu.be/Jxd4a4XmuDo)'* Name : UNTITLED.BAS *
'* Author : richard *
'* Notice : Copyright (c) 2022 caveat emptor *
'* : All Rights Reserved *
'* Date : 11/10/2022 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
#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 = OFF
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





DEFINE OSC 64
DEFINE DEBUG_REG PORTB
DEFINE DEBUG_BIT 7
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0
LATB.7=1



#DEFINE colours 1 ;1 mono 2 rg or 3 rgb
width con 128 ;
height con 64 ;
'use serial i/f
#define stserial 1
include "grx.pbpMOD"
include "st7920.pbpmod"
include "font.bas"
include "bignum.bas"
include "bigchr.bas"
BUFF VAR BYTE[32]
OSCCON=$70
OSCTUNE.6=1
while ! osccon2.7 :WEND ;wait for pll
ANSELB=0
ANSELC=0
ANSELA=0
' serial spi pins used
' e is sck latc.3
' rw is sdo latc.5
' rs is cs latc.1
'trisc = %11010101 ;cs,sck,sdo are output
trisc = %11010101 ;cs,sck,sdo are output
TRISB = %11111111
TRISA = %11111111



n var word


gosub st7920_init 'graphic mode


OSCCON=$70
OSCTUNE.6=1
while ! osccon2.7 :WEND ;wait for pll

ANSELB=0
ANSELC=0
ANSELA=0

Pause 500 ' LCD initialize time
lcdout $FE,1
gosub st7920_init 'graphic mode
gosub grf_clr
n=0
SETFONT bignum
bgcolour=0

main:
n= n+1
colour=1
fillrect 39,29,46,16 ; this is a guess about your font size
ARRAYWRITE BUFF,[dec4 n,0]
DMDSTR 40,30, Buff,0
colour=0
fillrect 39,9,46,16 ; this is a guess about your font size
DMDSTR 40,10, Buff,1
gosub show
pause 1000

goto main
(https://youtu.be/Jxd4a4XmuDo)

rocket_troy
- 11th October 2022, 23:48
Damn, maybe its my display modules. Your latest code doesn't appear to work properly either on mine.

So close... everything appears to display correctly* but craps itself after a few screen redraws :(

Troy

*with the exception of FILLRECT

richard
- 12th October 2022, 00:40
i fiddle with the files to suit other projects maybe what you have is out of date

rocket_troy
- 12th October 2022, 02:10
No luck. There is something I should've mentioned though: in post #31 you list the pin connections:

for a 26k22 i used
'spi pins used
'st7920_rst var latc.0
st7920_cs var latc.1
'st7920_sck is latc.3
'st7920_sdi is latc.4
'st7920_sdo is latc.5

Now, I don't have "st7920_sdi is latc.4" connected because I have no idea what to connect it to. Could that be the killer?

Troy

richard
- 12th October 2022, 02:40
no it has no connection , but its best not to try and use that pin for other purposes the mssp module owns it
the only other conn i have is psb is grounded
are you using my exact code ?

rocket_troy
- 12th October 2022, 03:32
Yeah, started out with the exact code, those latest graphics and LCD controller files and then (after running that) started tweaking the demo code in an attempt to get something working. Can post a video of the output if that helps or happy to send you a module if you're interested in trying one. I've ordered another flavour of st7920 controlled displays from China, so fingers crossed it's better behaved.

Troy

rocket_troy
- 12th October 2022, 04:40
There's one other thing I haven't done which might be required. I haven't pulled up the I2C clock or data lines with weak pull up resistors. Because the static display code appeared to be working well, I assumed it was done within the display module.

Troy

richard
- 12th October 2022, 04:57
its not i2c its spi , there is no need for pullups.
one thing i notice is my display cannot be reset with a pic pin it just won't pull the pin low enough . shit design.
so i have included no reset function. to test i always power the display off/on as it can go to gaga land easily.

in general a shit display if you don't have need for the usual "LCD commands" it can support along with graphics in parallel i/f mode
or the reduced pin count of the serial i/f.
the 20pin h64128 is better imo

rocket_troy
- 12th October 2022, 06:22
I have a few 18F26K83s that I've used for various projects. Worth trying one of these? They can source/sink twice the current on each pin apparently.

Scrub that... Different architecture

Troy

richard
- 12th October 2022, 07:05
how good is your power supply and your connections ?
reset wont help here if it starts up ok
if you want you can pm me to get my address to send a display to be evaluated

rocket_troy
- 12th October 2022, 22:25
Power supply going into the PIC was a PicKit2 and that doesn't appear to be the issue. I was doing all these tests on a 18F26K22 SOIC package. After you mentioned the power requirements issues, I tried it on the larger DIP package and that appears to have fixed the show-stopping issue of screen regeneration. FILLRECT still doesn't work correctly, but that's a peripheral issue for me. I can at least now use these displays for the apps I had in mind.

Thanks again for all the assistance Richard.

Troy

richard
- 13th October 2022, 10:32
on q43 chips i have to set the high slew rate settings on for really highspeed spi
the k22 has slew rate control SLRCON.2 for portc , can't hurt to try

rocket_troy
- 13th October 2022, 12:17
Worked! I can now run things on the smaller package.

Legend!

Troy

rocket_troy
- 14th October 2022, 01:26
Richard,
Curious Question:
I was feeding a 10bit rotary encoder into the PIC (RB0-RB5 & RA0-RA3) with the display connected and I was stumped to figure out why I wasn't getting any input signal into the PortA pins and also 1 of the PortB pins. After a while I realised they were acting as outputs not inputs even though I declared them as inputs before the display initialisation. After some head scratching, I tried setting their TRIS status *after* the display initialisation and that appeared to fix that. So, I think I can maybe see where the PortB pin may have been set (behind the scenes), but can't see where the PortA pins where set as outputs? Does that have anything to do with the LCDOUT command call in the initialisation instructions?

Troy

rocket_troy
- 14th October 2022, 02:15
Another Question:
In your graphics file for the FillRect code you have:

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

Shouldn't that line be s_xend=x1+s_xend-1 ?

Troy

richard
- 14th October 2022, 02:34
Does that have anything to do with the LCDOUT command call in the initialisation instructions?

if you mean the highlighted text below , then yes that an error and should be removed for serial i/f usage
and may impact portb


ANSELB=0
ANSELC=0
ANSELA=0
Pause 500 ' LCD initialize time
lcdout $FE,1
gosub st7920_init 'graphic mode
gosub grf_clr
n=0
setfont FONT5x7
ARRAYWRITE BUFF,["- scroll test -"]
DMDSTR 18,0, Buff,1
ARRAYWRITE BUFF,["- some text to test -"]
DMDSTR 6,8, Buff,1
SETFONT bignum
bgcolour=0
direction=0
gosub show
main:
n= n+1





Shouldn't that line be s_xend=x1+s_xend-1 ?

my ver is , you are using an old version , the ver of grx.pbpmod in post 10 has vertical line fixed but fillrect got mangled
post 59 ver has both of those fixed , yet to discover what else may be broken



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

rocket_troy
- 14th October 2022, 03:27
Cool, so assuming that fixes the FillRect (I'll find out this evening) everything should be dandy.

Troy

rocket_troy
- 24th October 2022, 05:03
Hi Richard,
Finished up giving up on the serial connection as it was just a bit flaky ie. characters and graphics didn't always display cleanly etc. That might've been a wiring issue - not sure. Anyhow, with your advice on the parallel interface (using the higher 4 bits & grounding the lower 4) I got that working and it appears to be much cleaner.
Question on fonts: I was trying to make some 28pt fonts but there appeared to be some overrun. Scaled back to 24 and that appeared to work fine. So, there's a size limit on fonts around that 24pt size?

Thanks,

Troy

richard
- 24th October 2022, 05:34
post#1


i wrote this graphics lib to handle led dmd's [1/4 scan dot matrix displays] in mono, red/green or rgb in varing sizes up to 128x32 pixels.
it occured to me that with a little more effort it would make a general purpose graphic lib for nearly any display. so here it is.
it uses mikroe fonts that you can easily generate. the variable width fonts can be up to 23 bits wide if you like.


no guarantee 24 bit wide will be reliable either

rocket_troy
- 24th October 2022, 05:42
Okay, so fixed widths can have a wider limitation?

Troy

richard
- 24th October 2022, 06:20
no there are no fixed width fonts not that that would alter anything.
the mask is 32bits wide that is used to insert the font row data into the graphics frame memory, 23 bits font + 8 bits to allow insertion at any bit point offset + 1 clr column between chars = 32 bits. to get to 24 bits the mask would need to be 48 bits wide [needs 16 bits to allow insertion at any bit point offset], the code size would double the speed halve. any font over 23 bits wide will intrude on its neighboring chars space at some bit offsets

rocket_troy
- 24th October 2022, 06:28
Thanks Richard, that clears that up. No biggy anyway.

edit: actually the one working fine was 18x24 (I was mixing up the width & height)

Troy

richard
- 12th January 2023, 01:44
a driver for the sharp memory lcd's to add to the list

Ioannis
- 12th January 2023, 14:04
Hi Richard.

Which LCD is this?

Your lib file looks more like an example file. Is it correct?

Ioannis

richard
- 12th January 2023, 19:33
Your lib file looks more like an example file. Is it correct ?

it is. it's the driver component to enable my graphics library to use a sharp memory display.
post #1 has typical use demos!

richard
- 26th December 2023, 23:46
update to ssd1306 include to allow easier configuration for 40x72 displays

eg


'************************************************* ***************'* Name : SSD1306 FOR PIC 18 DEMO *
'* Author : Richard *
'* Notice : *
'* : *
'* Date : 27/12/2023 *
'* Version : 1.0 *
'* Notes : *
'* :18f26k22 @64Mhz *
'************************************************* ***************


#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
DEFINE OSC 64
;set these to match display
ssd1306_addr con $78
#DEFINE colours 1 ;1 mono 2 rg or 3 rgb
width con 72;128
height con 40;64
h_offset con 28

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

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


gosub glcd_init
gosub grf_clr
SETFONT Arial_Narrow18x39
gosub show

main:
while j <1000
colour=1
fillrect 0,0,72,40
ARRAYWRITE BUFF,[dec2 j/10,":",dec1 j,0]
DMDSTR 1,0,buff,0
gosub show
pause 10
j=j+1
wend
j=0
goto main

Ioannis
- 27th December 2023, 09:10
Nice and useful addition to a very handy include file.

Though I wonder up to what age you can read that displays without eye glasses...

Ioannis

richard
- 27th December 2023, 09:30
Though I wonder up to what age you can read that displays without eye glasses...

that's kinda the purpose of this universal graphics method, fonts for it of a good size are simple to make and interchangeable
between versions and displays.
a 5x7 font on that display needs a magnifying glass and eye glasses for me.
note i used a 18x39 font to test with. that i can read from many metres away easily

richard
- 22nd February 2024, 23:06
bmp bug fix

spcw1234
- 23rd February 2024, 18:45
bmp bug fix

Working much better, but in my case it is cropping 6 columns off of the right side of the image (110x64). Using the pbp file I uploaded here (https://www.picbasic.co.uk/forum/showthread.php/23758-SSD1306-INCLUDE-for-PBP3?p=155256#post155256)

Here are 2 images of what it should look like (using SSDBM vs what is being displayed using DMDBMP.

9635 9636

richard
- 23rd February 2024, 19:34
the bmp image width needs to be a multiple of 8 by the look of it
post the original bmp image if you want me to look further into it

spcw1234
- 23rd February 2024, 22:08
Ok, I assume that is due to the horizontal vs vertical byte layout? I know on the SSDBM you said height must be multiple of 8 which I have been adhering to. I'll either stick to using the SSDBM with this driver as it seems to do exactly what I need or revise the bitmaps to make width a multiple of 8.

richard
- 24th February 2024, 00:03
i have had a look at how those programs [lcdassist and glcd tool] manage the remainder bits when a bitmap is not an 8bit multiple in width
and it defeats me , i cannot get how the "stray" bits of the image width are packed into the data
if you lay the data out to match the actual width x height as i have done here
[the last column i filled in manually only partially to get an idea of what the data needs to look like ]
the "left over" 48 bytes at the end somehow represents the extreme rhs 6 bits , i don't see how to extract the data correctly.
6 bits * 48 bytes is 384 bits , the stray 6 bits of width x 64 lines of height is 384 bits so there is enough information at least.
[assuming i have not misconstrued the original image]




OneIcon: '110x64 horiz
@ db 112, 0x40
@ db 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,0xfc
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0x00, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0x80, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0x80, 0x00, 0x00,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0x80, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xC0, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xC0, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xE0, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xF0, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xF0, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xF8, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xF8, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFE, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0x80, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0x80, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xC0, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xE0, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xF0, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFC, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFE, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0x80 ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0 ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x87, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ,0
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x04
@ db 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,0xfc


'@ db 0xFC, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00
'@ db 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x01, 0x00, 0x11, 0x00, 0x00, 0x00, 0x18, 0x00, 0x01, 0x00
'@ db 0x1A, 0x00, 0x04, 0x00, 0x28, 0x00, 0x02, 0x00, 0x38, 0x00, 0x00, 0x00, 0x4A, 0x02, 0x00, 0x00

spcw1234
- 24th February 2024, 16:15
Is there a way to do 90 degree screen rotation (using the display in portrait mode) for the text using fonts to be displayed correct?

Changing the SSDc $20 address to $01 seems to corrupt everything, so I'm not sure if I am going down the correct path with that, or if there is a simple way to accomplish this already built in?

spcw1234
- 24th February 2024, 18:54
The display layout still isn't quite right. Here is a simple program that displays a 16x16 image in all 4 corners the ones on the left side are good, but the right side locations are wrong.



'PIC18F26K22
#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
DEFINE OSC 64
clear
ssd1306_addr con $78
#DEFINE colours 1 ;1 mono 2 rg or 3 rgb
width con 128
height con 64
h_offset con 0

include "grx.pbpMOD"
include "SSD1306.pbpMOD"
BUFF VAR BYTE[32]
ANSELB=0
ANSELC=0
ANSELA=0
OSCCON=$70
OSCTUNE.6=1
gosub glcd_init
gosub grf_clr
gosub show

main: ' Rotate icon clockwise around display corners
DMDBMP 0,0,TestIcon 'top left 16x16 CORRECT PLACEMENT!
gosub show
pause 1000
gosub grf_clr
gosub show

DMDBMP 111,0,TestIcon 'top right 16x16 WRONT PLACEMENT!
gosub show
pause 1000
gosub grf_clr
gosub show

DMDBMP 111,47,TestIcon 'bottom right 16x16 WRONG PLACEMENT!
gosub show
pause 1000
gosub grf_clr
gosub show

DMDBMP 0,47,TestIcon 'bottom left 16x16 CORRECT PLACEMENT!
gosub show
pause 1000
gosub grf_clr
gosub show
goto main

end

TestIcon:
@ db 0x10,0x10 ;16x16
@ db 0xFF,0xFF;
@ db 0xC0,0x03;
@ db 0xA0,0x05;
@ db 0x90,0x09;
@ db 0x88,0x11;
@ db 0x84,0x21;
@ db 0x82,0x41;
@ db 0x81,0x81;
@ db 0x81,0x81;
@ db 0x82,0x41;
@ db 0x84,0x21;
@ db 0x88,0x11;
@ db 0x90,0x09;
@ db 0xA0,0x05;
@ db 0xC0,0x03;
@ db 0xFF,0xFF;


9640 9641 9642 9643

richard
- 24th February 2024, 22:37
bmp placement fixed , note that horiz placement is byte aligned ie for a 128 bit wide display there are 16 bytes therefore 16 positions max

spcw1234
- 25th February 2024, 00:10
Excellent! All seems to be working perfectly!

Now, how can I rotate the display for use in portrait mode?

richard
- 25th February 2024, 00:44
in theory portrait mode should be easier and faster than what i have now, the screen width 64 height 128
and the buffer sent to the screen in horiz fill mode nice and sequentially [ might need bit reversal, could be upside down or mirrored]
i will have a look one day time permitting

richard
- 25th February 2024, 01:27
a portrait version

9645



'************************************************* ******************
'* Name : SSD1306p.pbpmod *
'* Author : richard *
'* Notice : Copyright (c) 2021 *
'* : *
'* Date : 28/12/2023 *
'* Version : 1.1 *
'* Notes : generic GRX graphics DRIVER FOR SSD1306 *
'* : HW I2C PIC18 ONLY *
'* : 40x72 disp added *
'* : portrait version *
'* : *
'* : *
'************************************************* *********************
;set these to match display IN MAIN
' ssd1306_addr con $78
' #DEFINE colours 1 ;1 mono 2 rg or 3 rgb
' width con 128
' height con 32
' h_offset con 0 ;28 for 40x72



glrot var byte[8]
glrb var byte[8]
gltmp var byte[3]
glcd_rad var WORD
glcdData VAR byte 'DATA
glcdBC VAR BYTE 'gca var
page VAR WORD 'gca var
gy var byte 'gca pg address
gy_ var byte 'gca pg address
gx var byte 'gca row address
gx_ var byte 'gca row address
ssd_add var byte
USERCOMMAND "SENDBYTE" ;BYTE
USERCOMMAND "SSDC" ;cmd BYTE TO SSD1306
ssdheight con WIDTH/8-1 ; 7 = 8 PAGES 64*128 , 3 = 4 pages 32*128
ssdwidth con HEIGHT-1 ; 128 PIXELS WIDE

goto overssd
ASM
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
SENDBYTE?B macro Dat
MOVE?BB Dat ,_glcdData
L?CALL _send_byte
endm
SENDBYTE?W macro Dat
MOVE?WB Dat ,_glcdData
L?CALL _send_byte
endm
SENDBYTE?C macro Dat
MOVE?CB Dat ,_glcdData
L?CALL _send_byte
endm
ENDASM
glcd_init:
bgcolour = 0
colour = 1
SSPSTAT = 0 'High Speed Filter
SSPADD = $14'400 kHz @64 MHz ?
SSPCON1 = 101000 'I2C Master Mode Enable
SSPCON3 = 0
ssd_add = ssd1306_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 > 4 then
SSDc $40 ' Set display start line 0
elseif ssdheight > 3 then
SSDc $68 ' Set display start line
else
SSDc $60 ' Set display start line 4
endif
SSDc $8D : SSDc $14 ' Set Charge Pump Internal
SSDc $20 : SSDc $01 ' Adressing mode Horizontal
SSDc $A1 ' set segment remap column 127 as start
SSDc $C0 ' 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
show:
' gosub flip
SSDc $22
SSDc 0
SSDc ssdheight
SSDc $21
SSDc h_offset
SSDc ssdwidth + h_offset
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 SSP1STAT.2 = 1 : WEND ; SSPSTAT = 1 Transmit in progress
While SSP1CON2.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
for glcd_rad = 0 to width/8 * height -1
SENDBYTE fbr[glcd_rad ]
next
SSPCON2.2 = 1
' gosub flip
return
send_byte : 'DATA
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
return
cmd_byte: 'send command sequence "glcdData "
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 SSP1CON2.2 = 1 : Wend ; Wait for SSP to complete
return
overssd:



with demo




'PIC18F26K22#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
DEFINE OSC 64
clear
ssd1306_addr con $78
#DEFINE colours 1 ;1 mono 2 rg or 3 rgb
width con 64
height con 128
h_offset con 0
DEFINE DEBUG_REG PORTB
DEFINE DEBUG_BIT 7
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0
LATB.7=1
trisb.7=0
include "grx.pbpMOD"
include "SSD1306p.pbpMOD"
include "font.bas"
BUFF VAR BYTE[32]
ANSELB=0
ANSELC=0
ANSELA=0
OSCCON=$70
OSCTUNE.6=1
SETFONT FONT5x7
gosub glcd_init

main:
gosub grf_clr
gosub show
ARRAYWRITE BUFF,["GLCD",0]
DMDSTR 3,75,buff,1
DMDBMP 0,0,TestIcon
gosub show
pause 5000

goto main

end


TestIcon:
@ db 0x10,0x10 ;16x16
@ db 0xFF,0xFF;
@ db 0xC0,0x03;
@ db 0xA0,0x05;
@ db 0x90,0x09;
@ db 0x88,0x11;
@ db 0x84,0x21;
@ db 0x82,0x41;
@ db 0x81,0x81;
@ db 0x81,0x81;
@ db 0x82,0x41;
@ db 0x84,0x21;
@ db 0x88,0x11;
@ db 0x90,0x09;
@ db 0xA0,0x05;
@ db 0xC0,0x03;
@ db 0xFF,0xFF;

spcw1234
- 25th February 2024, 14:09
Excellent work Richard!!!

This will work well for my use, but with a little more tweaking it would be nice to have a define to set 1 of 4 different viewing directions to make a more universal driver.