Presentation is loading. Please wait.

Presentation is loading. Please wait.

Eejit’s guide to using a LCD alphanumeric display with the CCS C compiler 1.Hardware connection 2.The LCD.C include file 3.An example.

Similar presentations


Presentation on theme: "Eejit’s guide to using a LCD alphanumeric display with the CCS C compiler 1.Hardware connection 2.The LCD.C include file 3.An example."— Presentation transcript:

1 Eejit’s guide to using a LCD alphanumeric display with the CCS C compiler 1.Hardware connection 2.The LCD.C include file 3.An example

2 1 1: Hardware connection 1.The CCS LCD.C file is based on the LCD 4-bit mode, which only uses the top four Data pins of the LCD module. 2.The CCS LCD.C file defaults to all connections to Port D. If you wish to use Port B, then the line #define use_portb_lcd TRUE must be in your program before the LCD.C file is included. 3.The wiring diagram of the next slide shows the connections that have to be made.

3

4 2: The LCD.C file The standard CCS distribution comes with the file LCD.C, which in Version 4 is to be found in folder Program Files/PICC/Drivers by default. You should print this out. By including this file in the preamble of your program you can access the following functions: 1.Function lcd_init(). Normally this should be in your main() function following any variable definitions. This initializes the LCD module and thus should be run BEFORE any other LCD-related operation. 2.Function lcd_putc(c). Will display the character c in the next position of the LCD; e.g. lcd_putc(‘H’);. If the character is \f then the display is cleared, if \n then go to start of line 2 and if \b move back one position. This function also seems to work (at least in Version 4) with strings; e.g. lcd_putc(“Hello world”);. 3.Function lcd_gotoxy(x,y) is used to move the virtual cursor to any position in line 1 ( y is 1) or line 2 ( y = 2). E.g. lcd_gotoxy(8,2); moves the cursor to character position 8 in line 2. 4.Function lcd_getc(x,y) returns the character displayed on line y position x ; e.g. digit = lcd_getc(8,2); assigns the variable digit to the value displayed in line 2 position 8 5.If your application is using a different LCD; e.g. a 4-line display, then you need to copy and rename the lcd.c file and edit your renamed file.

5 3: An example To display the message on the LCD (2-line, 16 characters): PIC says hello xxth time *** where xx is incremented every second. Send a message “For the xxth time: Hello world from the PIC” via the serial port at 4,800 baud. Flash an LED connected to pin RB5 each time a message is sent/displayed. 1.Header: #define #use delay(clock = 8000000) #fuses HS,NOWDT,NOPROTECT,PUT,NOLVP #use rs232(baud=4800,xmit=PIN_C6) #bit LED = 5.5 #include I am using a PIC16F877A as the target With a 8MHz crystal, which is why the High Speed fuse is specified Give pin RA5 the name LED The all important LCD file included 4800 baud out of pin RC6 (UART)

6 2.Main function: main() { unsigned long int i = 0; lcd_init(); set_tris_a(0x1F); setup_adc_ports(NO_ANALOGS); while(TRUE) { LED = 1; printf(“For the %luth time; Hello world from the PIC\n\r”,i); printf(lcd_putc,”\fPIC says hello\n%luth time ***”,i++); delay(500ms); LED = 0; delay(500ms); } } 16-bit variable i records the message count Now initialise the LCD device Set Pin RA5 as Output (b’01111’) Ensure that Port A is all digital (not analog) DO forever Turn on LED Message through the serial port Long Decimal placeholder for i Message through the lcd_putc() function to the LCD display Delay for 0.5 second LED off Delay for 0.5 second Clear display and start again Line 2

7 This is what it looks like using HyperTerminal through a serial port of a PC

8 And this is what the LCD display looks like.


Download ppt "Eejit’s guide to using a LCD alphanumeric display with the CCS C compiler 1.Hardware connection 2.The LCD.C include file 3.An example."

Similar presentations


Ads by Google