C coded library to use 1Wire LCD

Dependencies:   mbed

This method allows you to control an lcd with a 74x595 shift register.

/media/uploads/ahmetunal/shift1.gif /media/uploads/ahmetunal/shift1b.gif /media/uploads/ahmetunal/shift1c.gif /media/uploads/ahmetunal/_scaled_one_wire_lcd.bmp.jpg

Import program1WireLcd

C coded library to use 1Wire LCD

Files at this revision

API Documentation at this revision

Comitter:
ahmetunal
Date:
Sun Apr 10 08:38:02 2011 +0000
Child:
1:842f42dcf39a
Commit message:

Changed in this revision

1WireLcd/1WireLcd.cpp Show annotated file Show diff for this revision Revisions of this file
1WireLcd/1WireLcd.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/1WireLcd/1WireLcd.cpp	Sun Apr 10 08:38:02 2011 +0000
@@ -0,0 +1,118 @@
+#include "1WireLcd.h"
+#include "mbed.h"
+
+DigitalOut wire(p21);
+
+
+
+
+void lcd_putc(unsigned char c)
+{
+   unsigned char data;
+    data = 0x00;
+    data |=0x50;
+    one_wire(data);
+    data |= ((c & 0xF0)>>4);
+    one_wire(data);
+    data &= 0x1F;
+    one_wire(data);
+    wait_us(100);
+    
+    data = 0x00;
+    data |= 0x50;
+    one_wire(data);
+    data |= (((c & 0x0F) << 4) >> 4);
+    one_wire(data);
+    data &= 0x1F;
+    one_wire(data);
+    wait_us(100);
+
+}
+
+void lcd_command(unsigned char c)
+{
+   unsigned char data;
+    data = 0x00;
+    data |=0x40;
+    one_wire(data);
+    data |= ((c & 0xF0)>>4);
+    one_wire(data);
+    data &= 0x0F;
+    one_wire(data);
+    wait_us(100);
+    
+    data = 0x00;
+    data |= 0x40;
+    one_wire(data);
+    data |= (((c & 0x0F) << 4) >> 4);
+    one_wire(data);
+    data &= 0x0F;
+    one_wire(data);
+    wait_us(100);
+
+}
+
+
+void lcd_init()
+{
+    one_wire(0);
+    wait_ms(15);
+    lcd_command(GoToFirst);
+    wait_ms(2);
+    lcd_command(TwoLine4Bit);    
+    lcd_command(WriteRight);    
+    lcd_command(HidePointer);    
+    lcd_clear();
+
+
+    lcd_command(FirstLine); 
+}
+
+
+void lcd_clear(void)
+{
+    lcd_command(0x1);
+    wait_ms(2);
+}
+
+void lcd_position(unsigned char x,unsigned char y)
+{
+    if(x==1)
+        lcd_command(0x80+((y-1)%20));
+    else
+        lcd_command(0xC0+((y-1)%20));
+}
+
+void lcd_printf(const char * a)
+{
+    wait_us(100);
+    while(*a)
+        lcd_putc(*a++);
+}
+
+void one_wire(unsigned char data)
+{
+    char i;
+    wire=1;
+    for(i=0;i < 8;i++)
+    {
+        if((data<<(i))&0x80)
+        {
+            wire=0;
+            wait_us(1);
+            wire=1;
+        }
+        else
+        {
+            wire=0;
+            wait_us(15);
+            wire=1;
+            wait_us(30);
+        }
+    }
+    wire=0;
+    wait_us(210);
+    wire=1;
+    wait_us(300);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/1WireLcd/1WireLcd.h	Sun Apr 10 08:38:02 2011 +0000
@@ -0,0 +1,34 @@
+#ifndef MBED_1WireLcd_H
+#define MBED_1WireLcd_H
+
+#include "mbed.h"
+#include "LPC1768/LPC17xx.h"
+
+#define Clear 1
+#define GoToFirst 2
+#define WriteLeft 4
+#define WriteRight 6
+#define CloseLcd 8
+#define HidePointer 12
+#define PointerBottom 14
+#define FlashPointer 15
+#define PointerBack 16
+#define ShiftRight 24
+#define ShiftLeft 28 
+#define FirstLine 128
+#define SecondLine 192 
+
+#define TwoLine8Bit 56 
+#define OneLine8Bit 48
+#define TwoLine4Bit 40
+#define OneLine4Bit 32
+
+void one_wire(unsigned char data);
+void lcd_putc(unsigned char);
+void lcd_clear(void);
+void lcd_printf(const char * a);
+void lcd_position(unsigned char x, unsigned char y);
+void lcd_command(unsigned char a);
+void lcd_init(void);
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Apr 10 08:38:02 2011 +0000
@@ -0,0 +1,12 @@
+#include "mbed.h"
+#include "1WireLcd.h"
+
+
+DigitalOut myled(LED1);
+
+int main() {
+    
+    lcd_init();
+    
+    lcd_printf("Ahmet UNAL");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Apr 10 08:38:02 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912