PDA

View Full Version : Making Code Smaller for a Multiplexed LCD Display



rsocor01
- 15th August 2015, 00:44
Hi,

I have some code for a multiplexed LCD display that's taking a lot of memory space. The LCDDATA registers need to be updated frequently, so the display can work. There's got to be a clever way to do this using very little memory program space. I just can't figure it out yet. :confused: Can I use the SYMBOL command at the beginning of the program to define the PATTERN byte and save code memory space? Any hints, clues, or ideas are greatly appreciated.


'********** LOAD LCD REGISTERS **************

IF DIGIT = 0 THEN
LCDDATA0.7 = PATTERN.0 'DIGIT 0A = SEGMENT 7, COMMON 0
LCDDATA3.7 = PATTERN.1 'DIGIT 0B = SEGMENT 7, COMMON 1
LCDDATA6.7 = PATTERN.2 'DIGIT 0C = SEGMENT 7, COMMON 2
LCDDATA10.4 = PATTERN.3 'DIGIT 0D = SEGMENT 12, COMMON 3
LCDDATA7.4 = PATTERN.4 'DIGIT 0E = SEGMENT 12, COMMON 2
LCDDATA1.4 = PATTERN.5 'DIGIT 0F = SEGMENT 12, COMMON 0
LCDDATA4.4 = PATTERN.6 'DIGIT 0G = SEGMENT 12, COMMON 1
LCDDATA9.7 = PATTERN.7 'DIGIT 0P = SEGMENT 7, COMMON 3
ENDIF
IF DIGIT = 1 THEN
LCDDATA0.4 = PATTERN.0 'DIGIT 1A = SEGMENT 4, COMMON 0
LCDDATA3.4 = PATTERN.1 'DIGIT 1B = SEGMENT 4, COMMON 1
LCDDATA6.4 = PATTERN.2 'DIGIT 1C = SEGMENT 4, COMMON 2
LCDDATA10.7 = PATTERN.3 'DIGIT 1D = SEGMENT 15, COMMON 3
LCDDATA7.7 = PATTERN.4 'DIGIT 1E = SEGMENT 15, COMMON 2
LCDDATA1.7 = PATTERN.5 'DIGIT 1F = SEGMENT 15, COMMON 0
LCDDATA4.7 = PATTERN.6 'DIGIT 1G = SEGMENT 15, COMMON 1
LCDDATA9.4 = PATTERN.7 'DIGIT 1P = SEGMENT 4, COMMON 3
ENDIF
IF DIGIT = 2 THEN
LCDDATA0.1 = PATTERN.0 'DIGIT 2A = SEGMENT 1, COMMON 0
LCDDATA3.1 = PATTERN.1 'DIGIT 2B = SEGMENT 1, COMMON 1
LCDDATA6.1 = PATTERN.2 'DIGIT 2C = SEGMENT 1, COMMON 2
LCDDATA9.5 = PATTERN.3 'DIGIT 2D = SEGMENT 5, COMMON 3
LCDDATA6.5 = PATTERN.4 'DIGIT 2E = SEGMENT 5, COMMON 2
LCDDATA0.5 = PATTERN.5 'DIGIT 2F = SEGMENT 5, COMMON 0
LCDDATA3.5 = PATTERN.6 'DIGIT 2G = SEGMENT 5, COMMON 1
LCDDATA9.1 = PATTERN.7 'DIGIT 2P = SEGMENT 1, COMMON 3
ENDIF
IF DIGIT = 3 THEN
LCDDATA1.2 = PATTERN.0 'DIGIT 3A = SEGMENT 10, COMMON 0
LCDDATA4.2 = PATTERN.1 'DIGIT 3B = SEGMENT 10, COMMON 1
LCDDATA7.2 = PATTERN.2 'DIGIT 3C = SEGMENT 10, COMMON 2
LCDDATA9.2 = PATTERN.3 'DIGIT 3D = SEGMENT 2, COMMON 3
LCDDATA6.2 = PATTERN.4 'DIGIT 3E = SEGMENT 2, COMMON 2
LCDDATA0.2 = PATTERN.5 'DIGIT 3F = SEGMENT 2, COMMON 0
LCDDATA3.2 = PATTERN.6 'DIGIT 3G = SEGMENT 2, COMMON 1
LCDDATA10.2 = PATTERN.7 'DIGIT 3P = SEGMENT 10, COMMON 3
ENDIF
IF DIGIT = 4 THEN
LCDDATA2.1 = PATTERN.0 'DIGIT 4A = SEGMENT 17, COMMON 0
LCDDATA5.1 = PATTERN.1 'DIGIT 4B = SEGMENT 17, COMMON 1
LCDDATA8.1 = PATTERN.2 'DIGIT 4C = SEGMENT 17, COMMON 2
LCDDATA11.0 = PATTERN.3 'DIGIT 4D = SEGMENT 16, COMMON 3
LCDDATA8.0 = PATTERN.4 'DIGIT 4E = SEGMENT 16, COMMON 2
LCDDATA2.0 = PATTERN.5 'DIGIT 4F = SEGMENT 16, COMMON 0
LCDDATA5.0 = PATTERN.6 'DIGIT 4G = SEGMENT 16, COMMON 1
LCDDATA11.1 = PATTERN.7 'DIGIT 4P = SEGMENT 17, COMMON 3
ENDIF
IF DIGIT = 5 THEN
LCDDATA2.3 = PATTERN.0 'DIGIT 5A = SEGMENT 19, COMMON 0
LCDDATA5.3 = PATTERN.1 'DIGIT 5B = SEGMENT 19, COMMON 1
LCDDATA8.3 = PATTERN.2 'DIGIT 5C = SEGMENT 19, COMMON 2
LCDDATA11.2 = PATTERN.3 'DIGIT 5D = SEGMENT 18, COMMON 3
LCDDATA8.2 = PATTERN.4 'DIGIT 5E = SEGMENT 18, COMMON 2
LCDDATA2.2 = PATTERN.5 'DIGIT 5F = SEGMENT 18, COMMON 0
LCDDATA5.2 = PATTERN.6 'DIGIT 5G = SEGMENT 18, COMMON 1
LCDDATA11.3 = PATTERN.7 'DIGIT 5P = SEGMENT 19, COMMON 3
ENDIF
IF DIGIT = 6 THEN
LCDDATA2.5 = PATTERN.0 'DIGIT 6A = SEGMENT 21, COMMON 0
LCDDATA5.5 = PATTERN.1 'DIGIT 6B = SEGMENT 21, COMMON 1
LCDDATA8.5 = PATTERN.2 'DIGIT 6C = SEGMENT 21, COMMON 2
LCDDATA11.4 = PATTERN.3 'DIGIT 6D = SEGMENT 20, COMMON 3
LCDDATA8.4 = PATTERN.4 'DIGIT 6E = SEGMENT 20, COMMON 2
LCDDATA2.4 = PATTERN.5 'DIGIT 6F = SEGMENT 20, COMMON 0
LCDDATA5.4 = PATTERN.6 'DIGIT 6G = SEGMENT 20, COMMON 1
LCDDATA11.5 = PATTERN.7 'DIGIT 6P = SEGMENT 21, COMMON 3
ENDIF
IF DIGIT = 7 THEN
LCDDATA2.7 = PATTERN.0 'DIGIT 7A = SEGMENT 23, COMMON 0
LCDDATA5.7 = PATTERN.1 'DIGIT 7B = SEGMENT 23, COMMON 1
LCDDATA8.7 = PATTERN.2 'DIGIT 7C = SEGMENT 23, COMMON 2
LCDDATA11.6 = PATTERN.3 'DIGIT 7D = SEGMENT 22, COMMON 3
LCDDATA8.6 = PATTERN.4 'DIGIT 7E = SEGMENT 22, COMMON 2
LCDDATA2.6 = PATTERN.5 'DIGIT 7F = SEGMENT 22, COMMON 0
LCDDATA5.6 = PATTERN.6 'DIGIT 7G = SEGMENT 22, COMMON 1
LCDDATA11.7 = PATTERN.7 'DIGIT 7P = SEGMENT 23, COMMON 3
ENDIF

Dave
- 15th August 2015, 15:31
Is this display a 7 segment?

rsocor01
- 15th August 2015, 15:37
Is this display a 7 segment? Yes, it is.

Dave
- 15th August 2015, 16:08
rsocor01, This may be a starting point:

Jerson
- 15th August 2015, 17:40
Actually, I have run into a similar LCD design very recently and have to eventually work on it. What he has is a segmented LCD glass with a controller. The various segments are scattered around the face of the lcd and not similar to a 7 segment LEDs grouping. Look carefully and you will find bits of each pattern are scattered around the lcddata bytes. To my mind, what rsocor01 has got now seems suitable if not ideal.

rsocor01
- 15th August 2015, 21:59
Dave,

This LCD is actually a 7-segments, 4 commons, multiplexed display. That code is more for an LED display type.

Jerson,

Thanks for your comment. So, you know that this displays are a pain in the neck to work with :eek:. The code that I posted works perfectly fine, and it can serve as a reference for somebody working with these displays in the future. However, it takes a lot of code space. I was hoping PBP could do something like



DIGIT_0.0 VAR LCDDATA0.7
DIGIT_0.1 VAR LCDDATA3.7
DIGIT_0.2 VAR LCDDATA6.7
......... And so on



But, I don't think that it can do it. Any ideas?

Jerson
- 16th August 2015, 06:15
Even if it could, the underlying code will still have to do the same hard work of juggling bits around. So, eventually, there may only be syntactic sugar, but the bitterness will remain(code size).

rsocor01
- 16th August 2015, 18:22
Even if it could, the underlying code will still have to do the same hard work of juggling bits around. Yeap, you are right. I was hoping that somebody knew of a clever way of doing this.

mark_s
- 16th August 2015, 18:51
Hello

Which pic are you using? There are some newer chips like the 16f1939 with 1k ram and 16K of program space. There are 18f with double.

rsocor01
- 17th August 2015, 07:45
Hello

Which pic are you using? There are some newer chips like the 16f1939 with 1k ram and 16K of program space. There are 18f with double.

Actually, I'm using the 16F1939. I'm going to check for the 18F that you mentioned.

Art
- 19th August 2015, 15:27
I think it’s tough, but a curiosity now,


LCDDATA11.1 = PATTERN.7

How did you define these?
Is PATTERN a single byte you are looking at bits 0-7,
and LCDDATA, there are 11 bytes, and you look at bits 0-7 of all 11 bytes?

I’ve not used that syntax before, but PATTERN.bit7 (to address a bit), or PATTERN[7] (to address a byte).

rsocor01
- 19th August 2015, 20:53
Art, in this example there is a multiplexed 7-segment LCD, 4 commons, display that I am running directly from the PIC. The advantage of the 4 commons is that you only need one pin in the PIC for every 4 segments of the display, so you minimize the number of needed pins.

The byte PATTERN changes its value for everyone of the 8 digits of the display. After enabling the LCD feature in the PIC, you need to load LCDDATA the registers for it to work.