1 / 8

Eejit’s guide to using a LCD alphanumeric display with the CCS C compiler

Eejit’s guide to using a LCD alphanumeric display with the CCS C compiler. Hardware connection The LCD.C include file An example. 1 : Hardware connection. 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.

torin
Download Presentation

Eejit’s guide to using a LCD alphanumeric display with the CCS C compiler

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 1: Hardware connection 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. 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 TRUEmust be in your program before the LCD.C file is included. The wiring diagram of the next slide shows the connections that have to be made.

  3. 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: • 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. • 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”);. • 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. • 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 • 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.

  4. 3: An example • To display the message on the LCD (2-line, 16 characters):PIC says helloxxth 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. • Header:#define <16f877a.h>#use delay(clock = 8000000)#fuses HS,NOWDT,NOPROTECT,PUT,NOLVP#use rs232(baud=4800,xmit=PIN_C6)#bit LED = 5.5#include <LCD.C> I am using a PIC16F877A as the target With a 8MHz crystal, which is why the High Speed fuse is specified 4800 baud out of pin RC6 (UART) Give pin RA5 the name LED The all important LCD file included

  5. 16-bit variable i records the message count Now initialise the LCD device Set Pin RA5 as Output (b’01111’) • 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);} } Ensure that Port A is all digital (not analog) DO forever Long Decimal placeholder for i Turn on LED Message through the serial port Clear display and start again Line 2 Message through the lcd_putc() function to the LCD display Delay for 0.5 second LED off Delay for 0.5 second

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

  7. And this is what the LCD display looks like.

More Related