Author: jsuijs
Date: Sun Mar 29 07:31:29 2009
New Revision: 894
Added:
trunk/test/external/lcd/tst_backlight.jal
Modified:
trunk/include/external/lcd/lcd_backlight.jal
trunk/test/board/board_16f88_sl.jal
trunk/test/external/lcd/test_backlight.jal
Log:
backlight cleanup, proper testfile (for sample generation) added. Afaik,
backlight is done now (remote backlight for serial_lcd is next).
Modified: trunk/include/external/lcd/lcd_backlight.jal
==============================================================================
--- trunk/include/external/lcd/lcd_backlight.jal (original)
+++ trunk/include/external/lcd/lcd_backlight.jal Sun Mar 29 07:31:29 2009
@@ -8,7 +8,23 @@
-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
--
-- Description:
--- Provides standard interface to backlight of (directly connected) lcd.
+-- Provides standard interface to backlight of (directly connected) lcd.
+-- First, setup the pin for the backlight:
+-- var volatile bit lcd_bl is pin_b0
+-- pin_b0_direction = output
+-- --
+-- If the backlight line is inverted (that is low output turn the
backlight on),
+-- you must define:
+-- const bit lcd_bl_inverted = true
+-- --
+-- If you want digital backlight (on or off), then you can include this
library.
+-- But if you want variable backlight (256 steps from off to on), the pin
above
+-- must be a pwm (ccp) output pin. And you have to tell the library, which
pwm:
+-- const byte lcd_backlight_pwm = 1
+-- --
+-- now include the library & init it:
+-- include lcd_backlight
+-- pwm_backlight_init()
--
-- Sources:
--
@@ -22,39 +38,47 @@
end if
--- setup
+--
----------------------------------------------------------------------------
+-- conditional compile for backlight_variable procedures
+--
----------------------------------------------------------------------------
if (defined(lcd_backlight_pwm) == true) then
- -- backlight pwm
+
+ -- backlight pwm is requested
include pwm_hardware
if (lcd_backlight_pwm == 1) then
--
----------------------------------------------------------------------
-- pwm on ccp1
- pin_ccp1_direction = output
- pwm_max_resolution(1)
- pwm1_on()
-
- --
----------------------------------------------------------------------------
- -- lcd_backlight_variable - set backlight level
- --
----------------------------------------------------------------------------
- procedure lcd_backlight_variable(byte in value) is
- pragma inline
- if (lcd_bl_inverted == false) then
- pwm1_set_dutycycle(value)
- else
- pwm1_set_dutycycle(255 - value)
- end if
+ ;pin_ccp1_direction = output
+ procedure pwm_backlight_init() is
+ pwm_max_resolution(1)
+ pwm1_on()
end procedure
- --
----------------------------------------------------------------------
+
+ -- next procedure is unindented to have the definition included into
the documentation
+--
----------------------------------------------------------------------------
+-- lcd_backlight_variable - set backlight level (0 =off, 255 = max on)
+--
----------------------------------------------------------------------------
+procedure lcd_backlight_variable(byte in value) is
+ pragma inline
+ if (lcd_bl_inverted == false) then
+ pwm1_set_dutycycle(value)
+ else
+ pwm1_set_dutycycle(255 - value)
+ end if
+end procedure
+-- ----------------------------------------------------------------------
+ -- end of unindented part
elsif (lcd_backlight_pwm == 2) then
--
----------------------------------------------------------------------
-- pwm on ccp2
- pin_ccp2_direction = output
- pwm_max_resolution(1)
- pwm2_on()
+ procedure pwm_backlight_init() is
+ pwm_max_resolution(1)
+ pwm2_on()
+ end procedure
procedure lcd_backlight_variable(byte in value) is
pragma inline
@@ -70,9 +94,10 @@
--
----------------------------------------------------------------------
-- pwm on ccp3
- pin_ccp3_direction = output
- pwm_max_resolution(1)
- pwm3_on()
+ procedure pwm_backlight_init() is
+ pwm_max_resolution(1)
+ pwm3_on()
+ end procedure
procedure lcd_backlight_variable(byte in value) is
pragma inline
@@ -88,9 +113,10 @@
--
----------------------------------------------------------------------
-- pwm on ccp4
- pin_ccp4_direction = output
- pwm_max_resolution(1)
- pwm4_on()
+ procedure pwm_backlight_init() is
+ pwm_max_resolution(1)
+ pwm4_on()
+ end procedure
procedure lcd_backlight_variable(byte in value) is
pragma inline
@@ -106,9 +132,10 @@
--
----------------------------------------------------------------------
-- pwm on ccp5
- pin_ccp5_direction = output
- pwm_max_resolution(1)
- pwm5_on()
+ procedure pwm_backlight_init() is
+ pwm_max_resolution(1)
+ pwm5_on()
+ end procedure
procedure lcd_backlight_variable(byte in value) is
pragma inline
@@ -125,9 +152,20 @@
end if
+if (defined(pwm_backlight_init) == false) then
+
+ -- next procedure is unindented to have the definition included into
the documentation
+--
----------------------------------------------------------------------------
+-- pwm_backlight_init - init backlight functions
+--
----------------------------------------------------------------------------
+procedure pwm_backlight_init() is
+ -- this procedure is empty for digital backlight
+ -- (the user must set the bl pin as output)
+ -- the procedure is provided for compatibility with variable backlight
+end procedure
+ -- end of unindented part
+end if
-;procedure lcd_backlight_variable(byte in value) is
-;end procedure
--
----------------------------------------------------------------------------
-- lcd_backlight - turn backlite on/off
@@ -146,7 +184,7 @@
if(defined(lcd_bl) == true) then
-- backlight pin exists
if (lcd_bl_inverted == true) then
- -- lcd_bl_inverted exists & is true
+ -- lcd_bl_inverted is true
lcd_bl = ! onoff
return
end if
Modified: trunk/test/board/board_16f88_sl.jal
==============================================================================
--- trunk/test/board/board_16f88_sl.jal (original)
+++ trunk/test/board/board_16f88_sl.jal Sun Mar 29 07:31:29 2009
@@ -63,7 +63,11 @@
var byte lcd_dataport is porta_low -- LCD data port
var byte lcd_dataport_direction is porta_low_direction
const byte LCD_ROWS = 4 -- 4 lines
-const byte LCD_CHARS = 20 -- 20 chars per line
+const byte LCD_CHARS = 20 -- 20 chars per line
+
+-- backlight control (can be variable and digital on this pin)
+var volatile bit lcd_bl is pin_b0
+var volatile bit lcd_bl_direction is pin_b0_direction
;@jallib section i2c
-- I2C io definition
Modified: trunk/test/external/lcd/test_backlight.jal
==============================================================================
--- trunk/test/external/lcd/test_backlight.jal (original)
+++ trunk/test/external/lcd/test_backlight.jal Sun Mar 29 07:31:29 2009
@@ -1,5 +1,5 @@
-- ------------------------------------------------------
--- Title: Test program for lcd_backlight test (extended test)
+-- Title: Test program for lcd_backlight test (basic test)
--
-- Author: Joep Suijs, Copyright (c) 2008..2008, all rights reserved.
--
@@ -10,9 +10,7 @@
-- This file is part of jallib (http://jallib.googlecode.com)
-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
--
--- Description: Testing lcd_hd44780_4 and lcd_hd44780_common
--- This is to test all hd44780_common features. See test_lcd_*
--- for a basic display test.
+-- Description: Testing lcd_backlight
-- --
-- This file defines a test for JALLIB testing, using a test-board
-- defined by a BOARD file .
@@ -20,7 +18,7 @@
-- Sources:
--
-- Notes:
--- setup: an hd44780 compatible display, used in 4-bit mode.
+-- setup: A hd44780 compatible display, used in 4-bit mode with backlight
--
-- ------------------------------------------------------
@@ -30,11 +28,6 @@
;@jallib use lcd_hd44780_4
;@jallib use led
---
----------------------------------------------------------------------------
--- optionally include this file to gain access to the tc_var* variables
---
----------------------------------------------------------------------------
-include serial_tc_header
-
-- setup libs, io etc
lcd_rs_direction = output
lcd_en_direction = output
@@ -45,64 +38,47 @@
include delay
lcd_init() -- initialize LCD
-var byte value = 0
-
lcd_clear_screen()
lcd_home()
-const byte teststring[] = "Serial TC ready."
+const byte teststring[] = "Backlight test."
print_string(lcd, teststring)
+
+const byte lcd_backlight_pwm = 1 -- by selecting the pwm pin,
lcd_backlight_variable() is enabled.
+lcd_bl_direction = output
+;const bit lcd_bl_inverted = true -- define this when pin low turns
backlight on
-const byte lcd_backlight_pwm = 6
-
--- setup for digital backlight control
-var volatile bit lcd_bl is pin_b0
-pin_b0_direction = output
-;const bit lcd_bl_inverted = true
+-- include & init backlight lib
include lcd_backlight
+pwm_backlight_init()
-
-
---
-----------------------------------------------------------------------------
--- Define all unit tests required
--- (testname string constants are optional)
---
-----------------------------------------------------------------------------
-
--- test support function
-var byte testchar = "a"
-procedure increment_testchar() is
- testchar = testchar + 1;
- if (testchar > "z") then
- testchar = "a"
- end if
-end procedure
--- test support function end
-
-const byte testname_a[] = "backlight on"
-procedure unit_test_a() is
- lcd_backlight(on)
-end procedure
-
-const byte testname_b[] = "backlight off"
-procedure unit_test_b() is
+var byte i
+forever loop
+
+ -- set backlight off for two seconds
lcd_backlight(off)
-end procedure
-
-const byte testname_c[] = "backlight 50%"
-procedure unit_test_c() is
- lcd_backlight_variable(128)
-end procedure
-
---
-----------------------------------------------------------------------------
---
-----------------------------------------------------------------------------
--- include testconsole after definition of unit tests
---
-----------------------------------------------------------------------------
---
-----------------------------------------------------------------------------
-include serial_testconsole
-testconsole_init()
-
-tc_var2 = 1 -- default (used for left/right shift)
-
-testconsole() -- contains forever loop
-
+ delay_100ms(20)
+ -- set backlight on for two seconds
+ lcd_backlight(on)
+ delay_100ms(20)
+
+ if(defined(lcd_backlight_pwm) == true) then
+
+ -- we have variable backlight!
+
+ -- first increase intensity
+ for 255 using i loop
+ lcd_backlight_variable(i)
+ delay_1ms(10)
+ end loop
+
+ -- and decrease intensity
+ for 255 using i loop
+ lcd_backlight_variable(255-i)
+ delay_1ms(10)
+ end loop
+
+ end if
+
+end loop
Added: trunk/test/external/lcd/tst_backlight.jal
==============================================================================
--- (empty file)
+++ trunk/test/external/lcd/tst_backlight.jal Sun Mar 29 07:31:29 2009
@@ -0,0 +1,121 @@
+-- ------------------------------------------------------
+-- Title: Test program for lcd_backlight test (extended test)
+--
+-- Author: Joep Suijs, Copyright (c) 2008..2008, all rights reserved.
+--
+-- Adapted-by:
+--
+-- Compiler: >=2.4g
+--
+-- This file is part of jallib (http://jallib.googlecode.com)
+-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
+--
+-- Description: Testing lcd_backlight
+-- --
+-- This file defines a test for JALLIB testing, using a test-board
+-- defined by a BOARD file .
+--
+-- Sources:
+--
+-- Notes:
+-- setup: A hd44780 compatible display, used in 4-bit mode with
+-- backlight and a serial connection to trigger the tests.
+--
+-- ------------------------------------------------------
+
+enable_digital_io() -- disable analog I/O (if any)
+
+;@jallib use chipdef
+;@jallib use lcd_hd44780_4
+;@jallib use led
+
+--
----------------------------------------------------------------------------
+-- optionally include this file to gain access to the tc_var* variables
+--
----------------------------------------------------------------------------
+include serial_tc_header
+
+-- setup libs, io etc
+lcd_rs_direction = output
+lcd_en_direction = output
+lcd_dataport_direction = output
+
+include print
+include lcd_hd44780_4
+include delay
+lcd_init() -- initialize LCD
+
+var byte value = 0
+
+lcd_clear_screen()
+lcd_home()
+
+const byte teststring[] = "Serial TC ready."
+print_string(lcd, teststring)
+
+const byte lcd_backlight_pwm = 1 -- by selecting the pwm pin,
lcd_backlight_variable() is enabled.
+lcd_bl_direction = output
+;const bit lcd_bl_inverted = true -- define this when pin low turns
backlight on
+
+-- include & init backlight lib
+include lcd_backlight
+pwm_backlight_init()
+
+
+--
-----------------------------------------------------------------------------
+-- Define all unit tests required
+-- (testname string constants are optional)
+--
-----------------------------------------------------------------------------
+
+-- test support function
+var byte testchar = "a"
+procedure increment_testchar() is
+ testchar = testchar + 1;
+ if (testchar > "z") then
+ testchar = "a"
+ end if
+end procedure
+-- test support function end
+
+const byte testname_a[] = "backlight on"
+procedure unit_test_a() is
+ lcd_backlight(on)
+end procedure
+
+const byte testname_b[] = "backlight off"
+procedure unit_test_b() is
+ lcd_backlight(off)
+end procedure
+
+
+if(defined(lcd_backlight_pwm) == true) then
+
+const byte testname_c[] = "backlight 25%"
+procedure unit_test_c() is
+ lcd_backlight_variable(64)
+end procedure
+
+const byte testname_d[] = "backlight 50%"
+procedure unit_test_d() is
+ lcd_backlight_variable(128)
+end procedure
+
+const byte testname_e[] = "backlight 75%"
+procedure unit_test_e() is
+ lcd_backlight_variable(128+64)
+end procedure
+
+end if -- defined lcd_backlight_pwm
+
+--
-----------------------------------------------------------------------------
+--
-----------------------------------------------------------------------------
+-- include testconsole after definition of unit tests
+--
-----------------------------------------------------------------------------
+--
-----------------------------------------------------------------------------
+include serial_testconsole
+testconsole_init()
+
+tc_var2 = 1 -- default (used for left/right shift)
+
+testconsole() -- contains forever loop
+
+
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---