UCS1903 tape led

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Thu Jan 17 13:49:36 2013 +0000
Commit message:
1st build

Changed in this revision

LEDTape.cpp Show annotated file Show diff for this revision Revisions of this file
LEDTape.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 49551c775fc5 LEDTape.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LEDTape.cpp	Thu Jan 17 13:49:36 2013 +0000
@@ -0,0 +1,83 @@
+/*
+ * UCS1903 tape led IC
+ */
+#include "mbed.h"
+#include "LEDTape.h"
+
+SPI tape(p11, p12, p13);
+
+//#define tape_write(d) tape.write(d)
+#ifndef tape_write
+#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
+void tape_write (int d) {
+    while (! (LPC_SSP0->SR & (1<<1))); // TNF
+    LPC_SSP0->DR = d;
+}
+#elif defined(TARGET_LPC11U24)
+void tape_write (int d) {
+    while (! (LPC_SSP1->SR & (1<<1))); // TNF
+    LPC_SSP1->DR = d;
+}
+#endif
+#endif
+
+void tapeReset (int flag) {
+    int i;
+
+    __disable_irq();
+#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
+    if (flag) {
+        while ((LPC_SSP0->SR & ((1<<4)|(1<<0))) != (1<<0)); // BSY, TFE
+        LPC_PINCON->PINSEL1 &= ~(0x03<<4);  // GPIO
+        LPC_GPIO0->FIODIR0 |= (1<<18);
+        LPC_GPIO0->FIOSET0 = (1<<18);
+    } else {
+        for (i = 0; i < 4; i ++) {
+            tape_write(0x1f);
+        }
+        LPC_PINCON->PINSEL1 &= ~(0x03<<4);
+        LPC_PINCON->PINSEL1 |= (0x02<<4);  // SSP MOSI
+    }
+#elif defined(TARGET_LPC11U24)
+    if (flag) {
+        while ((LPC_SSP1->SR & ((1<<4)|(1<<0))) != (1<<0)); // BSY, TFE
+        LPC_IOCON->PIO1_22 &= ~0x07;    // GPIO
+        LPC_GPIO->DIR[1] |= (1<<22);
+        LPC_GPIO->SET[1] |= (1<<22);
+    } else {
+        for (i = 0; i < 4; i ++) {
+            tape_write(0x1f);
+        }
+        LPC_IOCON->PIO1_22 &= ~0x07;    
+        LPC_IOCON->PIO1_22 |= 0x02;     // SSP MOSI
+    }
+#endif
+    __enable_irq();
+}
+
+void tapeSend (int dat) {
+    int b;
+
+    __disable_irq();
+    for (b = 0x800000; b; b = b >> 1) {
+        if (dat & b) {
+            // 1
+            tape_write(0x01);
+        } else {
+            // 0
+            tape_write(0x0f);
+        }
+    }
+    __enable_irq();
+}
+
+void tapeInit (int freq) {
+    tape.format(5, 1);
+    if (freq) {
+        tape.frequency(freq * 1000);
+    } else {
+        // high speed (800kbps)
+        tape.frequency(4000000);
+    }
+    tapeReset(1);
+}
diff -r 000000000000 -r 49551c775fc5 LEDTape.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LEDTape.h	Thu Jan 17 13:49:36 2013 +0000
@@ -0,0 +1,10 @@
+/*
+ * UCS1903 tape led IC
+ */
+ 
+//#define TEST
+
+void tape_write (int d);
+void tapeReset (int flag);
+void tapeSend (int dat);
+void tapeInit (int speed);
diff -r 000000000000 -r 49551c775fc5 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jan 17 13:49:36 2013 +0000
@@ -0,0 +1,39 @@
+/*
+ * UCS1903 tape led IC
+ */
+#include "mbed.h"
+#include "LEDTape.h"
+
+DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
+
+int main() {
+    int i, j, k = 0;
+
+    tapeInit(0);
+    led1 = 1;
+
+    tapeReset(1);
+    wait(0.1);
+    while(1) {
+        for (i = 0; i < 256; i ++) {
+            led2 = 1;
+            tapeReset(0);
+            for (j = 0; j < k; j ++) {
+                tapeSend(0);
+            }
+            tapeSend(i); // G
+            tapeSend(0);
+            tapeSend(i << 8); // B
+            tapeSend(0);
+            tapeSend(i << 16); // R
+            tapeSend(0);
+            tapeSend(i | (i << 8) | (i << 16));
+            tapeSend(0);
+            tapeReset(1);
+            led2 = 0;
+            k ++;
+            if (k >= 100) k = 0;
+            wait_ms(10);
+        }
+    }
+}
diff -r 000000000000 -r 49551c775fc5 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jan 17 13:49:36 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63cdd78b2dc1
\ No newline at end of file