Permalink
Browse files

Added figure simulator

  • Loading branch information...
1 parent 79d8a07 commit 97851bade1bdeab8657db5db96ae6bead92d42bf @natashenka committed Jun 25, 2012
Showing with 100 additions and 0 deletions.
  1. +1 −0 figure-simulator/README
  2. +99 −0 figure-simulator/simulator.pde
View
@@ -0,0 +1 @@
+Code to simulate a memetchi figure. In progress.
@@ -0,0 +1,99 @@
+#include <DSPI.h>
+
+DSPI0 spi;
+const int len = 200;
+uint8_t rgbSnd[len] = {0};
+uint8_t rgbRcv[len] = {0};
+uint8_t b[] ={0x40, 0x00, 0x00, 0xC4, 0x00, 0x00, 0xDC, 0x00, 0x00, 0x0F, 0x01, 0x00, 0x91, 0x01, 0x00, 0x0D, 0x02, 0x00, 0x89, 0x02, 0x00, 0xD1, 0x02, 0x00, 0x1F, 0x06, 0x00, 0x67, 0x0F, 0x00, 0x67, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x12, 0x00, 0xA7, 0x12, 0x00, 0x0D, 0x13, 0x00, 0x73, 0x13, 0x00, 0xD9, 0x13, 0x00, 0x3F, 0x14, 0x00, 0xA5, 0x14, 0x00, 0x0B, 0x15, 0x00, 0x71, 0x15, 0x00, 0xD7, 0x15, 0x00, 0x3D, 0x16, 0x00, 0xA3, 0x16, 0x00, 0x09, 0x17, 0x00, 0x6F, 0x17, 0x00, 0xD5, 0x17, 0x00, 0x3B, 0x18, 0x00, 0xA1, 0x18, 0x00, 0x07, 0x19, 0x00, 0x6D, 0x19, 0x00, 0xD3, 0x19, 0x00, 0x39, 0x1A, 0x00, 0x9F, 0x1A, 0x00, 0x05, 0x1B, 0x00, 0x6B, 0x1B, 0x00, 0xD1, 0x1B, 0x00, 0x37, 0x1C, 0x00, 0x9D, 0x1C, 0x00, 0x13, 0x1E, 0x00, 0x89, 0x1F, 0x00, 0xFF, 0x20, 0x00, 0x75, 0x22, 0x00, 0xEB, 0x23, 0x00, 0x61, 0x25, 0x00, 0xD7, 0x26, 0x00, 0x4D, 0x28, 0x00, 0xEB, 0x28, 0x00, 0x89, 0x29, 0x00, 0x64, 0x2A, 0x00, 0xA2, 0x2A, 0x00, 0xE0, 0x2A, 0x00, 0x1E, 0x2B, 0x00, 0x5C, 0x2B, 0x00, 0x9A, 0x2B, 0x00, 0x05, 0x2C, 0x00, 0x70, 0x2C, 0x00, 0x82, 0x2C, 0x00, 0x90, 0x2C, 0x00, 0x9E, 0x2C, 0x00, 0xB0, 0x2C, 0x00, 0xC2, 0x2C, 0x00, 0xD4, 0x2C};
+int i;
+int yc = 0;
+int x=0;
+int y=0;
+
+void setup()
+{
+ Serial.begin(9600);
+ Serial.println("start");
+ spi.begin();
+ spi.setSpeed(600000);
+ SPI2CONbits.ON = 0;
+ rgbRcv[0] = SPI2BUF;
+ SPI2CONbits.MSTEN = 0;
+ SPI2CONbits.SSEN = 1;
+ SPI2CONbits.CKP = 0;
+ SPI2CONbits.CKE = 1;
+ rgbSnd[4] = 0xaa;
+ rgbSnd[5] = 0x55;
+ rgbSnd[6] = 0x08;
+
+ rgbSnd[11] = 0xaa;
+ rgbSnd[12] = 0x55;
+
+
+
+ rgbSnd[17] = 0x03;
+ rgbSnd[18] = 0x03;
+ rgbSnd[19] = 0x03;
+ rgbSnd[20] = 0x00;
+ rgbSnd[21] = 0x00;
+ rgbSnd[22] = 0x10;
+ rgbSnd[23] = 0x03;
+ // rgbSnd[28] = 0x40;
+ // rgbSnd[31] = 0xc4;
+ // rgbSnd[34] = 0xdc;
+
+ // rgbSnd[40] =
+ while(i<96-28){
+ for(y = 0; y < 8; y++){
+ rgbSnd[28 + i] = b[yc++];
+ i++;
+ }
+ for(x = 0; x < 4; x++){
+ i++;
+ }
+ }
+
+ rgbSnd[100] = 0xaa;
+ rgbSnd[101] = 0x55;
+ rgbSnd[106] = 0x9a;
+ rgbSnd[107] = 0x2b;
+ rgbSnd[108] = 0x00;
+ rgbSnd[113] = 0x11;
+ rgbSnd[114] = 0x15;
+ rgbSnd[119] = 0xaa;
+ rgbSnd[120] = 0x55;
+ /// rgbSnd[140] = 0xff;
+ SPI2CONbits.ON = 1;
+ Serial.println("start 2");
+}
+
+void loop()
+{
+ for (i = 0; i < 150; i++)
+ {
+ rgbRcv[i] = spiComm(rgbSnd[i]);
+ }
+
+
+ for(i = 0; i < 150; i++)
+ {
+ Serial.print(i);
+ Serial.print(" ");
+ Serial.print(rgbSnd[i], HEX);
+ Serial.print(" ");
+ Serial.println(rgbRcv[i], HEX);
+ }
+ Serial.println("END");
+}
+
+uint8_t spiComm(uint8_t bVal)
+{
+ while ((SPI2STAT & (1 << _SPISTAT_SPITBE)) == 0) {
+ }
+ SPI2BUF = bVal;
+
+ while ((SPI2STAT & (1 << _SPISTAT_SPIRBF)) == 0) {
+ }
+
+ return SPI2BUF;
+}

0 comments on commit 97851ba

Please sign in to comment.