- Main Page
- Files

- File List
- Globals

# include/lc7981.h

Go to the documentation of this file.

    00001 /*
    00002  * lc7981.h
    00003  *
    00004  *  Created on: 01.05.2009
    00005  *      Author: sebastian
    00006  *
    00007  * Version 0.7 beta
    00008  *
    00009  * The contents of this file are subject to the Mozilla Public License
    00010  * Version 1.1 (the "License"); you may not use this file except in
    00011  * compliance with the License. You may obtain a copy of the License at
    00012  * http://www.mozilla.org/MPL/
    00013  *
    00014  * Software distributed under the License is distributed on an "AS IS"
    00015  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
    00016  * License for the specific language governing rights and limitations
    00017  * under the License.
    00018  *
    00019  * The Original Code is Sebastians AVR Library for lc7981.
    00020  *
    00021  * The Initial Developer of the Original Code is Sebastian Schumb (webmaster@sebastians-site.de).
    00022  *
    00023  * Contributor(s): None so far.
    00024  *
    00025  * Any version below 0.6 is still licensed under GPL.
    00026  * The GPLed versions will neither be supported, nor developed any further.
    00027  *
    00028  *                      'Do the thing you want to do and let your spirits guide you through.
    00029  *                      Live a life, worth being remembered.'
    00030  *                      -- Remembered - Firewind --
    00031  */
    00032
    00033
    00034 #ifndef LC7981_H_
    00035 #define LC7981_H_ LC7981_H_
    00036
    00037 #include <avr/io.h>
    00038 #include <util/delay.h>
    00039 #include <avr/pgmspace.h>
    00040
    00041 #define LCD_CTRL        PORTA
    00042 #define LCD_CRTL_DDR    DDRA
    00043 #define LCD_RS                  PA4
    00044 #define LCD_RW                  PA2
    00045 #define LCD_EN                  PA0
    00046
    00047
    00048
    00049 #define LCD_DATA                PORTD
    00050 #define LCD_DATA_PIN    PIND
    00051 #define LCD_DATA_DDR    DDRD
    00052
    00053 // Macros for (un)setting the control pins
    00054 #define lcd_rs_high() (LCD_CTRL |= (1 << LCD_RS))
    00055 #define lcd_rs_low() (LCD_CTRL &= ~(1 << LCD_RS))
    00056
    00057 #define lcd_rw_high() (LCD_CTRL |= (1 << LCD_RW))
    00058 #define lcd_rw_low() (LCD_CTRL &= ~(1 << LCD_RW))
    00059
    00060 #define lcd_en_high() (LCD_CTRL |= (1 << LCD_EN))
    00061 #define lcd_en_low() (LCD_CTRL &= ~(1 << LCD_EN))
    00062
    00063
    00064 #define LCD_TEXT 0
    00065 #define LCD_TEXT_LINES 10
    00066 #define LCD_TEXT_COLUMNS 26
    00067
    00068 #define LCD_GRAPHIC 1
    00069 #define LCD_GRAPHIC_WIDTH 160
    00070 #define LCD_GRAPHIC_HEIGHT 80
    00071 #define PIXEL_ON 1
    00072 #define PIXEL_OFF 0
    00073
    00074 void lcd_init(uint8_t mode);
    00075 void lcd_clear(void);
    00076
    00077 void lcd_write_text(char *txt);
    00078 void lcd_gotoxy(uint8_t x, uint8_t y);
    00079
    00080 void lcd_plot_pixel(uint8_t x, uint8_t y, uint8_t set);
    00081 void lcd_plot_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint8_t w, uint8_t h);
    00082 //void lcd_plot_bitmap(uint8_t x, uint8_t y, PGM_P bitmap, uint8_t w, uint8_t h);
    00083
    00084 void lcd_plot_char(uint8_t x, uint8_t y_off, uint8_t c, uint8_t fw, uint8_t fh, PGM_P font);
    00085 void lcd_plot_text(uint8_t x, uint8_t y_off, const char *text, uint8_t fw, uint8_t fh, PGM_P font);
    00086 void lcd_plot_pgmtext(uint8_t x, uint8_t y_off, PGM_P text, uint8_t fw, uint8_t fh, PGM_P font);
    00087
    00088
    00089 static inline void lcd_strobe(void);
    00090 static inline void lcd_write_command(uint8_t cmd, uint8_t data);
    00091 static inline uint8_t lcd_read_byte(uint16_t pos);
    00092
    00093
    00094 // Static inline functions, that can be used in the library and in the main programm
    00095
    00096
    00101 static inline void lcd_strobe(void) {
    00102         lcd_en_high();
    00103         _delay_us(1);
    00104         lcd_en_low();
    00105
    00106 }
    00107
    00108
    00115 static inline void lcd_write_command(uint8_t cmd, uint8_t data) {
    00116         _delay_us(30);
    00117         lcd_rw_low();
    00118         lcd_rs_high();
    00119         LCD_DATA = cmd;
    00120         _delay_us(1);
    00121         lcd_strobe();
    00122
    00123         lcd_rs_low();
    00124         LCD_DATA = data;
    00125         _delay_us(1);
    00126         lcd_strobe();
    00127
    00128 }
    00129
    00137 static inline uint8_t lcd_read_byte(uint16_t pos) {
    00138 uint8_t i,data;
    00139
    00140         lcd_write_command(0x0A,(uint8_t) pos );
    00141         lcd_write_command(0x0B,(uint8_t) (pos  >> 8));
    00142
    00143         for(i = 0; i < 2; i++) {
    00144                 _delay_us(30);
    00145                 lcd_rw_low();
    00146                 lcd_rs_high();
    00147                 LCD_DATA = 0x0D;
    00148                 _delay_us(1);
    00149                 lcd_en_high();
    00150
    00151                 LCD_DATA_DDR = 0x00;
    00152                 lcd_rs_low();
    00153                 lcd_rw_high();
    00154                 _delay_us(1);
    00155                 data = (uint8_t) LCD_DATA_PIN;
    00156                 lcd_en_low();
    00157                 LCD_DATA_DDR = 0xFF;
    00158         }
    00159         return data;
    00160 }
    00161
    00162 static inline void lcd_write_byte(uint16_t pos,uint8_t byte) {
    00163
    00164         lcd_write_command(0x0A,(uint8_t) pos );
    00165         lcd_write_command(0x0B,(uint8_t) (pos  >> 8));
    00166         lcd_write_command(0x0C,byte);
    00167
    00168
    00169 }
    00170
    00171
    00172
    00173
    00174
    00175 #endif /* LC7981_H_ */