Author: jsuijs
Date: Sun Feb 22 11:50:40 2009
New Revision: 806
Added:
trunk/include/external/lcd/lcd_hd44780_common.jal
trunk/include/external/lcd/ng_hd44780_4.jal
Removed:
trunk/include/external/lcd/js_hd44780_common.jal
trunk/include/external/lcd/js_interface_4bit.jal
Modified:
trunk/sample/test/external/lcd/test_lcd_hd44780_4.jal
Log:
ng_hd44780_4 is new (refactored) lcd_hd44780_4
Added: trunk/include/external/lcd/lcd_hd44780_common.jal
==============================================================================
--- (empty file)
+++ trunk/include/external/lcd/lcd_hd44780_common.jal Sun Feb 22 11:50:40
2009
@@ -0,0 +1,406 @@
+-- ------------------------------------------------------
+-- Title: common for HD44780 based LCD
+--
+-- Author: Richard Zengerink, Copyright (c) 2008..2008, all rights
reserved.
+--
+-- Adapted-by: Joep Suijs
+--
+-- Compiler: =2.4
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: Common API for HD44780 based LCD
+--
+-- Sources:
+--
+-- Notes:
+--
+--
+-- ------------------------------------------------------
+
+--
+-- ------------- place this below, in your MAIN file and add to
---------
+-- ------------- the pins which are not used the variable:
---------
+-- ------------- "not_connected" and change the other pins
---------
+-- ------------- according to your hardware.
---------
+-- ------------- (now selected as 4 line)
---------
+-- ------------- also remove the "--"
---------
+
+-- var bit not_connected
+
+-- var volatile bit lcd_rs is pin_e0 -- data/command select
+-- var volatile bit lcd_rw is pin_e1 -- read/write select
+-- var volatile bit lcd_enable is pin_e2 -- clock the data
+
+-- var volatile bit lcd_d0 is not_connected
+-- var volatile bit lcd_d1 is not_connected
+-- var volatile bit lcd_d2 is not_connected
+-- var volatile bit lcd_d3 is not_connected
+-- var volatile bit lcd_d4 is pin_d4
+-- var volatile bit lcd_d5 is pin_d5
+-- var volatile bit lcd_d6 is pin_d6
+-- var volatile bit lcd_d7 is pin_d7
+
+
+-- const lcd_hardware_4line = true ;true = 4 data line, false = 8 data
line
+-- const lcd_number_of_display_lines = 2 ; 1 = 1 line 2 = 2 line 4
= 4 line
+-- const lcd_number_of_display_characters = 16 ; number of digits per
line
+
+-- include lcd_hd44780_rz
+
+--
--------------------------------------------------------------------------
+--
--------------------------------------------------------------------------
+
+--
-------------------------------------------------------------------------
+-- procedures which can be used in your Main file
+--
-------------------------------------------------------------------------
+--
+-- * lcd_write_data( byte in value ):
+-- writes(byte) data to lcd
+-- example: lcd_write_data( "E" ) or lcd_write_data( 69 )
+-- ---------------
+-- * lcd_new_line_cursor_position(byte in line, byte in pos):
+-- places the cursor on position (pos) in line (line)
+-- example: lcd_new_line_cursor_position (1, 8)
+-- --------------
+-- * lcd_shift_left(byte in value):
+-- shifts the display [value] times to the left without changing DDRAM
data.
+-- example: lcd_shift_left(4)
+-- or lcd_shift_left(variable)
+--
+-- * lcd_shift_right(byte in value):
+-- shifts the display [value] times to the right without changing DDRAM
data.
+-- example: lcd_shift_right(12)
+-- or lcd_shift_right(variable)
+--
+-- * lcd_cursor_shift_left(byte in value):
+-- shifts the cursor [value] times to the left without changing display
+-- contents and DDRAM data.
+-- example: lcd_cursor_shift_left(8)
+-- or lcd_cursor_shift_left(variable)
+--
+-- * lcd_cursor_shift_right(byte in value):
+-- shifts the cursor [value] times to the right without changing display
+-- contents and DDRAM data.
+-- example: lcd_cursor_shift_right(3)
+-- or lcd_cursor_shift_right(variable)
+--
+-- * lcd_clear:
+-- Write "20H" to DDRAM. and set
+-- DDRAM address to "00H" from AC
+--
+-- * lcd_home:
+-- Set DDRAM address to "00H" from
+-- AC and return cursor to its original
+-- position if shifted. The contents of
+-- DDRAM are not changed.
+--
+-- * lcd_cursor_blink_display(bit in cursor,bit in blink,bit in display):
+-- sets the cursor on/off, let the cursor blink or not(if the cursor is
on),
+-- and puts the display on/off
+-- example: lcd_cursor_blink_display(on,off,on)
+--
+-- * lcd_clear_line ( byte in line )
+-- clears the line [line] of the lcd including DDRAM data of that line
+-- example: lcd_clear_line(1)
+--
+-- * lcd_progress(byte in line, byte in amount)
+-- create a progress bar on line [line] with a lenght of [amout]
+-- example: lcd_progress(2,12)
+--
+--
+-- * lcd_bvalue_dp_line_pos_left_sign( byte in value, byte in dp, byte in
line, byte in poskar, bit in left, bit in sign )
+-- displays a byte value with decimal point on position [dp] on line
[line] on position [pos] left alignment true/false,
+-- signed value true/false
+-- byte value = 0 to 255 as value or as variable, dp = 0 means 100 dp =
1 means 10.0 dp = 2 means 1.00 and dp > than 3 means 0.100
+--
+--
+-- example1: lcd_bvalue_dp_line_pos_left_sign(25,0,1,5,true,false)
+-- result on line 1 on position 5 you get 25
+--
+-- example2: lcd_bvalue_dp_line_pos_left_sign(25,0,1,5,false,false)
+-- result on line 1 on position 5 you get [space]25 (25 starts at
position 6)
+--
+-- example3: lcd_bvalue_dp_line_pos_left_sign(225,0,2,1,true,true)
+-- result on line 2 on position 1 you get -31
+--
+-- example4: lcd_bvalue_dp_line_pos_left_sign(225,0,2,1,true,false)
+-- result on line 2 on position 1 you get 225
+--
+--
+-- * lcd_wvalue_dp_line_pos_left_sign( word in value, byte in dp, byte in
line, byte in poskar, bit in left, bit in sign )
+--
+--
+--
+-- * lcd_time( byte in hrs, byte in minut, byte in second, byte in
seperator )
+--
+--
+--
+-- * lcd_date( byte in day, byte in mounth, word in year, byte in
seperator, bit in day_mounth_notation )
+--
+--
+-- * lcd_bvalue_hex( byte in value)
+--
+--
+-- * lcd_wvalue_hex( word in value)
+--
+--
+--
+-- * lcd_bvalue_bin( byte in value)
+--
+--
+--
+--
+
+--
-----------------------------------------------------------------------------
+-- some constants to control the lcd
+--
-----------------------------------------------------------------------------
+const lcd_clear_display = 0b_0000_0001
+const lcd_return_home = 0b_0000_0010
+const lcd_display_onoff = 0b_0000_1000
+const lcd_cursor_shift_r_val = 0b_0001_0100
+const lcd_cursor_shift_l_val = 0b_0001_0000
+const lcd_display_shift_right = 0b_0001_1100
+const lcd_display_shift_left = 0b_0001_1000
+
+const lcd_set_ddram_address = 0b_1000_0000
+--
-----------------------------------------------------------------------------
+
+var volatile byte lcd_pos = 0
+
+
+
+procedure lcd_writechar(byte in data) is
+; pragma inline
+ _lcd_write_data(data)
+end procedure
+
+procedure lcd'put(byte in data) is
+ pragma inline
+ _lcd_write_data(data)
+end procedure
+
+
+--
----------------------------------------------------------------------------
+-- sets the cursor of the LCD to the position in the shadow register
+-- (this routine is only used inside this file)
+--
----------------------------------------------------------------------------
+procedure lcd_restore_cursor() is
+ -- set LCD back to normal operation
+ _lcd_write_command( lcd_set_ddram_address | lcd_pos )
+end procedure
+--
----------------------------------------------------------------------------
+
+
+--
----------------------------------------------------------------------------
+-- sets the cursor of the LCD on "pos" position in line "line" in the
shadow register
+--
+--
----------------------------------------------------------------------------
+procedure lcd_new_line_cursor_position(byte in line, byte in pos) is
+ pos = pos -1
+ if LCD_ROWS == 1 then
+ lcd_pos = pos
+
+ elsif LCD_ROWS == 2 then
+ if line == 1 then
+ lcd_pos = pos
+ else
+ lcd_pos = pos + 0x40
+ end if
+ else -- 4 lines
+ if line == 1 then lcd_pos = pos
+ elsif line == 2 then lcd_pos = pos + 0x40
+ elsif line == 3 then lcd_pos = pos + 0x14
+ else line == 4 then lcd_pos = pos + 0x54
+ end if
+ end if
+
+ lcd_restore_cursor
+
+end procedure
+
+
+
+--
----------------------------------------------------------------------------
+-- shifts the coplete display one position to the left
+--
----------------------------------------------------------------------------
+procedure lcd_shift_left(byte in nr) is
+ -- set LCD back to normal operation
+
+ if nr != 0 then
+ for nr loop
+ _lcd_write_command( lcd_display_shift_left )
+ end loop
+ end if
+end procedure
+--
----------------------------------------------------------------------------
+
+--
----------------------------------------------------------------------------
+-- shifts the complete display one position to the right
+--
----------------------------------------------------------------------------
+procedure lcd_shift_right(byte in nr) is
+ if nr != 0 then
+ for nr loop
+ _lcd_write_command( lcd_display_shift_right )
+ end loop
+ end if
+end procedure
+--
----------------------------------------------------------------------------
+
+ --
----------------------------------------------------------------------------
+-- shifts cursor one position to the left
+--
----------------------------------------------------------------------------
+procedure lcd_cursor_shift_left(byte in nr) is
+ if nr != 0 then
+ for nr loop
+ _lcd_write_command( lcd_cursor_shift_l_val )
+ end loop
+ end if
+end procedure
+--
----------------------------------------------------------------------------
+
+--
----------------------------------------------------------------------------
+-- shifts cursor one position to the right
+--
----------------------------------------------------------------------------
+procedure lcd_cursor_shift_right(byte in nr) is
+ if nr != 0 then
+ for nr loop
+ _lcd_write_command( lcd_cursor_shift_r_val )
+ end loop
+ end if
+end procedure
+--
----------------------------------------------------------------------------
+
+--
----------------------------------------------------------------------------
+-- clears the LCD
+--
----------------------------------------------------------------------------
+procedure lcd_clearscreen() is
+ _lcd_write_command( lcd_clear_display )
+ delay_10us( 180 )
+end procedure
+--
----------------------------------------------------------------------------
+
+--
----------------------------------------------------------------------------
+-- sets or resets cursor blink and puts display on or off
+--
----------------------------------------------------------------------------
+procedure lcd_cursor_blink_display(bit in cursor,bit in blink,bit in
display) is
+ var byte reg
+
+ reg = lcd_display_onoff
+ if display then reg = reg + 4 end if
+ if cursor then reg = reg + 2 end if
+ if blink then reg = reg + 1 end if
+ _lcd_write_command( reg )
+end procedure
+--
----------------------------------------------------------------------------
+
+
+
+--
----------------------------------------------------------------------------
+-- cursor returns home(line 1, position 1)
+--
----------------------------------------------------------------------------
+procedure lcd_home() is
+ _lcd_write_command( lcd_return_home )
+ delay_10us( 180 )
+end procedure
+--
----------------------------------------------------------------------------
+
+
+--
----------------------------------------------------------------------------
+-- clears the line "line" of the LCD
+--
----------------------------------------------------------------------------
+procedure lcd_clear_line( byte in line ) is
+ -- set LCD-cursor at start of line
+ if line == 1 then lcd_pos = 0 end if
+ if line == 2 then lcd_pos = 40 end if
+
+ lcd_restore_cursor
+
+ -- now fill line with spaces
+ for 39 loop
+ lcd = " "
+ end loop
+
+ -- set LCD back to normal operation
+ lcd_restore_cursor
+end procedure
+--
----------------------------------------------------------------------------
+
+
+
+--
-----------------------------------------------------------------------------
+-- Displays a progress bar
+--
+--
-----------------------------------------------------------------------------
+procedure lcd_progress(byte in line, byte in amount, byte in pattern) is
+
+ if LCD_ROWS == 1 then
+ lcd_pos = pos
+
+ elsif LCD_ROWS == 2 then
+ if line == 1 then
+ lcd_pos = 0
+ else
+ lcd_pos = 0x40
+ end if
+ else -- 4 lines
+ if line == 1 then lcd_pos = 0
+ elsif line == 2 then lcd_pos = 0x40
+ elsif line == 3 then lcd_pos = 0x14
+ else line == 4 then lcd_pos = 0x54
+ end if
+ end if
+
+ lcd_restore_cursor
+
+ for amount loop
+ lcd = pattern
+ end loop
+
+ for ( LCD_CHARS - amount) loop
+ lcd = " "
+ end loop
+
+end procedure
+--
----------------------------------------------------------------------------
+
+-- 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).
+-- ------------------------------------------------------------
+procedure lcd_setcursor(byte in row, byte in col) is
+
+ col = col | 0b1000_0000 -- set to DRAM offset top
line
+ case row of
+ 1: col = col + 0x40 -- 2nd line of 2 or 4 line
lcd
+ 2: col = col + LCD_CHARS -- 3rd line \ with 4x16
+ 3: col = col + 0x40 + LCD_CHARS -- 4th line / or 4x20
+ end case
+ _lcd_write_command(col) -- set new cursor position
+
+end procedure
+
+
+--
-----------------------------------------------------------------------------
+-- Initialise display
+--
-----------------------------------------------------------------------------
+procedure _hd44780_init() is
+
+
+ _lcd_write_command(0b0010_1000) -- 4-bits, 2 lines, 5x8
font
+ _lcd_write_command(0b0001_1100) -- cursor move right
+ _lcd_write_command(0b0000_1100) -- display on,
cursor,blink off
+ _lcd_write_command(0b0000_0110) -- cursor->right, no shift
+ lcd_clearscreen() -- clear screen
+ -- (incl switch to data
char mode)
+end procedure
Added: trunk/include/external/lcd/ng_hd44780_4.jal
==============================================================================
--- (empty file)
+++ trunk/include/external/lcd/ng_hd44780_4.jal Sun Feb 22 11:50:40 2009
@@ -0,0 +1,159 @@
+--
-----------------------------------------------------------------------------
+-- Title: LCD library for HD44780 compatible LCDs, with 4 bits wide
datatransfer
+-- Author: Rob Hamerling, Copyright (c) 2008..2008, all rights reserved.
+-- Adapted-by: Eur van Andel, Joep Suijs (refactoring)
+-- 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:
+-- 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).
+-- *
+--
+-- ;; ;; JS: check where we put this info - actually, this file is only the
+-- ;; ;; driver and
+-- ;; Available functions for application programs:
+-- ;; lcd_init() initialize the LCD
controller
+-- ;; lcd_clearscreen() clear screen, cursor home
+-- ;; 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 byte variable 'lcd' is declared as alternative for
lcd_writechar(<byte>)
+-- ;; So in stead of: lcd_writechar(<byte>)
+-- ;; you may use: lcd = <byte>
+-- ;; And you may also use 'lcd' as destination in functions of other
+-- ;; libraries, like print().
+--
+--
+-- Dependencies: delay.jal
+--
+--
-----------------------------------------------------------------------------
+include delay
+
+--
----------------------------------------------------------------------------
+-- 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
+ ;pragma inline
+
+ if (defined(lcd_dataport) == true) then
+ -- write nibble at once
+ lcd_dataport = value -- replace low nibble
+ else
+ -- write nibble bit by bit
+ var bit bit0 at value : 0
+ var bit bit1 at value : 1
+ var bit bit2 at value : 2
+ var bit bit3 at value : 3
+
+ -- setup databits
+ lcd_d4 = bit0
+ lcd_d5 = bit1
+ lcd_d6 = bit2
+ lcd_d7 = bit3
+ end if
+
+ -- generate clockpuls
+ lcd_en = HIGH -- trigger on
+ asm nop -- delay (> 400 ns)
+ lcd_en = LOW -- trigger off
+
+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_10us(4) -- > 37 us
+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 = 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 = 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 = 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 �s
+ __lcd_write_nibble(0b0000_0011) -- function set
+ delay_10us(4) -- > 37 �s
+ __lcd_write_nibble(0b0000_0010) -- to 4-bit mode
+ delay_10us(4) -- > 37 �s
+
+ -- init the API
+ _hd44780_init()
+end procedure
\ No newline at end of file
Modified: trunk/sample/test/external/lcd/test_lcd_hd44780_4.jal
==============================================================================
--- trunk/sample/test/external/lcd/test_lcd_hd44780_4.jal (original)
+++ trunk/sample/test/external/lcd/test_lcd_hd44780_4.jal Sun Feb 22
11:50:40 2009
@@ -32,11 +32,12 @@
led_direction = output
-lcd_rs_direction = output
-lcd_en_direction = output
-lcd_dataport_direction = output
+lcd_rs_direction = output
+lcd_en_direction = output
+lcd_dataport_direction = output
-include lcd_hd44780_4 -- LCD library with 4 data lines
+;include lcd_hd44780_4 -- LCD library with 4 data lines
+include ng_hd44780_4
include print -- formatted output library
for 4 loop -- blink LED 4 times to indicate
startup
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---