On Sat, Feb 26, 2011 at 1:19 AM, muhd hanafi <[email protected]> wrote:
> > > On Thu, Feb 24, 2011 at 7:08 PM, Rob Hamerling <[email protected]>wrote: > >> >> >> On 2011/02/24 07:05, lalali wrote: >> >>> i would like to know how to use getkey and how to make a program if we >>> want to press key on keypad >>> >> >> Before duplicating things you already know: tell us which sources of info >> you have referenced (tutorials, manuals, samples, etc). >> And what didn't you understand? >> >> Regards, Rob >> >> >> -- >> R. Hamerling, Netherlands --- http://www.robh.nl >> >> >> -- >> 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. >> >> i found this and it tell me if i want to keypad,use "getkey()". > my keypad 4x4 is interfaced with lcd. my friend taught me this code for > lcd: > hd44780="m" --if i want to display "m" on lcd. > thats where i don't understand how to use that "getkey()". if i push number > 1 on keypad and want lcd display number 1,how is the code? > could you teach me? > sorry for bad english :) > -- 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.
-- Title: keyboard, scans 4x4 keybaord and returns 0x00..0x0F is keypressed, 0x10 if none pressed -- Author: Javier MartÃnez, Copyright (c) 2003, all rights reserved. -- Adapted-by: Eur van Andel, [email protected], Joep Suijs, Rob Hamerling -- 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) -- -- Description: This library is used to scan a 4x3 or 4x4 keyboard. -- To use it, you need to define three variables: -- keydrive is the half port (_high or _low) with the cols connected. -- keydrive_direction is the related direction register. -- keyscan is the half port (_high or _low) with the rows connected. -- -- -- Example: -- -- -- var volatile byte keyscan is porta_low -- rows of keyboard -- var volatile byte keydrive is portb_low -- columns of keyboard -- var volatile byte keydrive_direction is portb_low_direction -- include keyboard -- Note: if you don't want keyboard.jal change the direction of your pins, make sure all -- keydrive pins are set to output before you call the library and define: -- var volatile byte keydrive_direction is keydrive -- -- -- The library has two functions to read the keyboard: -- getkey() returns the key pressed. -- getkey_once() returns a pressed key only once (and 'none', 0x10 until the next key is pressed) -- -- -- Hardware setup: connect the keyboard rows to a half port (higher or lower 4 bits of a port) -- and connect the cols to a half port. Put a pull-down resistor (10k - 47k) on each row pin. -- Adaptation: soldering your wires in the right order is a lot harder than you think. -- Make sure you keep the rows and cols together and connect them to right port. -- You could either adapt your wiring to match the default configuration or reconfigure the -- library by defining the next 8 constants before you include keyboard.jal, like: -- const row1 = 0b0000_0100 -- const row2 = 0b0000_0001 -- const row3 = 0b0000_0010 -- const row4 = 0b0000_1000 -- const col1 = 0b0000_1000 -- const col2 = 0b0000_0010 -- const col3 = 0b0000_0100 -- const col4 = 0b0000_0001 -- Connect the keyboard and press the buttons. Adapt the row and column constants so -- pressing the buttons give the right result. -- Note: you need to specify all 8 constants, even when you have a 4x3 keyboard. In -- this case you can specify: -- const col4 = 0b0000_0000 -- -- -- keyboard map (4x4, col4 is left out with 4x3 keyboard) -- -- -- 1 2 3 C row 1 -- 4 5 6 D row 2 -- 7 8 9 E row 3 -- * 0 # F row 4 -- -- -- col 1 2 3 4 -- -- Notes: [RobH] Added a 1 microsecond delay after changing keydrive -- to obtain reliable results with oscillator frequencies -- of 8 MHz and higher -- -- ---------------------------------------------------------------------------- if (defined(row1) == false) then ; use default row/col definition const row1 = 0b0000_0001 const row2 = 0b0000_0010 const row3 = 0b0000_0100 const row4 = 0b0000_1000 const col1 = 0b0000_0001 const col2 = 0b0000_0010 const col3 = 0b0000_0100 const col4 = 0b0000_1000 end if -- ---------------------------------------------------------------------------- -- getkey - return the key pressed (until it is released) -- ---------------------------------------------------------------------------- -- return: 0 .. 9 numeric key pressed 0..9 -- 10 * (or A) -- 11 # (or B) -- 12 .. 15 C, D, E, F -- 16 no key pressed. -- 17 error (more then one key pressed) -- ---------------------------------------------------------------------------- function getkey() return byte is var byte scan0, scan1, scan2, scan3 keydrive_direction = col1 ^ 0x0F keydrive = col1 -- LSB MSB _usec_delay(1) scan0 = keyscan & 0x0F -- active col [1] [4] [7] [A] keydrive_direction = col2 ^ 0x0F keydrive = col2 _usec_delay(1) scan1 = keyscan & 0x0F -- active col [2] [5] [8] [0] keydrive_direction = col3 ^ 0x0F keydrive = col3 _usec_delay(1) scan2 = keyscan & 0x0F -- active col [3] [6] [9] [B] keydrive_direction = col4 ^ 0x0F keydrive = col4 _usec_delay(1) scan3 = keyscan & 0x0F -- active col [F] [E] [D] [C] keydrive_direction = all_input if ( scan3 == 0x00 ) & ( scan2 == 0x00 ) & ( scan1 == 0x00 ) & ( scan0 == 0x00 ) then return 0x10 -- 16 elsif scan0 == row1 then return 0x01 elsif scan0 == row2 then return 0x04 elsif scan0 == row3 then return 0x07 elsif scan0 == row4 then return 0x0A elsif scan1 == row1 then return 0x02 elsif scan1 == row2 then return 0x05 elsif scan1 == row3 then return 0x08 elsif scan1 == row4 then return 0x00 elsif scan2 == row1 then return 0x03 elsif scan2 == row2 then return 0x06 elsif scan2 == row3 then return 0x09 elsif scan2 == row4 then return 0x0B elsif scan3 == row1 then return 0x0F elsif scan3 == row2 then return 0x0E elsif scan3 == row3 then return 0x0D elsif scan3 == row4 then return 0x0C end if return 0x11 -- 17 -- error end function var byte lastkey = 0xff -- ---------------------------------------------------------------------------- -- getkey_once - return the value of a key pressed only once -- ---------------------------------------------------------------------------- -- returns: see getkey() -- ---------------------------------------------------------------------------- function getkey_once() return byte is var byte key = getkey() if (key == lastkey) then return 0x10 end if lastkey = key return key end function
