LCDTEST.C is provided as a sample for the use of LCD.C, DELAY.C provides a simple delay function. All the files and a ton of related pdf's (app notes, spec sheets, etc..) are available in hitachilcd-ak.zip
The character LCD interface LCD.C/LCD.H is based upon the Hitachi LCD controller chips. In particular, I have worked almost exclusively with the Hantronix LCD products because they are priced very reasonably in small quantities, whereas other manufacturers are higher priced in small quantities. If you use another vendor, you can compare their product on a "lines and rows" basis to a similar Hantronix part and be reasonably sure it will work right-off without a problem.
LCD.C supports both the four-bit and eight-bit interface modes of the controller. Select your choice in LCD.H. Port pins for the data bus must be assigned contiguously and in order. That is, in eight-bit mode, D0 must connect to the desired I/O ports 0 bit (say RB.0), D1 to RB.1, and so on. In four-bit mode the pins can begin anywhere in the port, but they must be sequential and contiguous. Use the definitions of LCD_D4_BIT, and LCD_TRIS_DATAMASK to match your wiring configuration. I heartily recommend using processor bits 7-4 for the data bus, and bits 3-1 for the control bus. A sample schematic is shown below:
Please note that all pins of the LCD interface except the E pin (enable) can be shared with other devices, particularly with a keypad. Any lines which are shared should be isolated from the data bus with at least 330 ohm resistors.
Be sure to set the PIN and PORT definitions in LCD.H to match your wiring configuration.
LCD.C also supports conditional exclusion of unused functions. If there are functions which you do not need in your application, you can reduce the code size by setting the appropriate LCD_ENABLE to FALSE. By default all modules are enabled. Note that some functions may be included even if you turned them off because another module requires it. Study the source to determine the exact interrelationships.
To ease the initialization of the display, LCD.C provides a startup string which is automatically configured to match your preferences as determined by the CURSOR and DISPLAY definitions. You can override these after lcd_init() by issuing the appropriate lcd_command sequence.
LCD.C also provides a few higher-level functions than what is implemented in the controller chip. These are a tiny terminal mode, whereby scrolling and some special ASCII control characters do something useful. Check function lcd_putc() to see exactly what these are.
The functions lcd_scroll() and lcd_unscroll() will scroll the LCD display up or down one line. This makes it very simple to provide your customer with a rolling display. The function lcd_define_char() enables the user to define a bit-map character for later use. When enabled, the lcd_putc() function will not perform terminal-mode functions. If you wish to have both, you will need to edit the C file to make it work the way you desire. But thats why you have the source anyway!
Funtion lcd_printf() makes it simple to print a ROM string. This function does not perform any of the formatting commands that the C-standard printf() function peforms. If you need that level of sophistication, follow the directions in the HiTech C manual for making a user-defined character output with the printf function.
Toward the end of LCD.H you will find a few COMMAND definitions. You should use these in order to issue forward and backspace and panning commands using the function lcd_command().
To determine the current position of the cursor, use lcd_getxy(). If all you need to know is the row, the function lcd_lineof() will return it given the cursor address.
Please note that LCD.C was written to enhance speed and reduce call-stack usage, although it is possible that further enhancements by the user can provide both. The source code as provided should give a good understanding of what optimizations are or are not needed.
i keep getting error saying defined more than once in this section of codeMarvin Ludwig replies: I'm getting the same Errors there as well: Error  F:\xxx\LCD_1\lcd.c; 454. symbol "l5668" defined more than once . . Error  F:\dropbox\Dropbox\Projekte\PIC\LCD_1\lcd.c; 454. symbol "l5666" defined more than once Advisory too many errors (21) the error log links me to this line: lcd_putbyte (0b00110000); even though i comment it, it keeps happening.. any help is appreciated =) +
#if LCD_4_BIT_MODE // Set LCD into 4-bit mode
lcd_putnybble (0b0011); // Select 8-bit mode
delay_mS (5); // Spec calls for 4.1 mS
here> lcd_putnybble (0b0011); // Do it again
My MCC18 compiler flagged up the same syntax error reported by "kevinwar99-Remove-at STOPspamyahoo.com" on line 74 "(PIN (LCD_E, PORTA,0);". Has anybody been able to resolve this? If not, please could somebody explain what this line does. Thanks JohnJames Newton of James Newton's Massmind replies: the PIN macro is defined in LCD.H as: #define PIN(n,x,y) static volatile bit n @ (unsigned)&x*8+y
Your C compiler apparently doesn't support bit variables.+
I only changed this part+
PIN (LCD_E, PORTC, 2);
PIN (LCD_RW, PORTC, 1);
PIN (LCD_RS, PORTC, 0);
PIN (LCD_TRIS_E, TRISC, 2);
PIN (LCD_TRIS_RW, TRISC, 1);
PIN (LCD_TRIS_RS, TRISC, 0);
then i connected my circuit and it didn't work, im using XT=4MHz, the LCD doesn't even get turned on.
Thanks for this code. It took a little work, but I got it to compile and it works well using the C18 compiler -- I even got it working with an 8mhz crystal with a few modifications.+
One note: In order to get cursor and blink to function correctly I had to add another 100uS delay after "lcd_putnybble (0b0011);" in lcd.c. According to the specs, you should delay all three times you send this command.
/techref/microchip/language/c/io/lcd/hitachilcd-ak/index.htmmuro replies: i can not take any result with 4 bit mode. i'm using hi-tech C 9,60 in MPLAB 8.30 with PROTEUS simulation. in 8 bit mode everything is OK. but in 4 bit mode proteus gives an error message; "[HD44780] Attempted to read after writing a single nibble"+
You work well!
case '\n': // Newline?
RS = 0;
LCD_RS = 0;
and I have problems with "4-bit mode" but not "8-bit mode.
(Cursor off and blinking are't fonctional)
I do screen tests (2x16 1602A) and (4x20 HS0066).
|file: /Techref/microchip/language/c/io/lcd/hitachilcd-ak/index.htm, 10KB, , updated: 2012/3/30 14:53, local time: 2020/7/5 20:01,
|©2020 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://piclist.com/techref/microchip/language/c/io/lcd/hitachilcd-ak/index.htm"> Character LCD Interface</A>
|Did you find what you needed?|
LCD Front Panel Set: $8.99!
- 2x16 LCD HD44780 controller
- 4 push buttons - 3 LEDs - 2x12 header
Welcome to piclist.com!