1/* 2 * lcd44780.c 3 * Simple "driver" for a memory-mapped 44780-style LCD display. 4 * 5 * Copyright 2001 Bradley D. LaRonde <brad@ltc.com> 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the 9 * Free Software Foundation; either version 2 of the License, or (at your 10 * option) any later version. 11 * 12 */ 13 14#define LCD44780_COMMAND ((volatile unsigned char *)0xbe020000) 15#define LCD44780_DATA ((volatile unsigned char *)0xbe020001) 16 17#define LCD44780_4BIT_1LINE 0x20 18#define LCD44780_4BIT_2LINE 0x28 19#define LCD44780_8BIT_1LINE 0x30 20#define LCD44780_8BIT_2LINE 0x38 21#define LCD44780_MODE_DEC 0x04 22#define LCD44780_MODE_DEC_SHIFT 0x05 23#define LCD44780_MODE_INC 0x06 24#define LCD44780_MODE_INC_SHIFT 0x07 25#define LCD44780_SCROLL_LEFT 0x18 26#define LCD44780_SCROLL_RIGHT 0x1e 27#define LCD44780_CURSOR_UNDERLINE 0x0e 28#define LCD44780_CURSOR_BLOCK 0x0f 29#define LCD44780_CURSOR_OFF 0x0c 30#define LCD44780_CLEAR 0x01 31#define LCD44780_BLANK 0x08 32#define LCD44780_RESTORE 0x0c // Same as CURSOR_OFF 33#define LCD44780_HOME 0x02 34#define LCD44780_LEFT 0x10 35#define LCD44780_RIGHT 0x14 36 37void lcd44780_wait(void) 38{ 39 int i, j; 40 for(i=0; i < 400; i++) 41 for(j=0; j < 10000; j++); 42} 43 44void lcd44780_command(unsigned char c) 45{ 46 *LCD44780_COMMAND = c; 47 lcd44780_wait(); 48} 49 50void lcd44780_data(unsigned char c) 51{ 52 *LCD44780_DATA = c; 53 lcd44780_wait(); 54} 55 56void lcd44780_puts(const char* s) 57{ 58 int j; 59 int pos = 0; 60 61 lcd44780_command(LCD44780_CLEAR); 62 while(*s) { 63 lcd44780_data(*s); 64 s++; 65 pos++; 66 if (pos == 8) { 67 /* We must write 32 of spaces to get cursor to 2nd line */ 68 for (j=0; j<32; j++) { 69 lcd44780_data(' '); 70 } 71 } 72 if (pos == 16) { 73 /* We have filled all 16 character positions, so stop 74 outputing data */ 75 break; 76 } 77 } 78#ifdef LCD44780_PUTS_PAUSE 79 { 80 int i; 81 82 for(i = 1; i < 2000; i++) 83 lcd44780_wait(); 84 } 85#endif 86} 87 88void lcd44780_init(void) 89{ 90 // The display on the RockHopper is physically a single 91 // 16 char line (two 8 char lines concatenated). bdl 92 lcd44780_command(LCD44780_8BIT_2LINE); 93 lcd44780_command(LCD44780_MODE_INC); 94 lcd44780_command(LCD44780_CURSOR_BLOCK); 95 lcd44780_command(LCD44780_CLEAR); 96} 97