Convenience routines for an I"C connected LCD display. Handy things like taking cursor to home, positioning cursor, clearing display, writing strings etc

Dependents:   gu_squirt_tester

Revision:
2:5b220477045b
Parent:
1:2ded47079af1
Child:
3:5744bf6006e1
diff -r 2ded47079af1 -r 5b220477045b jtlcd.cpp
--- a/jtlcd.cpp	Wed Nov 07 22:23:13 2012 +0000
+++ b/jtlcd.cpp	Thu Nov 08 06:12:34 2012 +0000
@@ -1,8 +1,226 @@
 #include "mbed.h"
 #include "jtlcd.h"
+#include "stdarg.h"
+#include "stdio.h"
+#define LCDCONTROL 0x00
+#define LCDDATA 0x40
+
+#define LCDBOTTOMSTART  0x40    /* start address of bottom line */
+#define LCDTOPSTART 0x00    /* start address of top line    */
 
 I2C i2c(p28, p27);        // sda, scl
-void lcdinit()
+
+
+/*==============================================================*/
+/* LcdGetAddress                        */
+/*==============================================================*/
+/*
+int LcdGetAddress(void)
+{
+int it;    //   current address position   
+it =read_E_port( LCDCONTROL);
+return(it);
+
+}
+*/
+/*==============================================================*/
+/* LcdSetAddress                        */
+/*==============================================================*/
+
+void LcdSetAddress(int address)
+{
+  //  LcdReady();
+    address |= 0x80;    /* write cg/dd ram address */   
+    write_E_port(LCDCONTROL, address);
+}
+
+
+/*==============================================================*/
+/* LcdClear                         */
+/*==============================================================*/
+void LcdClear(void)
+{
+   // LcdReady();
+    write_E_port(LCDCONTROL, 0x01);
+}    
+/*==============================================================*/
+/* LcdHomeTop                           */
+/*==============================================================*/
+void LcdHomeTop(void)
+{
+   // LcdReady();
+    write_E_port(LCDCONTROL, 0x02);
+}
+/*==============================================================*/
+/* LcdHomeBottom                        */
+/*==============================================================*/
+void LcdHomeBottom(void)
+{
+    //LcdReady();
+    write_E_port(LCDCONTROL, 0xc0);
+}
+
+/*==============================================================*/
+/* LcdCursorLeft                        */
+/*==============================================================*/
+void LcdCursorLeft(void)
+{
+    //LcdReady();
+    write_E_port(LCDCONTROL, 0x10);
+}       
+
+/*==============================================================*/
+/* LcdCursorRight                       */
+/*==============================================================*/
+void LcdCursorRight(void)
+{
+    //LcdReady();
+    write_E_port(LCDCONTROL, 0x14);
+}
+
+/*==============================================================*/
+/* LcdSpace                         */
+/*==============================================================*/
+void LcdSpace(void)
+{
+   // LcdReady();
+    write_E_port(LCDDATA, 0x20);
+}
+
+/*==============================================================*/
+/* LcdNSpace                            */
+/*==============================================================*/
+void LcdNSpace(int number)
+ 
+{
+int count;
+    for (count = 0; count < number; count++)
+    {
+        LcdSpace();
+    }
+}
+
+/*==============================================================*/
+/* LcdCursorNRight                      */
+/*==============================================================*/
+void LcdCursorNRight(int number)
+{
+    for (int n=0; n< number; n++)
+    {
+    LcdCursorRight();
+    }   
+}
+
+/*==============================================================*/
+/* LcdNLeft                         */
+/*==============================================================*/
+void LcdCursorNLeft(int number)
+
+{
+for (int n=0; n< number; n++)
+    {
+    LcdCursorLeft();
+    }   
+}
+
+
+/*==============================================================*/
+/* LcdClearTop                          */
+/*==============================================================*/
+void LcdClearTop(void)
+{
+    LcdHomeTop();
+    LcdNSpace(0x27);
+    LcdHomeTop();
+
+}
+
+/*==============================================================*/
+/* LcdClearBottom                       */
+/*==============================================================*/
+void LcdClearBottom(void)
+{
+    LcdHomeBottom();
+    LcdNSpace(0x27);
+    LcdHomeBottom();
+
+}
+
+/*==============================================================*/
+/* LcdPositionBottom                        */
+/*==============================================================*/
+void LcdPositionBottom(int pos)
+
+{
+    LcdSetAddress(LCDBOTTOMSTART + pos);
+
+}
+
+/*==============================================================*/
+/* LcdPositionTop                       */
+/*==============================================================*/
+void LcdPositionTop(int pos)
+ 
+{
+    LcdSetAddress(LCDTOPSTART + pos);
+}
+
+
+/*==============================================================*/
+/* LcdCursorFlash                       */
+/*==============================================================*/
+void LcdCursorFlash(void)
+{
+    //LcdReady();
+    write_E_port(LCDCONTROL, 0x0d);
+}       
+
+/*==============================================================*/
+/* LcdCursorOff                         */
+/*==============================================================*/
+void LcdCursorOff(void)
+{
+   // LcdReady();
+    write_E_port(LCDCONTROL, 0x0c);
+}       
+
+
+/*==============================================================*/
+/* LcdCursorNorm                        */
+/*==============================================================*/
+void LcdCursorNorm(void)
+{
+   // LcdReady();
+    write_E_port(LCDCONTROL, 0x0e);
+}       
+
+
+
+
+
+/*
+
+void read_E_port(unsigned char command)
+{
+        i2c.start();
+        i2c.write(Slave);
+        i2c.write(command);
+        i2c.stop();
+         wait(0.2);
+}
+*/
+
+void write_E_port(unsigned char command,unsigned char data)
+{
+ i2c.start();
+        i2c.write(Slave);
+        i2c.write(command);
+        i2c.write(data);
+        i2c.stop();
+        wait(0.01);
+}
+
+void LcdInit()
 {
 
         i2c.start();
@@ -24,7 +242,7 @@
         
 
 }
-
+/*
 void lcdclear()
 {
         i2c.start();
@@ -34,7 +252,7 @@
         i2c.stop();
          wait(0.2);
 }
-
+*/
 void test()
 {
 
@@ -45,17 +263,38 @@
 }
 
 
-void Show(char *text) 
+void LcdWriteText(char *text) 
 { 
  int n;//,d; 
  //d=0x00; 
  int length = strlen(text);
         i2c.start();
  i2c.write(Slave); //Slave=0x78 
- i2c.write(Datasend);//Datasend=0x40 
+ i2c.write(LCDDATA);//Datasend=0x40 
  for(n=0;n<length;n++){ 
   i2c.write(*text); 
   ++text; 
   } 
  i2c.stop(); 
-} 
\ No newline at end of file
+} 
+
+/*==============================================================*/
+/* attemp at lcdlcdprintf                       */
+/*==============================================================*/
+
+static void lcdputchar(char c, void *ptr)
+{
+    //LcdReady();         /* wait for lcd ready */
+    write_E_port(LCDDATA, c);   /* send data to lcd */
+}
+ /*
+int lcdprintf(const char *format, ...)
+{
+    va_list ap;
+    int nr_of_chars;
+    va_start (ap, format);  //variable arg begin    
+    nr_of_chars = _formatted_write (format, lcdputchar, (void *) 0, ap);
+    va_end(ap);         //variable arg end   
+    return(nr_of_chars);
+} */
+   
\ No newline at end of file