Hi Richard & others > I would love to modify and cleanup lcd_hd44780_common What kind of changes do you suggest? I'll be working on this file today and do some cleanup. So tomorrow would be a good check again.
> and please let we > rename to lcd_common instead of lcd_hd44780_common so that we can use it > for maybe other (non hd448780) lcd's in the futher. I thought about this but decided for this name. The reason is that there are many displays that are not compatible with hd44780 (I have two here: a graphics lcd and a starburst one). So it is better to give a more distinct name to the lib, since we can expect more shared lcd libs. But it is a lib that is not included by the end user and you can use it for any display that is hd44780 compatible (like dogm) without the user noticing. Joep > > Added: trunk/include/external/lcd/lcd_dog_m_4.jal > ============================================================================== > --- (empty file) > +++ trunk/include/external/lcd/lcd_dog_m_4.jal Sat Mar 7 12:16:30 2009 > @@ -0,0 +1,194 @@ > +-- ------------------------------------------------------ > +-- Title: control for DOG-M (ST7036 based) LCD's > +-- > +-- Author: Richard Zengerink, Copyright (c) 2008, all rights reserved > +-- Adapted-by: > +-- > +-- Compiler: =2.4 > +-- > +-- This file is part of jallib (http://jallib.googlecode.com) > +-- Released under the ZLIB license > (http://www.opensource.org/licenses/zlib-license.html) > +-- > +-- > +-- > +-- Description: > +-- Simple interface for DOG-M (st7036) alphanumeric LCD screens. > +-- Screens can range from 1x8 (1 lines, 8 chars), 2x16 and 3x16. > +-- Uses 4 bit wide datapath + 2 handshake lines (total 6 PIC pins). > +-- 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 3 lines > +-- const byte LCD_CHARS = 16 -- 8, 16 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_writenibble(byte) > + > + > + > +-- _lcd_write(<byte>) sends byte from value to > +-- register of the lcd and > +-- shift cursor position 1 > right > +-- > +-- _lcd_write_data(<byte>) write data to lcd using > +-- _lcd_write(<byte>) lcd_rs > high > +-- > +-- _lcd_write_data(<byte>) write command to lcd using > +-- _lcd_write(<byte>) lcd_rs > low > +-- > +-- lcd_init() initialize the LCD > controller > +-- > +-- > +-- Dependencies: delay.jal > +-- > +-- > ----------------------------------------------------------------------------- > + > +-- > +-- Notes: > +-- > +-- this type can be attached to your microcontroller serial with only 3 or > +-- 4 lines in total > +-- example type name: EA DOG-M > http://www.lcd-module.com/products/dog.html > +-- > + > +include delay -- include standard delay lib > +-- > +-- > +-- > +-- > ----------------------------------------------------------------------------- > +-- some constants to control the lcd > +-- > ----------------------------------------------------------------------------- > +const lcd_clear_display = 0b_0000_0001 -- long delay > +const lcd_return_home = 0b_0000_0010 -- long delay > +const lcd_display_onoff = 0b_0000_1000 -- short delay > + > +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 > +const lcd_set_cgram_address = 0b_0100_0000 > +-- > ----------------------------------------------------------------------------- > + > +-- > ----------------------------------------------------------------------------- > +-- delay's necessary for initialisation and some commands > +-- > ----------------------------------------------------------------------------- > +const lcd_normal_delay = 3 -- delay in 10 usec units = 30uS > +const lcd_long_delay = 120 -- delay in 10 usec units = 1,2mS > +-- > ----------------------------------------------------------------------------- > +-- > +-- > +-- > + > +-- ---------------------------------------------------------- > +-- Send byte to the LCD as 2 nibbles (most significant nibble first) > +-- and automatically set the cursor one position right. > +-- ---------------------------------------------------------- > +procedure _lcd_write(byte in value) is > + > + lcd_dataport = (value >> 4) > + > + lcd_en = high -- trigger on > + asm nop -- delay (> 400 ns) > + lcd_en = low -- trigger off > + > + lcd_dataport = value -- replace low nibble > + lcd_en = high -- trigger on > + asm nop -- delay (> 400 ns) > + lcd_en = low -- trigger off > + > + delay_10uS(lcd_normal_delay) -- required normal > delay > + > +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 > + > + if value < 4 then -- "clear display' > and 'return home' > + delay_10uS( lcd_long_delay ) -- require extra delay > + end if > + > +end procedure > +-- > ---------------------------------------------------------------------------- > + > + > + > +-- now we defined the interface, add the API > +include lcd_hd44780_common > + > + > +-- > ---------------------------------------------------------------------------- > +-- Initialize display in 1 ans 2 or 3 line, display on, no cursor shown an > cursor > +-- moves to the right. > +-- > ---------------------------------------------------------------------------- > +procedure lcd_init() is > + pragma inline > + delay_1ms( 45 ) -- powerup delay for 45mS > + if LCD_ROWS == 1 then > + _lcd_write_command( 0b_0010_0000 ) -- function 4bit > N=0,5x7dots > + _lcd_write_command( 0b_0010_0001 ) -- function 4bit > N=0,5x7dots > IS1=1 > + _lcd_write_command( 0b_0001_0100 ) -- BIAS 1 and 2 line > setting > + end if > + if LCD_ROWS == 2 then > + _lcd_write_command( 0b_0010_1000 ) -- function 4bit > N=1,5x7dots > + _lcd_write_command( 0b_0010_1001 ) -- function 4bit > N=1,5x7dots > IS1=1 > + _lcd_write_command( 0b_0001_0100 ) -- BIAS 1 and 2 line > setting > + end if > + if LCD_ROWS == 3 then > + _lcd_write_command( 0b_0010_1000 ) -- function 4bit > N=1,5x7dots > + _lcd_write_command( 0b_0010_1001 ) -- function 4bit > N=1,5x7dots > IS1=1 > + _lcd_write_command( 0b_0001_0101 ) -- BIAS 3 line > setting > + end if > + > + _lcd_write_command( 0b_0111_0000 ) -- contrast set > + _lcd_write_command( 0b_0101_1110 ) -- > power/ICON/contrast control > + _lcd_write_command( 0b_0110_1010 ) -- follower control > + delay_1ms( 210 ) -- extra delay to let display > settle > + > + -- init the API > + _hd44780_init() > + > +end procedure > + > + > + > > Added: trunk/include/external/lcd/lcd_dog_m_8.jal > ============================================================================== > --- (empty file) > +++ trunk/include/external/lcd/lcd_dog_m_8.jal Sat Mar 7 12:16:30 2009 > @@ -0,0 +1,180 @@ > +-- ------------------------------------------------------ > +-- Title: control for DOG-M (ST7036 based) LCD's > +-- > +-- Author: Richard Zengerink, Copyright (c) 2008, all rights reserved > +-- Adapted-by: > +-- > +-- Compiler: =2.4 > +-- > +-- This file is part of jallib (http://jallib.googlecode.com) > +-- Released under the ZLIB license > (http://www.opensource.org/licenses/zlib-license.html) > +-- > +-- > +-- > +-- Description: > +-- Simple interface for DOG-M (st7036) alphanumeric LCD screens. > +-- Screens can range from 1x8 (1 lines, 8 chars), 2x16 and 3x16. > +-- Uses 8 bit wide datapath + 2 handshake lines (total 10 PIC pins). > +-- Expects: - 2 pins for handshake: 'lcd_rs' and 'lcd_en' > +-- - 1 port 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 3 lines > +-- const byte LCD_CHARS = 16 -- 8, 16 chars per > line > +-- and variables (aliases): > +-- var byte lcd_dataport is portA -- 8 data pins > +-- var bit lcd_en is pin_b0 -- trigger > +-- var bit lcd_rs is pin_b1 -- 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_direction = all_output > +-- pin_b0_direction = output > +-- pin_b0_direction = output > +-- 4. Call lcd_init() to initialize the lcd controller. > +-- Above is an example for a 2x16 LCD: > +-- portA are is used for data, pins 0 and 1 of portB are > +-- used for handshake. Any other available port and handshake pins > +-- could be used (provided these are configurable for output). > +-- > +-- Available functions for application programs: > +-- > +-- > +-- _lcd_write(<byte>) sends byte from value to > +-- register of the lcd and > +-- shift cursor position 1 > right > +-- > +-- _lcd_write_data(<byte>) write data to lcd using > +-- _lcd_write(<byte>) lcd_rs > high > +-- > +-- _lcd_write_command(<byte>) write command to lcd using > +-- _lcd_write(<byte>) lcd_rs > low > +-- > +-- lcd_init() initialize the LCD > controller > +-- > +-- > +-- Dependencies: delay.jal > +-- > +-- > ----------------------------------------------------------------------------- > + > +-- > +-- Notes: > +-- > +-- this type can be attached to your microcontroller serial with only 3 or > +-- 4 lines in total > +-- example type name: EA DOG-M > http://www.lcd-module.com/products/dog.html > +-- > + > +include delay -- include standard delay lib > +-- > +-- > +-- > +-- > ----------------------------------------------------------------------------- > +-- some constants to control the lcd > +-- > ----------------------------------------------------------------------------- > +const lcd_clear_display = 0b_0000_0001 -- long delay > +const lcd_return_home = 0b_0000_0010 -- long delay > +const lcd_display_onoff = 0b_0000_1000 -- short delay > + > +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 > +const lcd_set_cgram_address = 0b_0100_0000 > +-- > ----------------------------------------------------------------------------- > + > +-- > ----------------------------------------------------------------------------- > +-- delay's necessary for initialisation and some commands > +-- > ----------------------------------------------------------------------------- > +const lcd_normal_delay = 3 -- delay in 10 usec units = 30uS > +const lcd_long_delay = 120 -- delay in 10 usec units = 1,2mS > +-- > ----------------------------------------------------------------------------- > +-- > +-- > +-- ---------------------------------------------------------- > +-- Send byte to the LCD and automatically set the cursor > +-- one position right. > +-- ---------------------------------------------------------- > +procedure _lcd_write(byte in value) is > + lcd_dataport = value -- replace low nibble > + lcd_en = high -- trigger on > + asm nop -- delay (> 400 ns) > + lcd_en = low -- trigger off > + delay_10uS(lcd_normal_delay) -- required normal delay > +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 > + > + if value < 4 then -- "clear display' > and 'return home' > + delay_10uS( lcd_long_delay ) -- require extra > delay > + end if > + > +end procedure > +-- > ---------------------------------------------------------------------------- > + > + > + > +-- now we defined the interface, add the API > +include lcd_hd44780_common > + > + > +-- > ---------------------------------------------------------------------------- > +-- Initialize display in 1 ans 2 or 3 line, display on, no cursor shown an > cursor > +-- moves to the right. > +-- > ---------------------------------------------------------------------------- > +procedure lcd_init() is > + pragma inline > + delay_1ms( 45 ) -- powerup delay for 45mS > + if LCD_ROWS == 1 then > + _lcd_write_command( 0b_0011_0000 ) -- function 8bit > N=0,5x7dots > + _lcd_write_command( 0b_0011_0001 ) -- function 8bit > N=0,5x7dots > IS1=1 > + _lcd_write_command( 0b_0001_0100 ) -- BIAS 1 and 2 line > setting > + end if > + if LCD_ROWS == 2 then > + _lcd_write_command( 0b_0011_1000 ) -- function 8bit > N=1,5x7dots > + _lcd_write_command( 0b_0011_1001 ) -- function 8bit > N=1,5x7dots > IS1=1 > + _lcd_write_command( 0b_0001_0100 ) -- BIAS 1 and 2 line > setting > + end if > + if LCD_ROWS == 3 then > + _lcd_write_command( 0b_0011_1000 ) -- function 8bit > N=1,5x7dots > + _lcd_write_command( 0b_0011_1001 ) -- function 8bit > N=1,5x7dots > IS1=1 > + _lcd_write_command( 0b_0001_0101 ) -- BIAS 3 line > setting > + end if > + > + > + _lcd_write_command( 0b_0111_0000 ) -- contrast set > + _lcd_write_command( 0b_0101_1110 ) -- > power/ICON/contrast control > + _lcd_write_command( 0b_0110_1010 ) -- follower control > + delay_1ms( 210 ) -- extra delay to let display > settle > + > + -- init the API > + _hd44780_init() > + > +end procedure > + > + > + > > Added: trunk/include/external/lcd/lcd_dog_m_spi.jal > ============================================================================== > --- (empty file) > +++ trunk/include/external/lcd/lcd_dog_m_spi.jal Sat Mar 7 12:16:30 > 2009 > @@ -0,0 +1,187 @@ > +-- ------------------------------------------------------ > +-- Title: control for DOG-M (ST7036 based) LCD's > +-- > +-- Author: Richard Zengerink, Copyright (c) 2008, all rights reserved > +-- Adapted-by: > +-- > +-- Compiler: =2.4 > +-- > +-- This file is part of jallib (http://jallib.googlecode.com) > +-- Released under the ZLIB license > (http://www.opensource.org/licenses/zlib-license.html) > +-- > +-- > +-- > +-- Description: > +-- Simple interface for DOG-M (st7036) alphanumeric LCD screens. > +-- Screens can range from 1x8 (1 lines, 8 chars), 2x16 and 3x16. > +-- Uses spi interface SI (data line), CLK (clock) RS (register select) > and > +-- if necesery CSB (chip select) (total 4 PIC pins max.). > +-- Expects: - 1 pin for data: 'lcd_data' > +-- - 1 pin for clock: 'lcd_clk' > +-- - 1 pin for register/data select: 'lcd_rs' > +-- - 1 pin for Chip Select 'lcd_csb' (if necesery, or CSB to > gnd on lcd) > +-- - 1 var bit named not_connected to assign to lcd_csb if > this pin > +-- is connected to ground. > +-- 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 3 lines > +-- const byte LCD_CHARS = 16 -- 8, or 16 chars per > line > +-- and variables (aliases): > +-- var bit not_connected > +-- var bit lcd_data is pin_A0 -- 1 data pin > +-- var bit lcd_clk is pin_A1 -- 1 data pin > +-- var bit lcd_rs is pin_A2 -- 1 data pin > +-- var bit lcd_csb is pin_A3 -- 1 data pin > +-- or if csb is connected to gnd: > +-- var bit lcd_csb is not_connected > + > +-- 2. Include this library. > +-- and somewhere before actually using the lcd: > +-- 3. Set the chosen LCD data and control pins to output: > +-- portA_low_direction = all_output (in above case this is OK) > +-- OR assign each pin seperatly (when not every pin is on the same > port): > +-- pin_A0_direction = output (each pin separately > assigned) > +-- pin_A1_direction = output > +-- pin_b0_direction = output > +-- pin_b1_direction = output > +-- 4. Call lcd_init() to initialize the lcd controller. > +-- Above is an example for a 2x16 LCD: > +-- > +-- Available functions for application programs: > +-- > +-- > +-- _lcd_write(<byte>) ends byte from value to > +-- register of the lcd and > +-- shift cursor position 1 > right > +-- > +-- _lcd_write_data(<byte>) write data to lcd using > +-- _lcd_write(<byte>) lcd_rs > high > +-- > +-- _lcd_write_data(<byte>) write command to lcd using > +-- _lcd_write(<byte>) lcd_rs > low > +-- > +-- lcd_init() initialize the LCD > controller > +-- > +-- > +-- Dependencies: delay.jal > +-- > +-- > ----------------------------------------------------------------------------- > + > +-- > +-- Notes: > +-- > +-- this type can be attached to your microcontroller serial with only 3 or > +-- 4 lines in total > +-- example type name: EA DOG-M > http://www.lcd-module.com/products/dog.html > +-- > +-- > +include delay -- include standard delay lib > +-- > +-- > +-- > +-- > ----------------------------------------------------------------------------- > +-- some constants to control the lcd > +-- > ----------------------------------------------------------------------------- > +const lcd_clear_display = 0b_0000_0001 -- long delay > +const lcd_return_home = 0b_0000_0010 -- long delay > +const lcd_display_onoff = 0b_0000_1000 -- short delay > + > +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 > +const lcd_set_cgram_address = 0b_0100_0000 > +-- > ----------------------------------------------------------------------------- > + > +-- > ----------------------------------------------------------------------------- > +-- delay's necessary for initialisation and some commands > +-- > ----------------------------------------------------------------------------- > +const lcd_normal_delay = 3 -- delay in 10 usec units = 30uS > +const lcd_long_delay = 120 -- delay in 10 usec units = 1,2mS > +-- > ----------------------------------------------------------------------------- > +-- > +-- > +-- > ---------------------------------------------------------------------------- > +-- sends byte from value to register of the lcd > +-- (this procedure is only used inside this file) > +-- > ---------------------------------------------------------------------------- > +procedure _lcd_write(byte in value) is > + pragma inline > + lcd_csb = low -- select lcd (wake him up) > + for 8 loop -- loop for sending serial > information > + var bit bit7 at value : 7 > + lcd_data = bit7 > + lcd_clk = high -- clock the data > + asm nop -- delay (> 400 ns depending > on > your xtal) > + lcd_clk = low > + value = value << 1 -- shift data to MSB > + end loop > + delay_10uS(lcd_normal_delay) -- required normal delay > + lcd_csb = low -- unselect lcd (let him > sleep) > +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 > + > + if value < 4 then -- "clear display' > and 'return home' > + delay_10uS( lcd_long_delay ) -- require extra delay > + end if > + > +end procedure > +-- > ---------------------------------------------------------------------------- > + > + > + > +-- now we defined the interface, add the API > +include lcd_hd44780_common > + > + > +-- > ---------------------------------------------------------------------------- > +-- Initialize display in 1 ans 2 or 3 line, display on, no cursor shown an > cursor > +-- moves to the right. > +-- > ---------------------------------------------------------------------------- > +procedure lcd_init() is > + pragma inline > + delay_1ms( 45 ) -- powerup delay for 45mS > + _lcd_write_command( 0b_0011_0000 ) -- function 8bit > N=1,5x7dots > + _lcd_write_command( 0b_0011_0001 ) -- function 8bit > N=1,5x7dots IS1=1 > + if LCD_ROWS == 3 then > + _lcd_write_command( 0b_0001_0101 ) -- BIAS 3 line > setting > + else > + _lcd_write_command( 0b_0001_0100 ) -- BIAS 1 and 2 line > setting > + end if > + > + _lcd_write_command( 0b_0111_0000 ) -- contrast set > + _lcd_write_command( 0b_0101_1110 ) -- > power/ICON/contrast control > + _lcd_write_command( 0b_0110_1010 ) -- follower control > + delay_1ms( 210 ) -- extra delay to let display > settle > + > + -- 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 -~----------~----~----~----~------~----~------~--~---
