Author: jsuijs
Date: Sat Mar  7 07:53:18 2009
New Revision: 833

Added:
    trunk/include/external/lcd/lcd_hd44780_serial_sw.jal

Log:
LCD display via serial software

Added: trunk/include/external/lcd/lcd_hd44780_serial_sw.jal
==============================================================================
--- (empty file)
+++ trunk/include/external/lcd/lcd_hd44780_serial_sw.jal        Sat Mar  7  
07:53:18 2009
@@ -0,0 +1,126 @@
+--  
-----------------------------------------------------------------------------
+-- Title: LCD library for HD44780 compatible LCDs, interfaced with 1 pin  
(serial_sw)
+-- Author: Joep Suijs, Copyright (c) 2008..2009, all rights reserved.
+-- Adapted-by:
+-- Compiler:  >=2.4g
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the ZLIB license  
(http://www.opensource.org/licenses/zlib-license.html)
+--
+-- Sources:
+--
+-- Description:
+--    Software serial interface for HD44780 compatible alphanumeric LCD  
screens.
+--  --
+--    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 bit serial_sw_tx_pin  is  pin_d0     -- pin on which lcd  
is connected
+-- --
+--    2. Set the chosen LCD dataport and handshake pins to output:
+--          pin_d0_direction = output
+-- --
+--    3. Include this library.
+-- --
+--    4. Call lcd_init() to initialize the lcd controller.
+-- --
+--    Above is an example for a 2x16 LCD, connected to pin d0
+-- --
+--    See hd_44780_common for the LCD API.
+--
+-- Dependencies: delay.jal
+--               serial_software
+--
+--  
-----------------------------------------------------------------------------
+
+include delay
+
+var bit     serial_sw_rx_pin              ; dummy to include lib; will be  
optimised away.
+const bit   serial_sw_invert     = true   ; normal (low active) serial  
comms
+const       serial_sw_baudrate   = 57600
+include serial_software
+
+var bit lcd_rs_shadow
+
+--  
----------------------------------------------------------------------------
+-- sends low nibble from value to the LCD
+-- can be used for both commands and data
+-- (requires no wait cycli inbetween upper and lower nibble)
+-- (this routine is only used inside this file)
+--  
----------------------------------------------------------------------------
+procedure __lcd_write_nibble( byte in value ) is
+
+   value = value & 0x0F
+   if (lcd_rs_shadow) then
+      value = value | 0x10
+   end if
+
+   serial_sw_write(value) -- interrupts are disabled by lib
+end procedure
+--  
----------------------------------------------------------------------------
+
+
+--  
----------------------------------------------------------------------------
+-- sends byte from value to register of the LCD
+-- (this procedure is only used inside this file)
+--
+--  
----------------------------------------------------------------------------
+procedure __lcd_write( byte in value ) is
+   __lcd_write_nibble(value >> 4)               -- write high nibble
+   __lcd_write_nibble(value)                    -- write low nibble
+   ; delay of 37 us is not required, since each byte takes 170us to transer
+end procedure
+--  
----------------------------------------------------------------------------
+
+
+--  
----------------------------------------------------------------------------
+-- sends data byte in value to LCD
+-- for slow commands an extra delay should be added
+--
+--  
----------------------------------------------------------------------------
+procedure _lcd_write_data(byte in value) is
+   lcd_rs_shadow = high                                -- select  
instruction
+   __lcd_write( value )                         -- output byte
+end procedure
+--  
----------------------------------------------------------------------------
+
+
+--  
----------------------------------------------------------------------------
+-- sends command byte in value to LCD
+-- for slow commands an extra delay should be added
+--
+--  
----------------------------------------------------------------------------
+procedure _lcd_write_command(byte in value) is
+;   pragma inline
+   lcd_rs_shadow = low                              -- select instruction
+   __lcd_write( value )                      -- output byte
+end procedure
+--  
----------------------------------------------------------------------------
+
+
+-- now we defined the interface, add the API
+include lcd_hd44780_common
+
+--  
----------------------------------------------------------------------------
+--  
----------------------------------------------------------------------------
+--  
----------------------------------------------------------------------------
+procedure lcd_init() is
+
+   -- first, init the interface
+   lcd_rs_shadow = LOW                                 -- set to control  
char mode
+   delay_1ms(25)                                -- power-up delay (> 15 ms)
+   __lcd_write_nibble(0b0000_0011)              -- function set
+   delay_1ms(5)                                 -- > 4.1 milliseconds
+   __lcd_write_nibble(0b0000_0011)              -- function set
+   delay_10us(10)                               -- > 100 us
+   __lcd_write_nibble(0b0000_0011)              -- function set
+   delay_10us(4)                                -- > 37 us
+   __lcd_write_nibble(0b0000_0010)              -- to 4-bit mode
+   delay_10us(4)                                -- > 37 us
+
+    -- init the API
+    _hd44780_init()
+end procedure

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to