4 Digits Shield and mbeduino

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Sun Oct 17 07:55:24 2010 +0000
Commit message:

Changed in this revision

G7Digits.c Show annotated file Show diff for this revision Revisions of this file
G7Digits.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 8b80ef8581d3 G7Digits.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/G7Digits.c	Sun Oct 17 07:55:24 2010 +0000
@@ -0,0 +1,94 @@
+/*
+ * mbed library to use a 4 Digits Shield
+ * Copyright (c) 2010 Hiroshi Suga
+ * Released under the MIT License: http://mbed.org/license/mit
+ */
+
+#include "mbed.h"
+#include "G7Digits.h"
+
+G7Digits::G7Digits(int p_beta) : g7d_d0(G7DIGITS_D0), g7d_d1(G7DIGITS_D1), g7d_d2(G7DIGITS_D2), g7d_d3(G7DIGITS_D3), g7d_dp(G7DIGITS_DP), g7d_com0(G7DIGITS_COM0), g7d_com1(G7DIGITS_COM1), g7d_en(G7DIGITS_EN) {
+    beta = p_beta;
+
+    digit_count = 0;
+    digit_num = 0;
+    digit_dot = 0;
+    digit_ctrl = 0x0f;
+}
+
+void G7Digits::begin() {
+    int_g7d.attach(this, &G7Digits::int_g7digits, 0.0025);
+}
+
+void G7Digits::int_g7digits() {
+    int n;
+
+    g7d_en = 0;
+
+    if (beta) {
+        if (digit_count == 0) {
+            g7d_com0 = 0;
+            g7d_com1 = 0;
+        } else
+        if (digit_count == 1) {
+            g7d_com0 = 1;
+            g7d_com1 = 1;
+        } else
+        if (digit_count == 2) {
+            g7d_com0 = 0;
+            g7d_com1 = 1;
+        } else
+        if (digit_count == 3) {
+            g7d_com0 = 1;
+            g7d_com1 = 0;
+        }
+    } else {
+        g7d_com0 = (digit_count & 0x01) ? 1 : 0;
+        g7d_com1 = (digit_count & 0x02) ? 1 : 0;
+    }
+
+    n = (digit_num >> (12 - (4 * digit_count))) & 0x0f;
+    g7d_d0 = (n & 0x01) ? 1 : 0;
+    g7d_d1 = (n & 0x02) ? 1 : 0;
+    g7d_d2 = (n & 0x04) ? 1 : 0;
+    g7d_d3 = (n & 0x08) ? 1 : 0;
+
+    if (digit_dot & (1 << digit_count)) {
+        digit_pin = g7d_dp.read();
+        g7d_dp = 0;
+        g7d_dp.output();
+    } else {
+        if (digit_pin || g7d_dp.read()) {
+            g7d_dp = 1;
+            g7d_dp.output();
+        } else {
+            g7d_dp.input();
+        }
+    }
+
+    if (digit_ctrl & (1 << digit_count))
+        g7d_en = 1;
+
+    digit_count ++;
+    if (digit_count >= 4) digit_count = 0;
+}
+
+int G7Digits::write (int num)
+{
+    digit_num = num % 10;
+    digit_num |= ((num / 10) % 10) << 4;
+    digit_num |= ((num / 100) % 10) << 8;
+    digit_num |= (unsigned int)((num / 1000) % 10) << 12;
+
+    return digit_num;
+}
+
+void G7Digits::ctrl (char d1, char d2, char d3, char d4)
+{
+    digit_ctrl = (d1 ? 1 : 0) | (d2 ? 2 : 0) | (d3 ? 4 : 0) | (d4 ? 8 : 0);
+}
+
+void G7Digits::dot (char d1, char d2, char d3, char d4)
+{
+    digit_dot = (d1 ? 1 : 0) | (d2 ? 2 : 0) | (d3 ? 4 : 0) | (d4 ? 8 : 0);
+}
diff -r 000000000000 -r 8b80ef8581d3 G7Digits.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/G7Digits.h	Sun Oct 17 07:55:24 2010 +0000
@@ -0,0 +1,57 @@
+/*
+ * mbed library to use a I2C LCD
+ * Copyright (c) 2010 Hiroshi Suga
+ * Released under the MIT License: http://mbed.org/license/mit
+ */
+ 
+#ifndef G7Digits_H
+#define G7Digits_H
+
+#include "mbed.h"
+
+#define G7DIGITS_LED1 p5
+#define G7DIGITS_LED2 p25
+#define G7DIGITS_LED3 p24
+#define G7DIGITS_SW1 p29
+#define G7DIGITS_SW2 p11
+#define G7DIGITS_SW3 p30
+#define G7DIGITS_BZ p21
+
+#define G7DIGITS_D0 p23
+#define G7DIGITS_D1 p12
+#define G7DIGITS_D2 p6
+#define G7DIGITS_D3 p7
+#define G7DIGITS_DP p5
+#define G7DIGITS_COM0 p27
+#define G7DIGITS_COM1 p28
+#define G7DIGITS_EN p22
+
+#define G7DIGITS_VR1 p15
+#define G7DIGITS_VR2 p16
+#define G7DIGITS_VR3 p17
+#define G7DIGITS_PHOTO p18
+#define G7DIGITS_TEMP p19
+#define G7DIGITS_VOLT p20
+
+class G7Digits : public Base {
+public:
+    G7Digits(int p_beta = 0);
+
+    void begin();
+    int write(int);
+    void ctrl(char, char, char, char);
+    void dot(char, char, char, char);
+
+private:
+    Ticker int_g7d;
+    DigitalOut g7d_d0, g7d_d1, g7d_d2, g7d_d3, g7d_com0, g7d_com1, g7d_en;
+    DigitalInOut g7d_dp;
+
+    int beta;
+    volatile int digit_count, digit_dot, digit_ctrl, digit_pin;
+    volatile unsigned int digit_num;
+
+    void int_g7digits();
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 8b80ef8581d3 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 17 07:55:24 2010 +0000
@@ -0,0 +1,21 @@
+#include "mbed.h"
+#include "G7Digits.h"
+
+DigitalIn g7d_sw1(G7DIGITS_SW1);
+AnalogIn g7d_vr1(G7DIGITS_VR1);
+G7Digits g7digits(1);
+
+int main() {
+    g7digits.begin();
+
+    for (int i = 0; i < 10000; i ++) {
+        g7digits.write(i);
+        wait(0.01);
+    }
+
+    for (;;) {
+        if (g7d_sw1) break;
+        g7digits.write(g7d_vr1 * 1023);
+        wait(0.1);
+    }
+}
diff -r 000000000000 -r 8b80ef8581d3 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Oct 17 07:55:24 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e