hw_lcd.h
Go to the documentation of this file.00001
00042 #ifndef HW_LCD_H
00043 #define HW_LCD_H
00044
00045 #include <appconfig.h>
00046
00047
00048 #include <cpu/attr.h>
00049 #include <cpu/irq.h>
00050 #include <cpu/types.h>
00051
00052 #include <cfg/macros.h>
00053 #include <cfg/debug.h>
00054
00055 #include <avr/io.h>
00056 #include <stdbool.h>
00057 #include <inttypes.h>
00058
00063 #define LCD_RS BV(PG3)
00064 #define LCD_RW BV(PG0)
00065 #define LCD_E BV(PG2)
00066 #define LCD_DB0 BV(PA0)
00067 #define LCD_DB1 BV(PA1)
00068 #define LCD_DB2 BV(PA2)
00069 #define LCD_DB3 BV(PA3)
00070 #define LCD_DB4 BV(PA4)
00071 #define LCD_DB5 BV(PA5)
00072 #define LCD_DB6 BV(PA6)
00073 #define LCD_DB7 BV(PA7)
00074
00080 #define LCD_PORT PORTG
00081 #define LCD_DB_PORT PORTA
00082 #define LCD_PIN PING
00083 #define LCD_DB_PIN PINA
00084 #define LCD_DDR DDRG
00085 #define LCD_DB_DDR DDRA
00086
00087 #if CONFIG_LCD_4BIT
00088 #define LCD_MASK (LCD_DB7 | LCD_DB6 | LCD_DB5 | LCD_DB4)
00089 #define LCD_SHIFT 4
00090 #else
00091 #define LCD_MASK (uint8_t)0xff
00092 #define LCD_SHIFT 0
00093 #endif
00094
00100 #define LCD_CLR_RS (LCD_PORT &= ~LCD_RS)
00101 #define LCD_SET_RS (LCD_PORT |= LCD_RS)
00102 #define LCD_CLR_RD (LCD_PORT &= ~LCD_RW)
00103 #define LCD_SET_RD (LCD_PORT |= LCD_RW)
00104 #define LCD_CLR_E (LCD_PORT &= ~LCD_E)
00105 #define LCD_SET_E (LCD_PORT |= LCD_E)
00106
00107 #if CONFIG_LCD_4BIT
00108 #define LCD_WRITE_H(x) (LCD_DB_PORT = (LCD_DB_PORT & ~LCD_MASK) | (((x) >> (4 - LCD_SHIFT)) & LCD_MASK))
00109 #define LCD_WRITE_L(x) (LCD_DB_PORT = (LCD_DB_PORT & ~LCD_MASK) | (((x) << LCD_SHIFT) & LCD_MASK))
00110 #define LCD_READ_H ((LCD_DB_PIN & LCD_MASK) >> (4 - LCD_SHIFT))
00111 #define LCD_READ_L ((LCD_DB_PIN & LCD_MASK) >> LCD_SHIFT)
00112 #else
00113 #define LCD_WRITE(x) (LCD_DB_PORT = (x))
00114 #define LCD_READ (LCD_DB_PIN)
00115 #endif
00116
00119 #define LCD_DB_OUT (LCD_DB_DDR |= LCD_MASK)
00120
00122 #define LCD_DB_IN (LCD_DB_DDR &= ~LCD_MASK)
00123
00125 #define LCD_DELAY_WRITE \
00126 do { \
00127 NOP; \
00128 NOP; \
00129 NOP; \
00130 NOP; \
00131 NOP; \
00132 } while (0)
00133
00135 #define LCD_DELAY_READ \
00136 do { \
00137 NOP; \
00138 NOP; \
00139 NOP; \
00140 NOP; \
00141 } while (0)
00142
00143
00144 INLINE void lcd_bus_init(void)
00145 {
00146 cpuflags_t flags;
00147 IRQ_SAVE_DISABLE(flags);
00148
00149 LCD_PORT = (LCD_PORT & ~(LCD_E | LCD_RW)) | LCD_RS;
00150 LCD_DDR |= LCD_RS | LCD_RW | LCD_E;
00151
00152
00153
00154
00155
00156 LCD_DB_OUT;
00157
00158
00159 IRQ_RESTORE(flags);
00160 }
00161
00162 #endif