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:
Mon Oct 15 21:23:48 2012 +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

HostIO.cpp Show annotated file Show diff for this revision Revisions of this file
HostIO.h Show annotated file Show diff for this revision Revisions of this file
SegDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
SegDisplay.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 507436d37d5e HostIO.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HostIO.cpp	Mon Oct 15 21:23:48 2012 +0000
@@ -0,0 +1,15 @@
+/* Program Example 6.8: HostIO.cpp code for modular 7-seg keyboard controller 
+                                                                            */
+#include "HostIO.h"
+
+Serial pc(USBTX, USBRX);       // communication to host PC
+
+void HostInit(void) {
+  pc.printf("\n\rType two digit numbers to be \n\r");
+}
+
+char GetKeyInput(void) {
+  char c = pc.getc();    // get keyboard ascii data
+  pc.printf("%c",c);     // print ascii value to host PC terminal
+  return (c&0x0F);       // return value as non-ascii 
+}
diff -r 000000000000 -r 507436d37d5e HostIO.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HostIO.h	Mon Oct 15 21:23:48 2012 +0000
@@ -0,0 +1,13 @@
+/* Program Example 6.9: HostIO.h code for modular 7-seg keyboard controller 
+                                                                           */
+#ifndef HOSTIO_H
+
+#define HOSTIO_H
+#include "mbed.h"
+
+extern Serial pc;        // allow pc to be manipulated by other files
+
+void HostInit(void);     // function prototype
+char GetKeyInput(void);  // function prototype
+
+#endif 
diff -r 000000000000 -r 507436d37d5e SegDisplay.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SegDisplay.cpp	Mon Oct 15 21:23:48 2012 +0000
@@ -0,0 +1,27 @@
+/* Program Example 6.6: SegDisplay.cpp file for modular 7-seg keyboard controller 
+                                                                  */
+#include "SegDisplay.h"
+BusOut Seg1(p5,p6,p7,p8,p9,p10,p11,p12);      // A,B,C,D,E,F,G,DP
+BusOut Seg2(p13,p14,p15,p16,p17,p18,p19,p20); // A,B,C,D,E,F,G,DP
+
+void SegInit(void) {
+  Seg1=SegConvert(0);        // initialise to zero
+  Seg2=SegConvert(0);        // initialise to zero
+}
+
+char SegConvert(char SegValue) {         // function 'SegConvert'
+  char SegByte=0x00;
+  switch (SegValue) {                  //DP G F E D C B A
+    case 0 : SegByte = 0x3F; break;    // 0 0 1 1 1 1 1 1 binary
+    case 1 : SegByte = 0x06; break;    // 0 0 0 0 0 1 1 0 binary
+    case 2 : SegByte = 0x5B; break;    // 0 1 0 1 1 0 1 1 binary
+    case 3 : SegByte = 0x4F; break;    // 0 1 0 0 1 1 1 1 binary
+    case 4 : SegByte = 0x66; break;    // 0 1 1 0 0 1 1 0 binary
+    case 5 : SegByte = 0x6D; break;    // 0 1 1 0 1 1 0 1 binary
+    case 6 : SegByte = 0x7D; break;    // 0 1 1 1 1 1 0 1 binary
+    case 7 : SegByte = 0x07; break;    // 0 0 0 0 0 1 1 1 binary
+    case 8 : SegByte = 0x7F; break;    // 0 1 1 1 1 1 1 1 binary
+    case 9 : SegByte = 0x6F; break;    // 0 1 1 0 1 1 1 1 binary
+  }
+  return SegByte;
+} 
diff -r 000000000000 -r 507436d37d5e SegDisplay.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SegDisplay.h	Mon Oct 15 21:23:48 2012 +0000
@@ -0,0 +1,14 @@
+/* Program Example 6.7: SegDisplay.h file for modular 7-seg keyboard controller 
+                                                                 */
+#ifndef SEGDISPLAY_H
+#define SEGDISPLAY_H
+
+#include "mbed.h"  
+                 
+extern BusOut Seg1;     // allow Seg1 to be manipulated by other files
+extern BusOut Seg2;     // allow Seg2 to be manipulated by other files
+
+void SegInit(void);                  // function prototype
+char SegConvert(char SegValue);      // function prototype
+
+#endif 
diff -r 000000000000 -r 507436d37d5e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 15 21:23:48 2012 +0000
@@ -0,0 +1,21 @@
+/* Program Example 6.5: main.cpp file for modular 7-seg keyboard controller
+
+This example program includes example code PE6.06, PE6.07, PE6.08, PE6.09
+                                                                           */
+#include "mbed.h"
+#include "HostIO.h"
+#include "SegDisplay.h"
+char data1, data2;                    // variable declarations
+
+int main() {                          // main program
+  SegInit();                          // call init function 
+  HostInit();                         // call init function
+  while (1) {                         // infinite loop
+    data2 = GetKeyInput();            // call to get 1st key press
+    Seg2  = SegConvert(data2);        // call to convert and output
+    data1 = GetKeyInput();            // call to get 2nd key press
+    Seg1  = SegConvert(data1);        // call to convert and output
+    pc.printf("  ");                  // display spaces on host
+  }
+} 
+
diff -r 000000000000 -r 507436d37d5e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Oct 15 21:23:48 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/cd19af002ccc
\ No newline at end of file