• No results found

Using Graphic LCD

In document PIC for Beginners (Page 66-70)

LCD_ENPIN = PORTC.2 LCD_RWPIN = PORTC.1 LCD_CS1PIN = PORTE.0 LCD_CS2PIN = PORTE.1 LCD_TYPE = GRAPHIC

We are going to connect the LCD data to PORTD, all 7 bits of PORTD will be used. The control pins will be connected to pins on PORTC, and chip select pins, CS1 and 2 on PORTE. The LCD_TYPE must be mentioned as Graphic otherwise by default character LCD is assumed by Proton Basic Compiler. You may chose any other pins as per your project. Once these connections have been defined the PRINT command can be used to send text data, and a bunch of graphic commands to send graphic data to LCD.

Font Declaration

After declaring the electrical connections, we have to inform the compiler about location of fonts table. The fonts table can be located on internal RAM or external EEPROM. Secondly more than one sets of fonts can be defined in EEPROM. The starting address of font table to use also has to be defined.

INTERNAL_FONT = On FONT_ADDR = 0

These two declarations define that we are going to use on-chip EEPROM, and Font table will be starting from byte 0 of EEPROM.

The font is described in a specific format like:

' Font CDATA table

' Copy and paste this table into your own program ' if an internal font is required.

Font:- CData $00,$00,$00,$00,$00,$00 'Graphic character 0 CData $FF,$FF,$FF,$FF,$FF,$FF 'Graphic character 1 CData $07,$07,$07,$00,$00,$00 'Graphic character 2 CData $00,$00,$00,$07,$07,$07 'Graphic character 3 CData $E0,$E0,$E0,$00,$00,$00 'Graphic character 4

This must be declared at the bottom of program. Notice the Font:- before starting data. The CData defines ready to read data within the program memory, starting from location where its been declared. The data itself consists of 6 bytes, the bit pattern of which defines a complete character to be displayed.

Fortunately Proton Basic comes with two predefined font files, located in installation folder. You can include this file in your program, by copying and pasting the entire table, or by copying the file in your project folder and using include statement.

Some displays internally invert the signals of chip1 and chip2, which result in malformed or mal-aligned data. If this is the case with your display also include this declare before using the LCD.

Declare GLCD_CS_INVERT true

In my case the display I use has CS inverted so I use this statement.

Notice the include statement in the program. The included file name is FONT.INC. This program will print the text on graphic LCD. Notice the print statement is exactly the same. Internally it has dealt with the complexity of graphic LCD.

Well there are a few things more that you can supply on print command. You can use the AT modifier just like character LCD. And keep it in mind that the numbers after AT are again line and character position not Device = 18F452

Print "This is Graphics Test"

End

Include "FONT.INC"

dots.

Print At 2,2,Inverse 1, "This is Graphics"

The inverse 1, will display the text in reverse, that is white on black background.

Print Cls Plot 20,50

The plot command is graphic library command, it will accept y,x position coordinates and display a dot on location. You can use this command in a variety of ways to control the location of coordinates and display dots. Like making a waveform, from data read on analog port to show its fluctuations.

The opposite of Plot command is Unplot. It clears the pixel at y,x location. The above program, first draws a line, by writing individual dots, and then clears them one by one.

Print Cls

Line 1,0,0,127,63

The line command is used to draw a line between two coordinates. The first argument 1 in this example indicates if line is to be drawn or erased. 1 is to draw. The next two pairs are x1,y1, x2,y2 two sets of coordinates to indicate line end positions.

This example draws a sequence of lines, increment x axis by 2. since lines are calculated mathematically, there is slight ragging in slanting lines. This ragging appears as a pattern on display.

Print Cls

Box 1, 60,30,20

The box command will make a box on screen. First parameter is again, weather to show or clear, the next two are x and y coordinates of center of box, and last parameter is the size of box.

Displaying Bitmap Images

Bitmap images are converted into appropriate format for display on graphic LCD first. A number of free to download programs are available on internet. The converted data is then sent to graphic LCD to show the bitmap image. Similarly there are tools available that can produce fonts data for graphical LCD from your system fonts.

Color LCDs and Touch Panels

Apart from the commonly used graphic LCDs, there are color LCDs as well. These LCDs have varying controller on board and you will need to look at the data sheets of your particular display to use it. The color LCDs differ in depth of color. This means the number of colors which can be displayed per pixel.

Most common are 65K color LCDs, however true type image quality displays called TFTs are also available with 262K color depth.

Touch panels are now commonly used in conjunction with graphical LCDs to get user input. Touch panel consists of a separate sheet of transparent membrane, incorporating thousands of touch sensitive points. It is available separately, or sometimes incorporated right over the display. It has its own driver circuit, which needs to be calibrated with the display.

In document PIC for Beginners (Page 66-70)