Author | Rob Hamerling, Copyright (c) 2008..2008, all rights reserved. |
Adapted-by | Eur van Andel |
Compiler | >=2.4g |
Simple interface for HD44780 compatible alphanumeric LCD screens. Screens can range from 2x8 (2 lines, 8 chars) to 4x20. Uses 4 bit wide datapath + 2 handshake lines (total 6 PIC pins). No support for shift and characterset manipulations. Expects: - 2 pins for handshake: 'lcd_rs' and 'lcd_en' - 1 port nibble for data: 'lcd_dataport' * Directions for use of this library in application programs (in this sequence): 1. Declare the following constants: const byte LCD_ROWS = 2 -- 1, 2 or 4 lines const byte LCD_CHARS = 16 -- 8, 16 or 20 chars per line and variables (aliases): var byte lcd_dataport is portA_low -- 4 data pins var bit lcd_en is pin_A4 -- trigger var bit lcd_rs is pin_A5 -- cmd/data select 2. Include this library. and somewhere before actually using the lcd: 3. Set the chosen LCD dataport and handshake pins to output: portA_low_direction = all_output pin_A4_direction = output pin_A5_direction = output 4. Call lcd_init() to initialize the lcd controller. Above is an example for a 2x16 LCD: Bits 0..3 of portA are used for data, pins 4 and 5 of portA are used for handshake. Any other available nibble and handshake pins could be used (provided these are configurable for output). * Available functions for application programs: lcd_init() initialize the LCD controller lcd_clearscreen() clear screen, cursor home lcd_setcursor(,
) where to write next character lcd_writechar( ) write single character at cursor position and shift cursor position 1 right * A pseudo byte variable 'lcd' is declared as alternative for lcd_writechar( ) So in stead of: lcd_writechar( ) you may use: lcd = And you may also use 'lcd' as destination in functions of other libraries, like print().
lcd_setcursor(byte in row, byte in col)
lcd'put(byte in c)
lcd_clearscreen()
lcd_init()
lcd_writechar(byte in c)
lcd_setcursor(byte in row, byte in col)
About cursor positions: the LCDs are internally 2x40 char devices. The first line starts at offset 0, the second line at offset 64 (0x40). With 4 line devices the third and fourth line are addressed as extensions of the first and second line by adding an offset. For a 4x20 line device the offset is 20, for a 4x16 line display the offset is 16 or 20. Declare the constant LCD_CHARS as appropriate for your screen (you may have to specify 20 even if your display has only 16 chars!). Note: Some 1x16 LCDs are implemented as 2x8 line LCDs, which means that the second half of the line has to be handled as a second line. Set cursor position Specify row and column in base-0 notation (first line is 0).
lcd'put(byte in c)
Pseudo variable 'lcd' as alternative for lcd_writechar()
lcd_clearscreen()
Clear screen (and set the cursor to the upper left corner: row 0, column 0)
lcd_init()
Initialize LCD * for 4-bit data mode * 2-line (/ 4-line) mode * shift right, invisible cursor
lcd_writechar(byte in c)
Send byte to the LCD as 2 nibbles (most significant nibble first) and automatically set the cursor one position right. There is no check on line overflow.
_lcd_writenibble(byte in data)
Write nibble (lower order 4 bits of byte) to LCD. Nibble is sent to dataport. lcd_rs is not touched: function can be used for commands and data. When wait is required after write then caller should wait (in 4-bit mode only required after second nibble).
sample | 16f876a_t6603.jal |
sample | 16f877a_co2_t6603.jal |
sample | 16f877a_hello_world_lcd.jal |
sample | 16f877a_lcd_format.jal |
sample | 16f876a_sht.jal |
sample | 18f6310_lcd_hd44780_4.jal |
sample | 16f876a_rtc_lcd.jal |
sample | 16f690_hello_world_lcd.jal |
sample | 16f876a_tc77.jal |
sample | 16f876a_keyboard_lcd.jal |
sample | 16f877a_keyboard_lcd.jal |
sample | 16f88_hello_world_lcd.jal |
sample | 16f877a_rtc_lcd.jal |
sample | 16f819_hello_world_lcd.jal |