PDA

View Full Version : LS020 - Sharp TFT display driver



_Gabi_
30th May 2010, 17:20
by Gabi M. (http://www.migadex.com/)

Part - 1

INTRODUCTION

Usually, writing a driver involve thorough reading and understanding of the device respectively. Probably, we will do it together, as a set of articles in the near future.

I will omit the description of programming for the TFT LS020, as there are sites that have dedicated a special importance to this type of graphic display, and I would like to mention the page of Christian Krantz (http://www.superkranz.de/christian/S65_Display/DisplayProgramming.html) .

HARDWARE

We have used for our tests an LS020 mounted display on a Amicus18 shield type of board, on which we had to make some small modifications to the connecting pins between the two boards. To begin with, I drew (by hand because of lack of time :) ) the schematic pin connections of each plate, as you would see it in a vertical overlap (http://www.amicus18.ro/themes/myAmicus/images_custom//s65_014.jpg).

SOFTWARE

We would like to write a code to confirm that our tandem Amicus18 and LS020 are connected to each other and the display receives commands from the Amicus18 board, and it understands and execute them, and we will observe a sequence of color on the display, for the entire screen. The main loop will be something like:


;================================================= =============================
MAIN_USER: ;
DelayMS 100 ; some delay
Clear ; initialize some variables
glcdClear Black ; paint the display with selected color
DelayMS 1000 ; some delay
;
DEMO_word_A = RGB($0A,$12,$01) ; define the color we will start with
;
While 1 = 1 ; loop
DEMO_word_B = 23231 ; the total mount of pixels on the screen
; equals 132 x 176 = 22232 pixels
drawStart ; start sending data to Glcd
Repeat
writeData DEMO_word_A ; write the selected color to each pixel
Dec DEMO_word_B ; next pixel
Until DEMO_word_B = 0 ;
drawStop ; all written so update the display
DEMO_word_A = DEMO_word_A + 100 ; increase the color value
DelayMS 50 ; some delay
Wend ; and back to loop start
;================================================= =============================

The final output on the display can be quickly viewed on this short clip S65 - Part 1 (http://www.youtube.com/watch?v=S8uUgcU20Tc).

You can find attached the code for this test and , for further details you can check with my Amicus18 Friendly Site (http://www.amicus18.ro/site/index.php?page=news&type=view&id=glcd_drivers%2Fs65_driver_-_part_1).

les
1st June 2010, 21:52
Hello Gabi

Welcome to the Amicus forum.

I've read you're first installment article with interrest, and look forward to the others. However, I have noticed some inconsistencies in the BASIC code attached:

1) You're actually turning off optimisation. Why? The 18F optimiser is absolutely safe to use up to level 2, then level 3 should be used and tested, just in case it optimises away some asm. This is usually caused when the overlying BASIC code is rather inconsistent.

Not only does the optimiser pass make better underlying ASM code, but you'll find that a lot of the Amicus18 compiler's functionality relies on the optimiser being switch on, and some future libraries simply will not function without it. In fact, I'm considering removing the option of disabling it.

2) You're altering the fuses with Config_Start and Config_End, however, the bootloader will disregard these, or are you programming using a PICkit2 or 3?

3) There is no need to issue the All_Digital declare, as the startup code generated by the Amicus18 compiler does this for you by default. If it wasn't for the plethora of PICmicro devices, each having differing requirements, I would do this for Proton as well.


It's good to see that you've grasped the use of the preprocessor. Take a look at the 23K256 and KS0713 libraries on the WIKI for some more ideas. Using the techniques in those libraries is the subject of a future series of articles.

_Gabi_
2nd June 2010, 07:34
Hello Les,

Well, I do all my code needs in Proton+ which is quick, fast and gets wonderful if one know how to drive it, and in return for that I have thought to contribute, now and then, here at the Amicus forum , when I get some spare time.

1.) Yes, right! I turn it off as I really have no time to change all those macros;

2 & 3 .) Thanks, oh yes I am using the Amicus18 board now, my bad. The initial code was written like after you have implemented the use of the preprocessor in Proton, and I was using some other chip and board and flashing with the pickit2, so anyone using the code attached above please feel free to remove/comment those lines.


I will definitely absorb all the techniques in those libraries, and thank you for sharing it with us.

Citius
2nd June 2010, 12:16
Gabi -

Thanks and nice work. Your you tube videos are great and fun to watch as well...

Carl

_Gabi_
3rd June 2010, 08:05
Unfortunately,

I will have to stop here with this article, as I was using macro's in my code (which is an unsupported feature as I know and looks inconsistent) and with the new 1.0.0.9 disabling the optimizer its not possible anymore.

Things like the code below will not provide the results I expect, so it have to be re-written ( :confused: and I do not have the time for that).


Dim WORD_AAA As Word
Dim WORD_BBB As Word
Dim WORD_CCC As Word
;
Bra after
test Macro P1
#if (Prm_1 == Word)
WORD_BYTE P1, WORD_AAA
#endif
GoSub TEST_SUB
Endm
TEST_SUB:
WORD_BBB = WORD_AAA
Return
after:
;
MAIN:
WORD_CCC = $ABCD
WORD_BBB = 0
test WORD_CCC
DelayMS 100
StopYou can still check on my ref site for the completion of this article but the code will only work with v.1.0.0.8 or Proton.

Till then . . .

_Gabi_
3rd June 2010, 09:27
;
Dim BYTE_AAA As Byte
Dim WORD_BBB As Word
Dim WORD_CCC As Word
;
Bra after
test Macro P1
#if (Prm_1 == Word)
WORD_BYTE P1, BYTE_AAA
#endif
GoSub TEST_SUB
Endm
TEST_SUB:
WORD_BBB = BYTE_AAA
Return
after:
;
MAIN:
WORD_CCC = $ABCD
WORD_BBB = 0
test WORD_CCC
DelayMS 100
Stop
;

les
3rd June 2010, 10:31
The anomaly you've seen is not down to the optimiser, it's down to some typos on my part within the "opt_ld16.inc" file.

The text:
;-------------------------------------------------------------------------------------------------
word_byte macro pWordIn,pByteOut
NOLIST
movff pWordIn,pByteOut
LIST
endm

Should be:
;-------------------------------------------------------------------------------------------------
word_byte macro pWordIn,pByteOut
LIST
movff pWordIn,pByteOut
endm

The assembler NOLIST directive was stopping production of mnemonics within the LST file, hence in the final output.

This happens in several places where I changed a previous Byte_Byte macro with the movff mnemonic.

The file can be found within the compiler's "Sources" folder. Default "Program Files\AmicusIDE\Includes\Sources"

Download these two files and replace the existing files in the above directory:

cof_ld16.inc (http://www.compile-it.com/pdsbeta/PDS/Updated%20inc%20files/cof_ld16.inc)
opt_ld16.inc (http://www.compile-it.com/pdsbeta/PDS/Updated%20inc%20files/opt_ld16.inc)

The best way to do this is to right click on the above links individually and "Save Link As" to the above folder.

Needless to say, a new version of the compiler will be forthcoming.

The same anomaly will also be found within the latest Proton compiler, so an update is imminent for that as well.

Sorry for the hastle the anomaly caused Gabi, but without your comment on this forum, it may have gone unnoticed for a lot longer. Best to nip an anomaly in the bud as soon as possible.

And please continue with your series of articles, as they will be a benefit to many, many people. If you have any queries concerning the code, please drop me an email (you should already have my email address from Tim), and I'll be glad to assist.

_Gabi_
3rd June 2010, 12:01
That was fast :), thank you !

all up and running with the Optimizer = ON

now I have to continue with part 2 of it, and will be available shortly.

Les, I guess I have misplaced your email address, will help if it can be PM'd or such.

_Gabi_
8th June 2010, 14:16
by Gabi M. (http://www.migadex.com/)

Part - 2

INTRODUCTION

Having seen first hand that the display receives commands from Amicus18 Board, now is the time to try some commands or functions such as printing characters, graphics functions, and some of the LS020 dedicated features.

Result expected After compilation and programming the Amicus18 board (as further explained in this article) will get the results that can be seen in the following clip: S65 LS020 driver - Amicus18 - Part 2
(http://www.youtube.com/watch?v=uv3Zq6_21uQ&feature=related)

Positioning data on the display (display mapping)



Screen dimensions for this type of display are 172 x 136 pixels. Being a rectangular display type can be used both in "landscape" format and "portrait".

Also, each type of format mentioned above can also be used in "mirror", resulting in four modes of positioning coordinates of reference.

To set this in code we use two variables, namely the "Mirror" and "Rotate" , and the combination are as follows:



;+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++
; T F T M A P P I N G - O P T I O N S S E C T I O N S
;+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++

; Screen positioning modes

(*
0 ----------------- > X HORIZONTAL MODE
|
| +------------+-+
| | | | MIRROR = 0
| | | | ROTATE = 0
| | | | X = 176
| +------------+-+ Y = 132
Y

^ Y HORIZONTAL MODE
+------------+-+ |
| | | | MIRROR = 1
| | | | ROTATE = 0
| | | | X = 176
+------------+-+ | Y = 132
|
X ---------------- 0 VERTICAL MODE
|
+------------+-+ |
| | | | MIRROR = 0
| | | | ROTATE = 1
| | | | X = 132
+------------+-+ | Y = 176
X


X VERTICAL MODE
^
| +------------+-+
| | | | MIRROR = 1
| | | | ROTATE = 1
| | | | X = 132
| +------------+-+ Y = 176
|
0------------------> Y

*)
;+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++OPTIONS GLCD (glcd_FlagsBits)

There is the possibility to select certain functions by setting some bits of a variable. We have declared in the code a variable called glcd_FlagsBits that contains the next bit sequence:
- Bit.0 AutoLineFeed (text printing routines will execute a so-called "wrap arround" on the window defined by glcd_Window)
- Bit.1 FixedFont (be = 0 for proportional fonts and will be = 1 for fixed width fonts)
- Bit.2 Clipping (activation function respectively restricting display outside the window defined by glcd_Clip_x1, glcd_Clip_x2, glcd_Cli p_y1, glcd_Clip_y2)


As usual, for further details you can check with my Amicus18 Friendly Site (http://www.amicus18.ro/site/index.php?page=news&type=view&id=glcd_drivers%2Fs65_driver_-_part_1).

Will be continued in the next post due to text length restriction.

_Gabi_
8th June 2010, 14:56
by Gabi M. (http://www.migadex.com/)

Part - 2.A

COLORS (Define)

LS020 accept encoding 8-bit RGB color format, 16 bit and even 24 bits. The submitted code will be referred only to 16-bit RGB format. The8-bit RGB format is RGB 3 - 3 - 2 and can form mix shades of colors: 3 bits of red, 3 bits green and two blue bits. The 16-bit RGB format allow the use of up to 65,000 colors in combination of RGB 5 - 6 - 5 respectively 5 bits red, 6 green bits and 5 bits blue.


;================================================= =============================
; Definition of the coded RGB 5-6-5 and some of the most used colors
; Note:
; For 8 Bit colors R,G,B 3,3,2 bits
; For 16 Bit colors R,G,B 5,6,5 bits
;================================================= =============================
; define the RGB coding for 5 red | 6 green | 5 blue
$define RGB(r,g,b) ((( r & $F8)<<8)|(( g & $FC)<<3)|(( b & $F8)>>3 ))
; and now some colors
$define NONE RGB($00, $40, $00) ; use this as transparent color
$define BLACK RGB($00, $00, $00)
$define WHITE RGB($FF, $FF, $FF)
$define RED RGB($FF, $00, $00)
$define GREEN RGB($00, $FF, $00)
$define BLUE RGB($01, $00, $FF)
$define YELLOW RGB($FF, $FF, $00)
$define MAGENTA RGB($FF, $00, $FF)
$define CYAN RGB($00, $FF, $FF)
$define GRAY RGB($80, $80, $40)
$define SILVER RGB($A0, $A0, $80)
$define GOLD RGB($A0, $A0, $40)
$define ORANGE RGB($FF, $6D, $00)
$define VIOLET RGB($85, $00, $DF)
;================================================= =============================A remarkable thing to RBG 16 bit is that we can quickly define specific colors by using a "Color Picker" in many such applications. Thus, if we want to define the hex color coded with # 3BCF0C all you have to do is:


$define MY_COLOR RGB($3B,$CF,$0C) ; #3BCF0Cand after that the user defined color MY_COLOR can be used in the code. There are many websites referring to encode hex color. Here are just a few (without any selective criteria):

The Other RGB Color Chart (http://translate.googleusercontent.com/translate_c?hl=ro&ie=UTF-8&sl=ro&tl=en&u=http://www.tayloredmktg.com/rgb/&prev=_t&rurl=translate.google.ro&usg=ALkJrhi4jmQmXyJTnydvG-XEGtQCryYxaw)

Wiki - List of Colors (http://translate.googleusercontent.com/translate_c?hl=ro&ie=UTF-8&sl=ro&tl=en&u=http://en.wikipedia.org/wiki/List_of_colors&prev=_t&rurl=translate.google.ro&usg=ALkJrhhNJtGu_AMhrs8KbUH0k2XmDNCT9g)

Name That Color (http://translate.googleusercontent.com/translate_c?hl=ro&ie=UTF-8&sl=ro&tl=en&u=http://chir.ag/projects/name-that-color/&prev=_t&rurl=translate.google.ro&usg=ALkJrhh5yaR2ANJ3WeoN2bO05LCUkATWAA)

As usual, for further details you can check with my Amicus18 Friendly Site (http://www.amicus18.ro/site/index.php?page=news&type=view&id=glcd_drivers%2Fs65_driver_-_part_2_2&redirected=1).

Will be continued in the next post due to text length restriction.

_Gabi_
8th June 2010, 15:03
by Gabi M. (http://www.migadex.com/)

Part - 2.B

GLCD Functions (Macros)

Next, will try to explain each function (macro) of the Code.



glcdWriteCmd
has as parameters and __param __reg bytes, and parameter target register;


glcdWriteData
parameter is a variable of type word and is used for sending information type "DATA" to display;



glcdSetArea
has four parameters, namely pairs x0 x1 y0 and y1, which are positions defining the corners (diagonally) to the area in which data will be displayed. Also, the cursor will position the coordinates of x0, y0;



glcdSetCursor
has the parameters x and y coordinates, which will position the cursor;



glcdDrawStart
placing the display in a reception mode for the data stream (representing color values, using 16 bits per pixel);



glcdDrawCmd
to transmit a variable of type word, representing the 16-bit color of the respective pixel;



glcdDrawStop
the display will exit from the continuous receive data stream;



glcdClear
accept a word variable type parameter representing the pixel color that will be filling the screen, the effect is similar to "erase" the screen;



glcdDrawPixel
the parameters are the coordinates x (byte) and y (byte) of the cursor and the color (Word) of the pixels to be written on the screen;



glcdPutPixel
is the color parameter (word) for the printed pixel. The Cursor position is not set with this function;



glcdSelectFont
parameter is a variable that represents the font name (LABEL type variable) to be used further;



glcdNewLine

no parameter.It is executing a <LF> <CR> inside the window defined by glcdWindow;




glcdDrawChar
parameter is the character to be printed, as defined within the previously selected font file;



glcdFillRectangle
has as parameters the coordinates x0, y0 and x1, y1 rectangle of the display, and color that will be 'filling' it (16-bit format);



glcdDrawRectangle
has as parameters the coordinates x0, y0 and x1, y1 rectangle of the display, and plotting its color (16 bit format);



glcdDrawLine
has as parameters the coordinates x0, y0 and x1, y1 line display, and plotting its color (16 bit format);



glcdDrawCircle
has as parameters the coordinates x0, y0 of the circle to display, the radius of the circle (in pixels) and its plotting color (16 bit format);



glcdFillCircle
has as parameters the coordinates x0, y0 of the circle to display, the radius of the circle (in pixels) and the color that will be 'filling' it (16-bit format);



glcdPrint
parameter is the string that contains the data to be displayed;



glcd65K
informs the display that will use RGB 5-6-5 format, that is 16-bit of color information per pixel;



glcd8
informs the display that will use 332 RGB format, that is 8-bit of color information per pixel;
the s
creen will display in negative mode the image that was on display before using this feature;



glcdPozitive

the
screen will display a positive image after it was turned glcdNegative;



glcdPowerOff
display should execute this command before powering off. It is recommended to use it so to keep a longer display operation duration;



glcdSleepBlack
execute display "Sleep" function, sending "Black" color for all pixels on the screen. During this period you can send commands and data to display;



glcdSleepWhite
execute display "Sleep" function, sending "White" color for all pixels on the screen. During this period you can send commands and data to display;



glcdDisplayOn
display out of sleep function induced state above and returns to normal display;




Following In Part 3


In the next article the following will be tackled:

- Function "Scroll";
- Producing/editing fonts;
- Conclusions



And finally, please see attached the related code for the Part 2 of the LS020 - Sharp TFT display driver. Please enjoy and improve it if possible for the benefit of all of us.




As these articles are automatically translated into English I would like to thank Paul for the support.

As usual , for further details you can check with my Amicus18 Friendly Site (http://www.amicus18.ro/site/index.php?page=news&type=view&id=glcd_drivers%2Fs65_driver_-_part_2_2&redirected=1).

Citius
17th August 2010, 13:12
Gabi -

This really is a first rate project. Very nicely done, useful & inspiring to others...

Thank you!

Carl

_Gabi_
17th August 2010, 19:12
Hi Carl

Glad you like it.

Thought would provide an alternative/upgrade to/from the standard monochrome glcd/lcd's as it did for me.

This TFT presented here cost less than a 2x16 LCD or thereabout , its way much faster, you have colors, backlight, 172x136 pixels and we have the driver for it as well :) with any type of mono or multi color fonts you name it, compressed or not, etc etc.

I hope it will be useful or at least inspiring to anyone.

Ph1l1pJ
7th December 2010, 13:44
Can you tell me where I can buy an TFT LS020 type display ?