4 * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 2001 Bernardo Innocenti <bernie@codewiz.org>
6 * This file is part of DevLib - See README.devlib for information.
11 * \author Bernardo Innocenti <bernie@develer.com>
12 * \author Stefano Fedrigo <aleph@develer.com>
14 * \brief LCD low-level hardware macros
19 *#* Revision 1.1 2006/09/20 17:39:24 marco
20 *#* Low level lcd for avr.
27 #include <appconfig.h>
31 #include <cfg/macros.h> /* BV() */
32 #include <cfg/debug.h>
39 * \name LCD I/O pins/ports
42 #define LCD_RS BV(PG3)
43 #define LCD_RW BV(PG0)
45 #define LCD_DB0 BV(PA0)
46 #define LCD_DB1 BV(PA1)
47 #define LCD_DB2 BV(PA2)
48 #define LCD_DB3 BV(PA3)
49 #define LCD_DB4 BV(PA4)
50 #define LCD_DB5 BV(PA5)
51 #define LCD_DB6 BV(PA6)
52 #define LCD_DB7 BV(PA7)
56 * \name DB high nibble (DB[4-7])
59 #define LCD_PORT PORTG
60 #define LCD_DB_PORT PORTA
62 #define LCD_DB_PIN PINA
64 #define LCD_DB_DDR DDRA
67 #define LCD_MASK (LCD_DB7 | LCD_DB6 | LCD_DB5 | LCD_DB4)
70 #define LCD_MASK (uint8_t)0xff
76 * \name LCD bus control macros
79 #define LCD_CLR_RS (LCD_PORT &= ~LCD_RS)
80 #define LCD_SET_RS (LCD_PORT |= LCD_RS)
81 #define LCD_CLR_RD (LCD_PORT &= ~LCD_RW)
82 #define LCD_SET_RD (LCD_PORT |= LCD_RW)
83 #define LCD_CLR_E (LCD_PORT &= ~LCD_E)
84 #define LCD_SET_E (LCD_PORT |= LCD_E)
87 #define LCD_WRITE_H(x) (LCD_DB_PORT = (LCD_DB_PORT & ~LCD_MASK) | (((x) >> (4 - LCD_SHIFT)) & LCD_MASK))
88 #define LCD_WRITE_L(x) (LCD_DB_PORT = (LCD_DB_PORT & ~LCD_MASK) | (((x) << LCD_SHIFT) & LCD_MASK))
89 #define LCD_READ_H ((LCD_DB_PIN & LCD_MASK) >> (4 - LCD_SHIFT))
90 #define LCD_READ_L ((LCD_DB_PIN & LCD_MASK) >> LCD_SHIFT)
92 #define LCD_WRITE(x) (LCD_DB_PORT = (x))
93 #define LCD_READ (LCD_DB_PIN)
97 /** Set data bus direction to output (write to display) */
98 #define LCD_DB_OUT (LCD_DB_DDR |= LCD_MASK)
100 /** Set data bus direction to input (read from display) */
101 #define LCD_DB_IN (LCD_DB_DDR &= ~LCD_MASK)
103 /** Delay for write (Enable pulse width, 220ns) */
104 #define LCD_DELAY_WRITE \
113 /** Delay for read (Data ouput delay time, 120ns) */
114 #define LCD_DELAY_READ \
123 INLINE void lcd_bus_init(void)
126 IRQ_SAVE_DISABLE(flags);
128 LCD_PORT = (LCD_PORT & ~(LCD_E | LCD_RW)) | LCD_RS;
129 LCD_DDR |= LCD_RS | LCD_RW | LCD_E;
132 * Data bus is in output state most of the time:
133 * LCD r/w functions assume it is left in output state
141 #endif /* HW_LCD_H */