00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef LC7981_H_
00032 #define LC7981_H_ LC7981_H_
00033
00034 #include <avr/io.h>
00035 #include <util/delay.h>
00036 #include <avr/pgmspace.h>
00037
00038 #define LCD_CTRL PORTA
00039 #define LCD_CRTL_DDR DDRA
00040 #define LCD_RS PA4
00041 #define LCD_RW PA2
00042 #define LCD_EN PA0
00043
00044
00045
00046 #define LCD_DATA PORTD
00047 #define LCD_DATA_PIN PIND
00048 #define LCD_DATA_DDR DDRD
00049
00050
00051 #define lcd_rs_high() (LCD_CTRL |= (1 << LCD_RS))
00052 #define lcd_rs_low() (LCD_CTRL &= ~(1 << LCD_RS))
00053
00054 #define lcd_rw_high() (LCD_CTRL |= (1 << LCD_RW))
00055 #define lcd_rw_low() (LCD_CTRL &= ~(1 << LCD_RW))
00056
00057 #define lcd_en_high() (LCD_CTRL |= (1 << LCD_EN))
00058 #define lcd_en_low() (LCD_CTRL &= ~(1 << LCD_EN))
00059
00060
00061 #define LCD_TEXT 0
00062 #define LCD_TEXT_LINES 10
00063 #define LCD_TEXT_COLUMNS 26
00064
00065 #define LCD_GRAPHIC 1
00066 #define LCD_GRAPHIC_WIDTH 160
00067 #define LCD_GRAPHIC_HEIGHT 80
00068 #define PIXEL_ON 1
00069 #define PIXEL_OFF 0
00070
00071 void lcd_init(uint8_t mode);
00072 void lcd_clear();
00073
00074 void lcd_write_text(char *txt);
00075 void lcd_gotoxy(uint8_t x, uint8_t y);
00076
00077 void lcd_plot_pixel(uint8_t x, uint8_t y, uint8_t set);
00078 void lcd_plot_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint8_t w, uint8_t h);
00079
00080 void lcd_plot_char(uint8_t x_off, uint8_t y_off, uint8_t c, uint8_t fw, uint8_t fh, PGM_P font);
00081 void lcd_plot_text(uint8_t x_off, uint8_t y_off, const char *text, uint8_t fw, uint8_t fh, PGM_P font);
00082 void lcd_plot_pgmtext(uint8_t x_off, uint8_t y_off, PGM_P text, uint8_t fw, uint8_t fh, PGM_P font);
00083
00084
00085 static inline void lcd_strobe();
00086 static inline void lcd_write_command(uint8_t cmd, uint8_t data);
00087 static inline uint8_t lcd_read_byte();
00088
00089
00090
00091
00092
00097 static inline void lcd_strobe() {
00098 lcd_en_high();
00099 _delay_us(1);
00100 lcd_en_low();
00101
00102 }
00103
00104
00111 static inline void lcd_write_command(uint8_t cmd, uint8_t data) {
00112 _delay_us(30);
00113 lcd_rw_low();
00114 lcd_rs_high();
00115 LCD_DATA = cmd;
00116 _delay_us(1);
00117 lcd_strobe();
00118
00119 lcd_rs_low();
00120 LCD_DATA = data;
00121 _delay_us(1);
00122 lcd_strobe();
00123
00124 }
00125
00134 static inline uint8_t lcd_read_byte() {
00135 uint8_t i,data;
00136
00137 for(i = 0; i < 2; i++) {
00138 _delay_us(30);
00139 lcd_rw_low();
00140 lcd_rs_high();
00141 LCD_DATA = 0x0D;
00142 _delay_us(1);
00143 lcd_en_high();
00144
00145 LCD_DATA_DDR = 0x00;
00146 lcd_rs_low();
00147 lcd_rw_high();
00148 _delay_us(1);
00149 data = (uint8_t) LCD_DATA_PIN;
00150 lcd_en_low();
00151 LCD_DATA_DDR = 0xFF;
00152 }
00153 return data;
00154 }
00155
00156
00157
00158
00159
00160 #endif