//DSP-0801 TEST PROGRAM
//For Arduino IDE

//pin definitions, using the shiftOut function to communicate with the display
const int SDATA = 12;   //to SIN on JP1     
const int CLOCK = 11;   //to CLK on JP1
const int LATCH = 10;   //to LAT on JP1
const int BLANK = 9;	//to BL  on JP1

//BL pin on JP1 MUST be pulled LOW, we will do this in software
//Display brightness can also be controlled through PWM using AnalogWrite function

void setup () {
  
  //set all pins to output
  pinMode(SDATA, OUTPUT);    
  pinMode(CLOCK, OUTPUT);
  pinMode(LATCH, OUTPUT);
  pinMode(BLANK, OUTPUT);
  digitalWrite(BLANK, LOW); //for this example, BLANK is held LOW throughout
  
  //allow DSP-0801's onboard PIC to wake up before sending any data
  delay(500);                
  
   //send 8 blank digits to clear all registers, not always necessary but good practice
   for(int i = 0; i < 8; i++) {                  
    digitalWrite(LATCH, LOW);
    shiftOut(SDATA, CLOCK, MSBFIRST, 0x0000);    //data must be sent one byte at a time
    shiftOut(SDATA, CLOCK, MSBFIRST, 0x0000);
    digitalWrite(LATCH, HIGH);
  }
  
}


void loop () {
  
    //defines how fast digits will scroll
    int scrollRate   = 200;      
    
    //character table array - what we want to put on the display goes in here, in this case:
    //"DSP0801 THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG    "
    //refer to 14-segment character code document for HEX values
    
    word charTable[55] = {
    0x120F, 0x909,  0x00F3, 0x243F, 0x00FF, 0x243F, 0x406,  0x0000,
    0x1201, 0x00F6, 0x0079, 0x0000, 0x83F,  0x003E, 0x1209, 0x0039, 0xC70,
    0x0000, 0x00BF, 0x8F3,  0x003F, 0x2A36, 0x936,  0x0000,
    0x0071, 0x003F, 0x2D00, 0x0000, 0x001E, 0x003E, 0x1536, 0x00F3, 0x909,
    0x0000, 0x003F, 0x2430, 0x0079, 0x8F3,  0x0000, 0x1201, 0x00F6, 0x0079,
    0x0000, 0x0038, 0x00F7, 0x2409, 0x1500, 0x0000, 0x120F, 0x003F, 0x00BD,
    0x0000, 0x0000, 0x0000, 0x0000 
    };                                                                      
                                                                            
  //get characters from array one at a time ready to be shifted out
 
  for(int index = 0; index < 55; index++){                                   
  word charData = charTable[index];
  
  //shift out the value currently held in charData
  digitalWrite(LATCH, LOW);
  shiftOut(SDATA, CLOCK, MSBFIRST, (charData >> 8));  //send one byte
  shiftOut(SDATA, CLOCK, MSBFIRST, charData);         //then the other 
  digitalWrite(LATCH, HIGH);
  delay(scrollRate);
  }
   
  
}

  
