Home | History | Annotate | Line # | Download | only in ic
      1 /* $NetBSD: hd44780reg.h,v 1.4 2009/08/30 02:07:05 tsutsui Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2002 Dennis I. Chernoivanov
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     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
     17  *
     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.
     28  */
     29 
     30 #ifndef _DEV_IC_HD44780REG_H_
     31 #define _DEV_IC_HD44780REG_H_
     32 
     33 /*
     34  * Register definitions for Hitachi HD44870 style displays
     35  */
     36 
     37 #define HD_MAX_CHARS	80
     38 
     39 #define HD_ROW1_ADDR	0x00
     40 #define HD_ROW2_ADDR	0x40
     41 
     42 #define HD_TIMEOUT_LONG	5000
     43 #define HD_TIMEOUT_SHORT	100
     44 #define HD_TIMEOUT_NORMAL	200
     45 
     46 #define	BUSY_FLAG	0x80
     47 
     48 /* Bit set helper */
     49 #define bset(cond, bit)	((cond) ? (bit) : 0x00)
     50 
     51 /* Get 4 most/least significant bits */
     52 #define hi_bits(byte)	(((byte) & 0xf0) >> 4)
     53 #define lo_bits(byte)	((byte) & 0x0f)
     54 
     55 /*
     56  * 'Initialize by instruction'	8bit=1/0 8-bit/4-bit operation
     57  */
     58 #define cmd_init(mode)	((uint8_t)(mode ? 0x3f : 0x03))
     59 
     60 /*
     61  * 'Clear display'
     62  */
     63 #define cmd_clear()	((uint8_t)0x01)
     64 
     65 /*
     66  * 'Return home'
     67  */
     68 #define cmd_rethome()	((uint8_t)0x03)
     69 
     70 /*
     71  * 'Entry mode set'		id=1/0 increment/decrement
     72  * 				s=1  display shift
     73  */
     74 #define cmd_modset(id, s) \
     75 	((uint8_t)(0x04 | bset(id, 0x2) | bset(s, 0x1)))
     76 
     77 /*
     78  * 'Display on/off control'	d=1/0 display on/off
     79  * 				c=1/0 cursor on/off
     80  * 				b=1/0 blinking of cursor position on/off
     81  */
     82 #define cmd_dispctl(d, c, b) \
     83 	((uint8_t)(0x08 | bset(d, 0x04) | bset(c, 0x02) | bset(b, 0x01)))
     84 
     85 /*
     86  * 'Cursor or display shift'	sc=1/0 display shift/cursor move
     87  * 				rl=1/0 shift to the right/left
     88  */
     89 #define cmd_shift(sc, rl) \
     90 	((uint8_t)(0x13 | bset(sc, 0x08) | bset(rl, 0x04)))
     91 
     92 /*
     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
     96  */
     97 #define cmd_funcset(dl, n, f) \
     98 	 ((uint8_t)(0x23 | bset(dl, 0x10) | bset(n, 0x08) | bset(f, 0x04)))
     99 
    100 /*
    101  * 'Set CGRAM address'
    102  */
    103 #define cmd_cgramset(acg) \
    104 	((uint8_t)(0x40 | ((acg) & 0x3f)))
    105 
    106 /*
    107  * 'Set DDRAM address'
    108  */
    109 #define cmd_ddramset(add) \
    110 	((uint8_t)(0x80 | ((add) & 0x7f)))
    111 
    112 #endif /* _DEV_IC_HD44780REG_H_ */
    113