1 1.4 tsutsui /* $NetBSD: hd44780reg.h,v 1.4 2009/08/30 02:07:05 tsutsui Exp $ */ 2 1.1 soren 3 1.1 soren /* 4 1.1 soren * Copyright (c) 2002 Dennis I. Chernoivanov 5 1.1 soren * All rights reserved. 6 1.1 soren * 7 1.1 soren * Redistribution and use in source and binary forms, with or without 8 1.1 soren * modification, are permitted provided that the following conditions 9 1.1 soren * are met: 10 1.1 soren * 1. Redistributions of source code must retain the above copyright 11 1.1 soren * notice, this list of conditions and the following disclaimer. 12 1.1 soren * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 soren * notice, this list of conditions and the following disclaimer in the 14 1.1 soren * documentation and/or other materials provided with the distribution. 15 1.1 soren * 3. The name of the author may not be used to endorse or promote products 16 1.1 soren * derived from this software without specific prior written permission 17 1.1 soren * 18 1.1 soren * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 1.1 soren * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 1.1 soren * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 1.1 soren * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 1.1 soren * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 1.1 soren * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 1.1 soren * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 1.1 soren * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 1.1 soren * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 1.1 soren * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 1.1 soren */ 29 1.1 soren 30 1.1 soren #ifndef _DEV_IC_HD44780REG_H_ 31 1.1 soren #define _DEV_IC_HD44780REG_H_ 32 1.1 soren 33 1.1 soren /* 34 1.1 soren * Register definitions for Hitachi HD44870 style displays 35 1.1 soren */ 36 1.1 soren 37 1.1 soren #define HD_MAX_CHARS 80 38 1.1 soren 39 1.1 soren #define HD_ROW1_ADDR 0x00 40 1.1 soren #define HD_ROW2_ADDR 0x40 41 1.1 soren 42 1.2 joff #define HD_TIMEOUT_LONG 5000 43 1.2 joff #define HD_TIMEOUT_SHORT 100 44 1.2 joff #define HD_TIMEOUT_NORMAL 200 45 1.1 soren 46 1.1 soren #define BUSY_FLAG 0x80 47 1.1 soren 48 1.1 soren /* Bit set helper */ 49 1.1 soren #define bset(cond, bit) ((cond) ? (bit) : 0x00) 50 1.1 soren 51 1.1 soren /* Get 4 most/least significant bits */ 52 1.1 soren #define hi_bits(byte) (((byte) & 0xf0) >> 4) 53 1.1 soren #define lo_bits(byte) ((byte) & 0x0f) 54 1.1 soren 55 1.1 soren /* 56 1.1 soren * 'Initialize by instruction' 8bit=1/0 8-bit/4-bit operation 57 1.1 soren */ 58 1.4 tsutsui #define cmd_init(mode) ((uint8_t)(mode ? 0x3f : 0x03)) 59 1.1 soren 60 1.1 soren /* 61 1.1 soren * 'Clear display' 62 1.1 soren */ 63 1.4 tsutsui #define cmd_clear() ((uint8_t)0x01) 64 1.1 soren 65 1.1 soren /* 66 1.1 soren * 'Return home' 67 1.1 soren */ 68 1.4 tsutsui #define cmd_rethome() ((uint8_t)0x03) 69 1.1 soren 70 1.1 soren /* 71 1.1 soren * 'Entry mode set' id=1/0 increment/decrement 72 1.1 soren * s=1 display shift 73 1.1 soren */ 74 1.1 soren #define cmd_modset(id, s) \ 75 1.4 tsutsui ((uint8_t)(0x04 | bset(id, 0x2) | bset(s, 0x1))) 76 1.1 soren 77 1.1 soren /* 78 1.1 soren * 'Display on/off control' d=1/0 display on/off 79 1.1 soren * c=1/0 cursor on/off 80 1.1 soren * b=1/0 blinking of cursor position on/off 81 1.1 soren */ 82 1.1 soren #define cmd_dispctl(d, c, b) \ 83 1.4 tsutsui ((uint8_t)(0x08 | bset(d, 0x04) | bset(c, 0x02) | bset(b, 0x01))) 84 1.1 soren 85 1.1 soren /* 86 1.1 soren * 'Cursor or display shift' sc=1/0 display shift/cursor move 87 1.1 soren * rl=1/0 shift to the right/left 88 1.1 soren */ 89 1.1 soren #define cmd_shift(sc, rl) \ 90 1.4 tsutsui ((uint8_t)(0x13 | bset(sc, 0x08) | bset(rl, 0x04))) 91 1.1 soren 92 1.1 soren /* 93 1.1 soren * 'Function set' dl=1/0 8 bits/4 bits operation 94 1.1 soren * n=1/0 2 lines/1 line 95 1.1 soren * f=1/0 5x10/5x8 dots font 96 1.1 soren */ 97 1.1 soren #define cmd_funcset(dl, n, f) \ 98 1.4 tsutsui ((uint8_t)(0x23 | bset(dl, 0x10) | bset(n, 0x08) | bset(f, 0x04))) 99 1.1 soren 100 1.1 soren /* 101 1.1 soren * 'Set CGRAM address' 102 1.1 soren */ 103 1.1 soren #define cmd_cgramset(acg) \ 104 1.4 tsutsui ((uint8_t)(0x40 | ((acg) & 0x3f))) 105 1.1 soren 106 1.1 soren /* 107 1.1 soren * 'Set DDRAM address' 108 1.1 soren */ 109 1.1 soren #define cmd_ddramset(add) \ 110 1.4 tsutsui ((uint8_t)(0x80 | ((add) & 0x7f))) 111 1.1 soren 112 1.1 soren #endif /* _DEV_IC_HD44780REG_H_ */ 113