by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
robt
Date:
Fri May 24 21:33:46 2013 +0000
Commit message:
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Changed in this revision

LCD.cpp Show annotated file Show diff for this revision Revisions of this file
LCD.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
diff -r 000000000000 -r 519ae7e3077e LCD.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.cpp	Fri May 24 21:33:46 2013 +0000
@@ -0,0 +1,64 @@
+#include "LCD.h"
+
+DigitalOut RS(p19);             // RS
+DigitalOut RW(p19);             // RW
+DigitalOut E(p20);              // Enable
+BusOut data(p21, p22, p23, p24);// DB4-DB7
+
+/****initialise LCD function ****/  
+void LCD_init(void){  
+
+  wait(0.02);
+  RS=0;    // set all low to write control/instruction data
+//  RW=0;
+  E=0;
+     
+  // Function set
+  data=0x2;            // = 4 bit mode
+  toggle_enable();
+  data=0x8;            // = 2-line mode, 7 dot characters
+  toggle_enable(); 
+ 
+  // Display Mode
+  data=0x0;          //                    
+  toggle_enable();
+  data=0xF;             // display on, cursor on, blink on                    
+  toggle_enable();
+
+  // Clear display
+  data=0x0;            //
+  toggle_enable();
+  data=0x1;            // clear 
+  toggle_enable();
+  
+}
+
+
+/**** display ****/  
+void display_to_LCD(char value ){
+    
+    RS=1;
+    //***** display character *****************            
+    data=value>>4;       // value shifted right 4 = upper              
+    toggle_enable();
+    data=value&0x0F;       // value bitmask with 0x0F = lower      
+    toggle_enable();
+}
+
+
+/**** toggle enable function ****/  
+void toggle_enable(void){
+  E=1;
+  wait(0.001);
+  E=0;
+  wait(0.001);
+}
+
+/**** set location function ****/                                                                      
+void set_location(char location){
+    RS=0;
+    data=(location|0x80)>>4;             // upper nibble             
+    toggle_enable();
+    data=location&0x0F;                  // lower nibble      
+    toggle_enable();
+}
diff -r 000000000000 -r 519ae7e3077e LCD.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.h	Fri May 24 21:33:46 2013 +0000
@@ -0,0 +1,11 @@
+//LCD.h file
+
+#ifndef LCD_H
+#define LCD_H
+
+#include "mbed.h"
+void display_to_LCD(char value);    //function to display characters on the LCD 
+void toggle_enable(void);           //function to toggle the enable bit
+void LCD_init(void);                //function to initialise the LCD
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 519ae7e3077e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 24 21:33:46 2013 +0000
@@ -0,0 +1,18 @@
+/*Program Example 8.1, 8.2, 8.3, 8.4:  TextLCD example
+                                                           */
+
+
+#include "LCD.h"
+
+int main() {
+    LCD_init();
+    display_to_LCD(0x48);   // ￿H￿
+    display_to_LCD(0x45);   // ￿E￿
+    display_to_LCD(0x4C);   // ￿L￿
+    display_to_LCD(0x4C);   // ￿L￿
+    display_to_LCD(0x4F);   // ￿O￿
+    for(char x=0x30;x<=0x39;x++){
+      display_to_LCD(x);              // display numbers 0-9
+    }
+}
+
diff -r 000000000000 -r 519ae7e3077e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri May 24 21:33:46 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912
\ No newline at end of file