PDA

View Full Version : Replacing array member on the fly (big LCD characters idea)



CuriousOne
- 30th October 2020, 17:21
Hello.
I've created a large "font" from custom definable LCD characters, which look quite good. But to use with them with real software, I need a code which will translate some variable into these digit display. So to accomplish this, I've created two arrays, one for top row and one for bottom, which hold appropriate number of corresponding custom chars for the digit display. So to display the required char, I simply read values from arrays from index at that position and pass it to display. The code is as follows:



DTOP VAR BYTE[10] 'array for top line
DBOT VAR BYTE[10] 'array for bottom line
DTOP[0]=21 '0
DBOT[0]=37
DTOP[1]=96 '1 9 REPLACES 16
DBOT[1]=96
DTOP[2]=05 '2
DBOT[2]=24
DTOP[3]=05 '3
DBOT[3]=47
DTOP[4]=37 '4
DBOT[4]=96
DTOP[5]=20 '5
DBOT[5]=45
DTOP[6]=20 '6
DBOT[6]=35
DTOP[7]=81 '7
DBOT[7]=96
DTOP[8]=25 '8
DBOT[8]=25
DTOP[9]=25 '9
DBOT[9]=96


QROMA:
FOR CNT=0 TO 9
LCDOUT $FE,$01,DTOP[CNT] DIG 1, DTOP[CNT] DIG 0
LCDOUT $FE,$C0,DBOT[CNT] DIG 1, DBOT[CNT] DIG 0
PAUSE 1000
NEXT
GOTO QROMA


But I run into problem, since I'm using "space" for some characters shape, namely 4, 7 and 9 and DEC code for space is 16, I can't put it into that arrays. In fact I can put it, but when I read array like I do in example code, with DIG statement, it will get ,messed, because say I need to display space at left and 6th custom char at right. If I put 166 into array (16 for space and 6 for that custom char), when I read it, the DIG 1 will return 6, not 16.

So what can I do? One way I see is to use individual array elements, and omit usage of DIG, but this doubles array size.

Any other ideas?
8960

Ioannis
- 2nd November 2020, 19:51
Have you seen this: http://www.picbasic.co.uk/forum/showthread.php?t=4795&p=26736#post26736

And this: http://www.picbasic.co.uk/forum/showthread.php?t=17707&p=118687#post118687

Ioannis

CuriousOne
- 3rd November 2020, 05:03
Yes and I have done way better font for 2004 LCD, but here we're talking about 1602 parallel LCD, not serial, as in 1st link.

CuriousOne
- 3rd November 2020, 05:42
Here is my font for 20x4 LCD displays. Far better than posted in the link above.
8962

Ioannis
- 3rd November 2020, 08:40
Really nice job on the big numbers.

What is the difference between parallel - serial LCD? Other than electrical connections and some specific commands? Have not used serial so far but I guess behind the serial driver everything else is the same.

Ioannis

CuriousOne
- 3rd November 2020, 18:29
Thanks. I have experience of making pseudographics (so called ASCII art) since early 80s. That set of characters also can be used to display most latin alphabet letters, except some. Regarding the LCD, I have no idea, but above example uses serial LCD and I don't see any PBP manual entries for serial LCD.

Jerson
- 4th November 2020, 03:11
I counted 8 custom characters and a full block(possibly from the existing character set). Is that correct?

Enumerating,

Full rounded top left corner,
Full rounded top right corner
Full rounded bot left corner
Full rounded bot right corner
bottom line
top line
half rounded top left corner
half rounded top right corner
and
the full block

CuriousOne
- 4th November 2020, 06:31
Yes, there are 8 custom characters and char #255 - Full block is used.

CuriousOne
- 8th November 2020, 19:04
Here's 2x2 font for 1602 OLED (Here you can write bytes directly, not limited by 8 custom chars).

8964

CuriousOne
- 13th November 2020, 19:23
Wanted to store above font in EEPROM. each character takes 2x13 bytes. so 260 byte of memory are needed, but most chips have only 256 bytes of eeprom available.
I come up with run length encoding compression idea. Since there are only 5 bits used, can use remaining 3 as a counter, showing how many times current pattern should be repeated. This gives ability to repeat up to 8 positions

Say for character 4 (top left part), in "normal" mode, bit pattern looks like this: %11000. But if we add %110 to end of it, so it now looks like %11000110, decoder software will know that it have to repeat that pattern 6 times.

So code for reading and decoding char to appropriate DDRAM or whatever it is called, should work like this:

1. Set pointer address from which the bitmap should be read.
2. Read it, if 3 last bits<>0 then separate it, and do the loop, writing the code of first 5 bits, repeating them times specified in these 3 bits.
3. Continue reading of bitmap as needed.

But I have issue with statement for dividing bit variable into two. Say I have %10101010. How should I divide it into two variables, one which has 5 bits from left, and another having 3 bits from right?

CuriousOne
- 13th November 2020, 19:38
Just did a rough estimation - the above idea should save 30-40% of EEPROM space. Not bad.

CuriousOne
- 13th November 2020, 21:16
Also it is possible to separate and replace some similar blocks with additional indexes - this should save additional 10-20%...

Ioannis
- 13th November 2020, 21:22
But I have issue with statement for dividing bit variable into two. Say I have %10101010. How should I divide it into two variables, one which has 5 bits from left, and another having 3 bits from right?

Something like this?



byte_var var byte
a_left var byte
b_left var byte

byte_var=%10101010
a_left=byte_var & %11111000
b_left=byte_var & %00000111



Ioannis

CuriousOne
- 13th November 2020, 21:41
Yes, but I was thinking about either <<, >> or DIG() operators...

Ioannis
- 14th November 2020, 11:41
then combine accordingly like that:



a_left=(byte_var & %11111000)>>3


to make it right justified if needed.

Ioannis

CuriousOne
- 19th November 2020, 17:45
Found interesting thing. On power up, custom character area in normal LCD are empty, but on WS0010 OLED displays, they are filled with random numbers on power up.

Ioannis
- 19th November 2020, 19:56
On the custom character, unless explicitly stated, you should consider it full of rubbish.

Ioannis

CuriousOne
- 20th November 2020, 06:50
Yes, but on LCD it is usually empty. On OLED - it is filled with different garbage on each power up.
Anyways, problem solved, also did some nice animation, will post code and video later.

CuriousOne
- 20th November 2020, 19:41
https://www.youtube.com/watch?v=jp5oeGZj1ho

Ioannis
- 20th November 2020, 20:53
Nice and clear fonts. Good work!

Ioannis

CuriousOne
- 21st November 2020, 07:28
Actually, it works on any 1602 LCD too, just animation is not so smooth. Will post code a bit later.

CuriousOne
- 21st November 2020, 09:09
'font data, left side start, going down, then right side going down
data %00000,%00000,%00000,%00000,%00000,%00000,%00000,% 00000,%00000 '0 1
data %00110,%01110,%11110,%11110,%00110,%00110,%00110,% 00110 '1 9
data %00110,%00110,%00110,%11111,%11111,%00000,%00000,% 00000 '2 17
data %01111,%11111,%11000,%00000,%00000,%00000,%01111,% 11111 '3 25
data %11000,%11000,%11000,%11111,%11111,%00000,%00000,% 00000 '4 33
data %11110,%11111,%00011,%00011,%00011,%00011,%11111,% 11110 '5 41
data %00000,%00000,%00000,%11111,%11111,%00000,%00000,% 00000 '6 49
data %01111,%11111,%11000,%00000,%00000,%00000,%00000,% 00000 '7 58
data %00000,%00000,%11000,%11111,%01111,%00000,%00000,% 00000 '8 66
data %00011,%00011,%00011,%11111,%11110,%00000,%00000,% 00000 '9 74
data %11000,%11000,%11000,%11000,%11000,%11000,%11111,% 01111 '10 82
data %00011,%00011,%00011,%00011,%00011,%00011,%11111,% 11111 '11 90
data %00011,%00011,%00011,%00011,%00011,%00000,%00000,% 00000 '12 98
data %11111,%11111,%11000,%11000,%11000,%11000,%11111,% 11111 '13 106
data %11111,%11111,%00000,%00000,%00000,%00000,%11110,% 11111 '14 114
data %01111,%11111,%11000,%11000,%11000,%11000,%11111,% 11111 '15 122
data %11000,%11000,%11000,%11111,%01111,%00000,%00000,% 00000 '16 130
data %11110,%11111,%00011,%00000,%00000,%00000,%11110,% 11111 '17 138
data %11111,%11111,%11000,%00000,%00000,%00000,%00000,% 00000 '18 146
data %11111,%11111,%00011,%00011,%00111,%01110,%11100,% 11000 '19 154
data %11000,%11000,%11000,%11000,%11000,%00000,%00000,% 00000 '20 162
data %01111,%11111,%11000,%11000,%11000,%11000,%11111,% 01111 '21 170
data %11110,%11111,%00011,%00011,%00011,%00011,%11111,% 11111 '22 178
data %01111,%11111,%11000,%11000,%11000,%11000,%11000,% 11000 '23 186
data %11110,%11111,%00011,%00011,%00011,%00011,%00011,% 00011 '24 194

x var word ' counter variable
D VAR WORD 'VARIABLE TO BE DECODED
y var byte 'eeprom reader var
LFT VAR BYTE
LB VAR BYTE
RT VAR BYTE
RB VAR BYTE 'LEFT TOP, LEFT BOTTOM, RIGHT TOP, RIGHT BOTTOM variables
T1 VAR BYTE
T2 VAR BYTE
T3 VAR BYTE
T4 VAR BYTE 'TEMP VARIABLES FOR DATA READ


CLEANER: 'CLEAR ALL CHARS
FOR X=0 TO 7
LCDOUT $FE,64+X,0
LCDOUT $FE,72+X,0
LCDOUT $FE,80+X,0
LCDOUT $FE,88+X,0
NEXT




MAINER:
lcdout $fe,$80,0,2,0,2,".",0,2,0,2,".",0,2,0,2
lcdout $fe,$c0,1,3,1,3," ",1,3,1,3," ",1,3,1,3
'd=0
for d=0 to 9
GOSUB DECODER
GOSUB EREADER


PAUSE 1000


FOR X=0 TO 7 'Clean screen between chars
LCDOUT $FE,64+X,0
LCDOUT $FE,72+X,0
LCDOUT $FE,80+X,0
LCDOUT $FE,88+X,0
NEXT
next
GOTO MAINER




DECODER 'DECODE THE VARIABLE
IF D=0 THEN LFT=185:LB=129:RT=193:RB=73 '0
IF D=1 THEN LFT=1:LB=1:RT=9:RB=17 '1
IF D=2 THEN LFT=25:LB=33:RT=41:RB=49 '2
IF D=3 THEN LFT=57:LB=65:RT=41:RB=73 '3
IF D=4 THEN LFT=81:LB=1:RT=89:RB=97 '4
IF D=5 THEN LFT=105:LB=65:RT=113:RB=73 '5
IF D=6 THEN LFT=121:LB=129:RT=137:RB=73 '6
IF D=7 THEN LFT=145:LB=1:RT=153:RB=161 '7
IF D=8 THEN LFT=169:LB=129:RT=41:RB=73 '8
IF D=9 THEN LFT=169:LB=65:RT=177:RB=73 '9
RETURN






EREADER: 'read eeprom data into screen user area with reversal of direction for lower line, for cooler look
for x=0 to 7
READ LFT+7-X,T1
READ LB+X,T2
READ RT+X,T3
READ RB+7-X,T4
LCDOUT $FE,64+7-X,T1
LCDOUT $FE,72+X,T2
LCDOUT $FE,80+X,T3
LCDOUT $FE,88+7-X,T4
pause 25
NEXT
RETURN


Pin configs, defines and other, personalized settings not included in the above code.

richard
- 21st November 2020, 12:03
But can it show the time or date or anything else but the one digit ?

if you really want big chr's on that size display get a 122x32 graphical job

CuriousOne
- 21st November 2020, 13:32
Yes, why not?
Here I was having fun with animation process - direct reading from EEPROM is a new thing for me. I already have clock code written to use these 2x2 chars, will post it after I'll tidy it up.

Graphical screens might be good but 1602 OLED have 2 advantages:

1. We know the interface.
2. They're cheap for their size (comparable physical size Graphical OLED is more expensive)

CuriousOne
- 21st November 2020, 13:34
And almost forgot - 1602 OLEDs also support mixed mode - having both character and graphic mode together. So you can save on memory when displaying the text and digits, and use graphics only where needed - and you're not limited by 8 custom characters in that case.

richard
- 21st November 2020, 22:36
Yes, why not?
the font you depict has 22 "shapes" that i can see, the display can hold only eight user defined [cga ram] shapes at any one time

try to show this

8966

CuriousOne
- 22nd November 2020, 05:39
This is 1602 OLED, using WS0010 controller, and besides the standard mode, it also has Graphical mode. So you can write whatever you want. Or you can use a trick - Draw something with these 8 custom chars. Switch display to graphic mode - all image on screen remains, but it is turned into graphics. Now turn back to standard mode, update custom charset and draw next symbol at next place (the symbol you've drawn previously is kept on display, because it turned into graphics) and so on.

Ioannis
- 22nd November 2020, 12:14
And there is Nextion displays, in many sizes, low cost, with touch and colors to do anything like that with almost zero overhead in programming.

But in either case, nice study case.

Ioannis

mpgmike
- 22nd November 2020, 17:59
I am using the Nextion displays more and more. Not only can they display anything you like, they're easy to program, use a simple UART communication protocol (with user defined Baud rate), and because they're touch screen, they eliminate the need for buttons, knobs, and switches. You can load practically any font you want into your project, along with graphics for fancy buttons etc.

(Nuts & Volts Magazine currently has Part 4 of a 7 part article series on using the Nextion... and yes, I wrote it.)

CuriousOne
- 22nd November 2020, 18:55
Unfortunately, nextion displays are junk in several aspects:

1. Low display brightness, bad viewing angles, zero daylight visibility, bad contrast. Can't be compared to OLED in this field. And who needs "ease of programming" (which is very questionable), if you can't see the result?
2. Their IDE is written with left rear feet and has appropriate usability.
3. Price? Above mentioned 1602 OLED module costs $9. I'd love to have Nextion for that price.

All above is based on personal experience with nextion displays, not other's ideas or impressions.

Ioannis
- 23rd November 2020, 07:04
OK, depends on what you want to do. If you want to place the LCD opposite of the sun, yes, nextion will not fit in.

In anyway, most of the user interface is well covered with these displays. As for the price, well, you can't have touch for free, right?

And the IDE is not that bad. You need to take your time, see some tutorials (there are many on-line), ask Mike if needed, he is here and very helpful and off you go.

At the end of the day, you will offer your client a more attractive device than the classic 2x16 display.

Ioannis

CuriousOne
- 24th November 2020, 05:48
It is 21st century, and Nextion using cheapest TN+Film panels, but asking premium prices is just a funny thing :D They can do at least IPS, for better angles and contrast. For the touch screen, a simple glass add-on touch screen (which is used in Nextion), sized for 1602 display, costs about 30 cents in china. So you can upgrade even 1602 LCD with touch screen (I don't see any practical purpose in that, but this is possible) And by the way, topic is not about Nextion :)

richard
- 24th November 2020, 07:56
3. Price? Above mentioned 1602 OLED module costs $9

might i ask where from , i cannot find anyone in Australia that stocks them , most tell me they are end of product life
or only have units with different chipset
ebay has no hits
crystalfontz says end of life [extortionate shipping cost]
google zip nil nothing other than the winstar site

i would get one to play with but it looks to be not worthwhile

CuriousOne
- 25th November 2020, 07:05
https://item.taobao.com/item.htm?spm=a1z09.2.0.0.3fd92e8dTB6Lqm&id=567609161459&_u=p2otmf3i3dd2

Yellow one from video above was bought exactly from that link.

richard
- 26th November 2020, 03:23
thanks for the effort, but i cannot get that site to work ,seems you need to sign up and login to get the buttons to work
its not for me.

CuriousOne
- 30th November 2020, 05:38
https://youtu.be/wGzZn8CFBqg

Will be doing mechanical counter animation next :)

CuriousOne
- 1st December 2020, 07:22
With timings adjusted, it looks quite good even on normal 1602 LCD.

https://youtu.be/jRG7m_4VE4U

Ioannis
- 1st December 2020, 09:54
Indeed, it looks very nice! Nice work.

Ioannis