Author: robhamerling
Date: Tue Oct 7 08:00:42 2008
New Revision: 369
Modified:
trunk/unvalidated/include/external/lcd/lcd_hd44780_4.jal
Log:
Removed direction settings in lcd_setup(), increased power-up delay, added
constants for display size, updated lcd_setcursor() procedure, updated
user instructions
Modified: trunk/unvalidated/include/external/lcd/lcd_hd44780_4.jal
==============================================================================
--- trunk/unvalidated/include/external/lcd/lcd_hd44780_4.jal (original)
+++ trunk/unvalidated/include/external/lcd/lcd_hd44780_4.jal Tue Oct 7
08:00:42 2008
@@ -9,43 +9,56 @@
--
-- Sources:
--
--- Description: Controls HD44780 compatible alphanumeric LCD screens.
+-- Description: 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'
--
-- Dependencies: delay_any_mc.jal
--
--- Code example:
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+--
+-- Directions for use of this library:
--
-- The application program must declare the following variables (aliases)
--- _before_ the include of this library!
+-- and constants _before_ the include of this library:
+--
+-- const byte LCD_ROWS = 2 -- 2 lines
+-- const byte LCD_CHARS = 16 -- 16 chars per line
+--
+-- var byte lcd_dataport is portA_low -- LCD data
+-- var bit lcd_en is pin_A4 -- LCD data trigger
+-- var bit lcd_rs is pin_A5 -- LCD cmd/data select
+--
+-- Then set the dataport and handshake pin directions:
+--
+-- PortA_low_direction = all_output -- make datapath output
+-- pin_A4_direction = output -- \
+-- pin_A5_direction = output -- / make handshake lines
output
--
--- var byte lcd_dataport is portA_low -- LCD data
--- var byte lcd_dataport_direction is portA_low_direction
--- var bit lcd_en is pin_A4 -- LCD data
trigger
--- var bit lcd_en_direction is pin_A4_direction
--- var bit lcd_rs is pin_A5 -- LCD cmd/data
select
--- var bit lcd_rs_direction is pin_A5_direction
+-- And then include this library.
--
--- Above is an example: 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
+-- 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_setup() (called automatically)
-- lcd_clearscreen() clear screen, cursor
home
--- lcd_setcursor(<row>,<column>) position cursor
+-- lcd_setcursor(<row>,<column>) where to write next
character
-- lcd_writechar(<byte>) write single character
-- at cursor position and
-- shift cursor position 1
right
--- A pseudo variable 'lcd' is available as alternative for
lcd_writechar(<byte>):
--- var byte lcd
+--
+-- A pseudo byte variable 'lcd' is declared as alternative for
lcd_writechar(<byte>)
-- So in stead of writing: lcd_writechar(<byte>)
-- you may write: lcd = <byte>
+-- And you may use 'lcd' as destination in other functions, like print().
--
---
-----------------------------------------------------------------------------
+-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
include delay_any_mc -- delay procedures
@@ -61,14 +74,15 @@
lcd_dataport = data -- replace low nibble
lcd_en = HIGH -- trigger on
- asm nop -- wait (> 400 ns)
+ asm nop -- delay (> 400 ns)
lcd_en = LOW -- trigger off
end procedure
-- ----------------------------------------------------------
-- Send byte to the LCD as 2 nibbles (most significant nibble first)
--- (and automatically set the cursor one position right)
+-- and automatically set the cursor one position right.
+-- There is no check on line overflow.
-- ----------------------------------------------------------
procedure lcd_writechar(byte in c) is
@@ -106,8 +120,11 @@
-- 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 a 4x16 or 4x20 LCD the third line starts at offset 20 and the
--- fourth line at offset 84 (0x40 + 20).
+-- 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 the second line.
--
@@ -120,9 +137,9 @@
col = col | 0b1000_0000 -- set to DRAM offset top
line
case row of
- 1: col = col + 0x40 -- 2nd line of 2 or 4 line
displays
- 2: col = col + 20 -- 3rd line \ 4x16 or
- 3: col = col + 0x40 + 20 -- 4th line / 4x20
+ 1: col = col + 0x40 -- 2nd line of 2 or 4 line
lcd
+ 2: col = col + LCD_CHARS -- 3rd line \ 4x16 or
+ 3: col = col + 0x40 + LCD_CHARS -- 4th line / 4x20
end case
lcd_rs = LOW -- set to control char mode
lcd_writechar(col) -- set new cursor position
@@ -133,22 +150,15 @@
-- -----------------------------------------------------
-- Initialize LCD
--- - global init to 4-bit data mode
--- - 2-line (/ 4-line) mode, shift right invisible cursor
+-- - for 4-bit data mode
+-- - 2-line (/ 4-line) mode
+-- - shift right, invisible cursor
-- -----------------------------------------------------
procedure lcd_setup() is
--- Initialize the port and pin directions
-
- lcd_dataport_direction = all_output -- make datapath output
- lcd_en_direction = output -- \
- lcd_rs_direction = output -- / make handshake lines
output
-
--- Initialize HD44780 controller for 4-bit data mode
-
lcd_rs = LOW -- set to control char mode
- delay_1ms(15) -- 15 ms power-up delay
+ delay_1ms(25) -- power-up delay (> 15 ms)
_lcd_writenibble(0b0000_0011) -- function set
delay_1ms(5) -- > 4.1 milliseconds
_lcd_writenibble(0b0000_0011) -- function set
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---