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