CVS: examples/char_lcd hardware.h,1.1,1.2 lcd.c,1.5,1.6 lcd.h,1.2,1.3 main.c,1.7,1.8
Chris Liechti <[email protected]>
| Newsgroups | gmane.comp.hardware.texas-instruments.msp430.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/mspgcc/examples/char_lcd
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1445/examples/char_lcd
Modified Files:
hardware.h lcd.c lcd.h main.c
Log Message:
- updated lcd library: suuport for 4 line displays
- prefix with underline
- use the real printf impl we have
Index: hardware.h
===================================================================
RCS file: /cvsroot/mspgcc/examples/char_lcd/hardware.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- hardware.h 6 Jul 2002 20:19:05 -0000 1.1
+++ hardware.h 26 Dec 2005 17:33:08 -0000 1.2
@@ -51,4 +51,7 @@
#define TACTL_INIT TASSEL0|TACLR|ID_3 //ACLK, /8
#define ONESECOND 512 //32768/8/16
+// LCD options
+#define LCD_EXTRA
+
#endif //HARDWARE_H
Index: lcd.c
===================================================================
RCS file: /cvsroot/mspgcc/examples/char_lcd/lcd.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -d -r1.5 -r1.6
--- lcd.c 4 Feb 2003 23:45:04 -0000 1.5
+++ lcd.c 26 Dec 2005 17:33:08 -0000 1.6
@@ -53,7 +53,7 @@
LCDOUT = 0; //reset pins
lcdDelay(LCDDELAY1MS*30); //wait more than 30ms
//send the reset sequece (3 times the same pattern)
- LCDOUT = LCD8BITS; //set 8 bit interface
+ LCDOUT = LCD_8BITS; //set 8 bit interface
LCDOUT |= LCD_E; //toggle LCD_E, the enable pin
LCDOUT &= ~LCD_E; //back to inactive position
lcdDelay(LCDDELAY1MS*5); //wait a bit
@@ -64,7 +64,7 @@
LCDOUT &= ~LCD_E; //back to inactive position
lcdDelay(LCDDELAY1MS*5); //wait until instr is finished
- LCDOUT = LCD4BITS; //now set up the 4 bit interface
+ LCDOUT = LCD_4BITS; //now set up the 4 bit interface
LCDOUT |= LCD_E; //toggle LCD_E, the enable pin
LCDOUT &= ~LCD_E; //back to inactive position
lcdBusy(); //wait until instr is finished
@@ -130,6 +130,27 @@
}
/**
+Read one character from the LCD
+*/
+unsigned char lcdGetchar(void)
+{
+ unsigned char c ;
+ LCDDIR = (char)~(LCD_D4|LCD_D5|LCD_D6|LCD_D7); //
+ LCDOUT = LCD_RW|LCD_RS; //read out data
+ //read out the high nibble with the BF flag
+ LCDOUT |= LCD_E; //toggle LCD_E, the enable pin
+ nop();
+ c = (LCDIN & 0xf0);
+ LCDOUT &= ~LCD_E; //back to inactive position
+ //read out the low nibble, ignore it
+ LCDOUT |= LCD_E; //toggle LCD_E, the enable pin
+ c |= (LCDIN & 0xf0) >> 4;
+ LCDOUT &= ~LCD_E; //back to inactive position
+ LCDDIR = LCD_D4|LCD_D5|LCD_D6|LCD_D7|LCD_E|LCD_RW|LCD_RS;
+ return c;
+}
+
+/**
Initialize the display with two lines, cursor hidden and clear
display.
@@ -137,12 +158,37 @@
this function to complete the display setup.
*/
void lcdInit( void ) {
- lcdInstr(LCD2LINES); //set 2 lines display
- lcdInstr(LCDCURSOROFF); //hide cursor
- lcdInstr(LCDCLEAR); //clear display
+ #ifdef LCD_4LINETYPE
+ // select the extension register (set RE bit)
+ lcdInstr(LCD_FUNCTIONSET | LCD_RE_BIT);
+ // set the 4-line display mode
+ lcdInstr(LCD_EXT_FUNCTIONSET | LCD_4LINES);
+ // clear RE bit
+ lcdInstr(LCD_FUNCTIONSET);
+ #else
+ // set the 2-line display mode
+ lcdInstr(LCD_FUNCTIONSET | LCD_2LINES);
+ #endif
+ lcdInstr(LCD_CURSOROFF); //hide cursor
+ lcdInstr(LCD_CLEAR); //clear display
}
/**
+Unspecific delay function (busy wait type).
+this small assembler bit does not need any C init etc. so
+we can use the attribute "naked"
+*/
+__attribute__ ((naked)) void lcdDelay(unsigned int n) {
+ //first arg comes in register R15
+ //the loop uses 3 cycles per round
+ //the eight cycles come from the call overhead and ret
+ //
+ //delay_time = (1/MCLK)*(8+(3*n))
+ asm("lcdloop: dec %0\n jnz lcdloop\n ret" :: "r" (n));
+}
+
+#ifdef LCD_EXTRA
+/**
Write a string in CGRAM or DDRAM of display controller. It uses
NULL terminated strings, whitch is usual in C code.
@@ -159,20 +205,6 @@
}
/**
-Unspecific delay function (busy wait type).
-this small assembler bit does not need any C init etc. so
-we can use the attribute "naked"
-*/
-__attribute__ ((naked)) void lcdDelay(unsigned int n) {
- //first arg comes in register R15
- //the loop uses 3 cycles per round
- //the eight cycles come from the call overhead and ret
- //
- //delay_time = (1/MCLK)*(8+(3*n))
- asm("lcdloop: dec %0\n jnz lcdloop\n ret" :: "r" (n));
-}
-
-/**
Write font data in CGRAM. This function is intended to download the
user definable characters to the display. These are 8 bytes per
characte and our display has eight free programmable characters. This
@@ -223,9 +255,11 @@
*/
void lcdDownloadFont(const void * fontdata, int size) {
int i;
- lcdInstr(LCDCGADRSET);
+ lcdInstr(LCD_CGRAM);
for (i = 0; i<size; i++) {
lcdPutc(((unsigned char *)fontdata)[i]);
}
- lcdInstr(LCDLINE1); //just in case, set cursor to a visible pos
+ lcdInstr(LCD_DDRAM); //just in case, set cursor to a visible pos
}
+
+#endif //LCD_EXTRA
Index: lcd.h
===================================================================
RCS file: /cvsroot/mspgcc/examples/char_lcd/lcd.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -d -r1.2 -r1.3
--- lcd.h 6 Jul 2002 21:08:11 -0000 1.2
+++ lcd.h 26 Dec 2005 17:33:08 -0000 1.3
@@ -11,61 +11,89 @@
<B>IMPORTANT:</B> <code>lcdDelay(LCDDELAY2)</code> must be called after
this instruction because the display contoller needs some additional time.
*/
-#define LCDON 0x01 //0x00000001 //Switch on display
-#define LCDOFF 0x08 //0x00001000 //Switch off display
+#define LCD_ON 0x01 //0x00000001 //Switch on display
+#define LCD_OFF 0x08 //0x00001000 //Switch off display
//#define LCDEMODE 0x06 //0x00000110
//#define LCDFONT 0x21 //0x00100001
-/** Clear the display. As this function is exactly the same as "Switch on display",
-it needs the same precautions:
-IMPORTANT:> lcdDelay(LCDDELAY2) must be called after
-this instruction because the display contoller needs some additional time.
-*/
-#define LCDCLEAR 0x01 //0x00000001
+/** Clear the display. */
+#define LCD_CLEAR 0x01 //0x00000001
/** Place cursor on a specific display line. The horizontal offset
can be added: LCDLINEx + xoffset. As the line length is limited,
the horizontal offset must not be greater 64
*/
-#define LCDLINE1 0x80 //0x10000000
-#define LCDLINE2 0xc0 //0x11000000
+#ifdef LCD_4LINETYPE
+ //~ #message "lcd.h: 4 Line LCD selected"
+ // 4 line display
+ #define LCD_LINE1 0x80 ///< Address offset for 1st line in 4-line display mode
+ #define LCD_LINE2 0xa0 ///< Address offset for 2nd line in 4-line display mode
+ #define LCD_LINE3 0xc0 ///< Address offset for 3rd line in 4-line display mode
+ #define LCD_LINE4 0xe0 ///< Address offset for 4th line in 4-line display mode
+ #define LCD_LINEWIDTH 0x20 ///< Specify the line with in 4-line display mode
+#else // LCD_4LINETYPE
+ //~ #message "lcd.h: 2 Line LCD selected"
+ // 2 line display
+ #define LCD_LINE1 0x80 ///< Address offset for 1st line in 2-line display mode
+ #define LCD_LINE2 0xc0 ///< Address offset for 2nd line in 2-line display mode
+ #define LCD_LINEWIDTH 0x40 ///< Specify the line with in 2-line display mode
+#endif // LCD_4LINETYPE
/** Cursor modes.
*/
-#define LCDCURSORON 0x0f //0x00001111 //turn on cursor blinking
-#define LCDCURSOROFF 0x0c //0x00001100 //Disable cursor blinking. The cursor is hidden.
-
-/** Set address pointer in CGRAM. An offset can be added:
-<code>LCDCGADRSET + offset</code>. As the CGRAM is limited to 64 bytes, the
-offset must not exeed 64.
-*/
-#define LCDCGADRSET 0x40 //0b01000000
+#define LCD_CURSORON 0x0f //0x00001111 //turn on cursor blinking
+#define LCD_CURSOROFF 0x0c //0x00001100 //Disable cursor blinking. The cursor is hidden.
-/** Set address pointer in DDRAM. An offset can be added:
-<code>LCDDDADRSET + offset</code>. As the CGRAM is limited to 128 bytes, the
-offset must not exeed 128.
-For code redability and ease of use the <code>LCDLINEx</code> command should be
-sed!
-*/
-#define LCDDDADRSET 0x80 //0b10000000
/** these are used for the LCD init and module internally
*/
-#define LCD2LINES 0x28 //0b00101000 //Set display mode to two lines.
//Bitpatters for LCDOUT
-#define LCD8BITS 0x30 //0b00110000 //select 8 Bit interface
-#define LCD4BITS 0x20 //0b00100000 //select 4 Bit interface
+#define LCD_8BITS 0x30 //0b00110000 //select 8 Bit interface
+#define LCD_4BITS 0x20 //0b00100000 //select 4 Bit interface
#define LCD_DATA_OFF 0x05 //0x00000101 //mask used to clear the data lines
+//some instructions
+#define LCD_FUNCTIONSET 0x20 ///< LCD function set instruction
+#define LCD_2LINES 0x08 ///< Bitmask for the \c LCD_FUNCTIONSET to set the 2-line display mode
+#define LCD_RE_BIT 0x04 ///< Bitmask for the \c LCD_FUNCTIONSET to select the extension register (set RE bit)
+
+#define LCD_EXT_FUNCTIONSET 0x08 ///< LCD extended function set instruction
+#define LCD_4LINES 0x01 ///< Bitmask for the \c LCD_EXT_FUNCTIONSET to set the 4-line display mode
+
+#define LCD_DISP_CTRL 0x08 ///< LCD ON/OFF control instruction
+#define LCD_DISP_ON 0x04 ///< Bitmask for the \c LCD_DISP_CTRL to turn on the display (visible).
+
+#define LCD_ENTRYMODE 0x04 ///< LCD entry mode set
+#define LCD_INC 0x02 ///< Bitmask for the #LCD_ENTRYMODE to set the cursor moving direction
+
+#define LCD_CLEAR 0x01 /**< Instruction to clear the display.
+ @note This instructions use much more execution time then an other instruction.
+ @warning The data book says not more then 1.53ms but in fact its 2ms.
+ Call <code>lcdDelay(LCD_DELAY_2MS)</code> after using this instruction! */
+
+#define LCD_HOME 0x02 /**< Instruction to set the cursor to the home position.
+ @note This instructions use much more execution time then an other instruction.
+ @warning The data book says not more then 1.53ms but in fact its 2ms.
+ Call <code>lcdDelay(LCD_DELAY_2M)</code> after using this instruction! */
+
+#define LCD_CGRAM 0x40 /**< Set the address pointer in CGRAM. An additionally offset can be added.
+ @note The CGRAM is limited to 64 bytes. The offset can not exeed 64. */
+
+#define LCD_DDRAM 0x80 /**< Set the address pointer in DDRAM. An additionally offset can be added.
+ For direct access to the individual lines use the definitions like #LCD_LINE1.
+ @note The DDRAM is limited to 128 bytes. The offset can not exeed 128. */
+
//forward declarations
void lcdOn( void );
void lcdInstr( char cmd );
void lcdPutc( char c );
void lcdInit( void );
-void lcdPuts( char * str );
void lcdDelay(unsigned int d);
+#ifdef LCD_EXTRA
+void lcdPuts( char * str );
void lcdDownloadFont( const void * fontdata, int size);
+#endif //LCD_EXTRA
#endif /*LCD_H*/
Index: main.c
===================================================================
RCS file: /cvsroot/mspgcc/examples/char_lcd/main.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -d -r1.7 -r1.8
--- main.c 12 Aug 2005 21:16:36 -0000 1.7
+++ main.c 26 Dec 2005 17:33:08 -0000 1.8
@@ -12,10 +12,11 @@
//the font in this array:
extern const char lcdfont[64];
-//redirect stdio looking funcs to LCD
-#define printf(format, args...) uprintf(lcdPutc, format, args)
-#define puts lcdPuts
-#define putc lcdPutc
+//redirect stdio to LCD
+int putchar(int c) {
+ lcdPutc(c);
+ return 1;
+}
//global vars to store the time
int h, m, s;
@@ -80,7 +81,7 @@
puts("Hi, I'm a clock"); //say hello
while (1) { //main loop, never ends...
- lcdInstr(LCDLINE2);
+ lcdInstr(LCD_LINE2);
//show the clock
//as we are synced with the interrupt, its save to read h,m,s
//otherwise a dint..eint around the following line would be
@@ -88,8 +89,8 @@
printf("%02d:%02d:%02d", h, m, s);
//now show the bargraph. it hasn't to do much with a clock
//but we want to show the feature here...
- lcdInstr(LCDLINE2+15);
- putc(i);
+ lcdInstr(LCD_LINE2+15);
+ putchar(i);
if (++i >= 8) i = 0; //lets show all 8 downloadable chars
LPM0; //sync, wakeup by irq
}
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click