Lab5

Dependencies:   mbed

Revision:
0:59a8574b663a
diff -r 000000000000 -r 59a8574b663a main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 21 16:17:32 2017 +0000
@@ -0,0 +1,49 @@
+
+#include "mbed.h"
+#include "MCP4922.h"
+
+MCP4922 MCP(SPI_MOSI, SPI_SCK,PB_6);  // MOSI, SCLK, CS
+
+
+/**** Main Function  ***/
+int main(void)
+{
+    MCP.frequency(3125000);
+
+    uint16_t i=0;
+    int state=0;
+    while(1) {
+        if(i < 0x07FF) {
+            i++;
+        } 
+        else {
+            i=0;
+            if (state == 0 ){
+                state = 1;    
+            }
+            else if(state == 1) {
+                state = 2;
+            }
+            else if(state == 2){
+                state = 3;
+            }
+            else if(state == 3){
+                state = 0;
+            }
+        }
+
+        if(state ==0) {
+            MCP.writeA(i);
+        }
+        else if (state == 1){
+            MCP.writeA( ((~i))&0x07FF);
+        }
+        else if (state == 2){
+            MCP.writeA( ((~i))&0x0FFF);
+        }
+        else if (state == 3){
+            MCP.writeA(i+0x07FF);
+        }
+        wait_us(2);
+    }
+}
\ No newline at end of file