/*-------------------------------------------------------------------------- * LCD routines based on HD44780U standard * Texas Intruments MSC12xx MCU family chips * * Written By - Philippe Latu / philippe.latu(at)linux-france.org * $Id: lcd_msc1210.h 1126 2007-05-06 21:58:55Z latu $ * * Copyright (C) 2007 Philippe Latu * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNES0S FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * *---------------------------------------------------------------------------*/ #ifndef __LCD_MSC1210_H #define __LCD_MSC1210_H // Device addressing // Addresses are hardware dependant and should be changed to fit // hardware requirements sbit at 0xb6 LCD_READ_WRITE; sbit at 0xb5 LCD_REGISTER_SELECT; sbit at 0xb7 LCD_ENABLE; sfr at 0x80 LCD_DATA; // Device commands // Commands defined from HD44780U standard #define LCD_CLEAR_CMD 0x01 #define LCD_HOME_CMD 0x02 #define LCD_ON_CMD 0x0c #define LCD_SHIFT_CMD 0x10 #define LCD_CONFIG_CMD 0x38 // Cursor positionning // starting from 0,0 #define LCD_DSPL_WIDTH 0x14 #define LCD_DSPL_HEIGHT 0x04 #define LCD_ADDR_OFFSET 0x40 #define lcd_set_xy(x, y) (lcd_command( ( (y%LCD_DSPL_HEIGHT == 0) || (y%LCD_DSPL_HEIGHT == 2) ? (y%LCD_DSPL_HEIGHT/2 * LCD_DSPL_WIDTH + x%LCD_DSPL_WIDTH) : ((y%LCD_DSPL_HEIGHT-1)/2 * LCD_DSPL_WIDTH + LCD_ADDR_OFFSET + x%LCD_DSPL_WIDTH) ) | 0x80)) // Display selection boolean parameter // print2lcd = 0: serial line // print2lcd = 1: LCD bit print2lcd = 0; void lcd_busy(void) { do { LCD_ENABLE = 0; // start LCD_REGISTER_SELECT = 0; // command mode LCD_READ_WRITE = 1; // read LCD_DATA = 0xff; // every data bits to 1 LCD_ENABLE = 1; // send } while (LCD_DATA & 0x80); // get LCD status LCD_ENABLE = 0; // cleanup before leaving LCD_READ_WRITE = 0; } void lcd_command(unsigned char cmd) { lcd_busy(); LCD_ENABLE = 0; // start LCD_REGISTER_SELECT = 0; // command mode LCD_READ_WRITE = 0; // write LCD_DATA = cmd; // instruction LCD_ENABLE = 1; // send LCD_ENABLE = 0; // cleanup before leaving } void lcd_putc(unsigned char c) { lcd_busy(); LCD_ENABLE = 0; // start LCD_REGISTER_SELECT = 1; // data mode LCD_READ_WRITE = 0; // write LCD_DATA = c; // character to display LCD_ENABLE = 1; // send LCD_ENABLE = 0; // cleanup before leaving } void lcd_init(void) { lcd_command(LCD_CONFIG_CMD); lcd_command(LCD_ON_CMD); lcd_command(LCD_SHIFT_CMD); } void lcd_clear(void) { lcd_command(LCD_CLEAR_CMD); } void lcd_home(void) { lcd_command(LCD_HOME_CMD); } #endif