⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lad_pad.h

📁 Linux嵌入式设计配套光盘,学习嵌入式设计可参考
💻 H
字号:
/* * An LCD/keypad interface. * * The book "Linux Appliance Design" describes a simple LCD and * keypad interface.  This file documents the defines and the * API of that interface. * * Copyright (c) 2005,2006 by Laddie Group, Inc * *//*************************************************************************** * LICENSE: * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * 3. The name of the author may not be used to endorse or promote *    products derived from this software without specific prior *    written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. ***************************************************************************/#ifndef LADPAD_H#define LADPAD_H/* CONTENTS: - Overview - Hardware - Installation - Usage - Defines *//* -OVERVIEWThe book "Linux Appliance Design" includes a sample appliance,called "Laddie".  The sample appliance is an alarm system thatuses the five input pins on a parallel port as inputs from thealarm system hardware.  The sample appliance includes a webinterface, a command line interface, a framebuffer and LIRCinterface, a MIB and SNMP agent, and a LCD/keypad interface.This file describes the LCD/keypad interface by describing itshardware, installation, usage, and API.*//* -HARDWAREThe Laddie appliance is an alarm system with a remote stationthat allows a user to enable or disable the alarm system.  This"remote station" has a two line display, a sixteen button keypad,and an LED.  This section briefly describes the hardware for theremote station.  Please see http://www.linuxappliancedesign.comfor the full schematics or, better, buy the book.The hardware can be thought of as having three sections, twooutput sections and one input section.  The ouput sections arethe two line alphanumeric display and the LED.  The input sectionis the 16 button keypad.  We use a standard parallel port forall IO to the device.  The LCD display uses an HD44780 compatible controller.  This isby far the most widely used text LCD controller and the code givenhere should port easily to any 44780 based device.  A completedescription of these types of displays is beyond the scope of thisdocument and the interested reader is referred to the followingweb sites for more information:   http://www.myke.com/lcd.htm   http://home.iae.nl/users/pouweha/lcd/lcd.shtml*//* -INSTALLATIONYou must build the ladpad module and to do this you should havethe Linux kernel source code installed on your development system.Download the ladpad module source code from the LAD web site andinstall in your /usr/src/linux (or equivalent) directory.  Build and install the module with:   cd /usr/src/linux   tar -xzf ladpad.tgz   cd ladpad   makeThe major number is assigned automatically.  Look in /proc/devicesfor the number assigned.   LADPAD_MAJOR=`grep ladpad /proc/devices | awk '{print $1}'`   mknod /dev/ladpad c $LADPAD_MAJOR 0You may wish to place the above lines in your rc.local file.After you have installed the ladpad module and created the ladpaddevice you can read from its keypad and write to its LCD and LED.Verify that keypad is connected and working with the followingcommand:   cat /dev/ladpadKeys pressed on the keypad should be displayed in your terminalwindow.Verify that output to the display is working with the followingcommand:   echo -n "Hello World" > /dev/ladpadVerify that the LED is working with the following:   echo -ne '\021' >/dev/ladpad    echo -ne '\003' >/dev/ladpad *//* -USAGEInput from the kepad is straighforward.  Reading from the devicewill block until the user presses a key.  When a key is presses,the device driver will return the ASCII value of the key pressed.You can use either blocking reads or a select statement to waitfor key presses.Output to the LCD is a little more complicated in that the 44780type of displays have a command set that allows defining the fontfor custom characters and allows cursor positioning.  You cantransparently send commands to the LCD by prepending the commandwith an escape character.CHARACTER  RESPONSEprintable  Puts the character on the display at the current cursor           location.  The cursor is then shifted one position to            the right.  You can override the "shift right" default           by sending the appropriate command to the LCD.0x10       Escape character for LCD commands.  The next byte read is           sent to the LCD display as a command.  For example, the           two byte sequence to move the cursor to the beginning of           the first line is: 0x10, 0x80.  To move to the beginning           of the second line: 0x10, 0xC0.  Any 8 bit pattern can be           used in the second byte, and the data is transparently           delivered to the LCD as a command.  You can use this            escape mechanism to define custom characters if you wish.0x11       Escape character for LED control.  The next byte read            has the desired state of the LED.  Zero is off, 0xFF is           on steady, and any other value is the number of jiffies           between transitions.*//* -DEFINES*/#define LADPAD_CMD  ((char) 0x10)#define LADPAD_LED  ((char) 0x11)#endif  /* LADPAD_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -