/* Embedded */
#include "inp_mat.h"
#define WIN_SIZE 8
void setup() {
// put your setup code here, to run once:
volatile char *dirf;
volatile char *outf;
volatile char x, l,l1, l2,l3, l4, l5, m, n, matrix_no, com_bit, com_bit2;
volatile char i=0;
dirf = 0x30;
outf = 0x31;
*dirf = 0x07;
volatile char arr[] = {0x0C, 0x01}; // Shutdown register - Normal Operation
l = (sizeof(arr))/ (sizeof(char));
while(l)
{
for (n=0; n<8; n++)
{
*outf = 0x00; // CS is set to 0 (Enabling CS)
com_bit = (((arr[i]) & (1 << (7-n))) ? 1:0);
//com_bit1 = ((com_bit) << 2);
*outf = ((com_bit) << 2); // Each bit of array elements is serially communicated (DIN)
delay(1);
*outf = (*outf) | (1<<1); // Enabling CLK signal
//*outf = 0x01; // CS is set to 1 (Disabling CS)
delay(1);
*outf = (*outf) & (0<<1); // Disabling CLK signal
delay(1);
}
i++;
l--;
//delay(2000);
}
*outf = 0x01; // CS is set to 1 (Disabling CS)
volatile char array1[] = {0x0B, 0x07}; // Scan Limit Register - Display all digits
l1 = (sizeof(array1))/ (sizeof(char));
volatile char j=0;
while(l1)
{
for (n=0; n<8; n++)
{
*outf = 0x00; // CS is set to 0 (Enabling CS)
com_bit = (((array1[j]) & (1 << (7-n))) ? 1:0);
//com_bit1 = ((com_bit) << 2);
*outf = ((com_bit) << 2); // Each bit of array elements is serially communicated (DIN)
delay(1);
*outf = (*outf) | (1<<1); // Enabling CLK signal
//*outf = 0x01; // CS is set to 1 (Disabling CS)
delay(1);
*outf = (*outf) & (0<<1); // Disabling CLK signal
delay(1);
}
j++;
l1--;
//delay(2000);
}
*outf = 0x01;
volatile char address_arr[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
volatile char temp1;
volatile int pos = 0;
volatile char temp[2], com_bit1[8];
volatile char k, k1;
//volatile char array2[] = {0x02, 0xFF, 0x04, 0xFF, 0x06, 0xFF, 0x08, 0xFF}; // Chip 2 - Column 4 - ALL LEDs ON
//volatile char array2[] = {0x01, 0x3F, 0x02, 0x41, 0x03, 0x81, 0x04, 0x81, 0x05, 0x3F, 0x06, 0x01, 0x07, 0x01, 0x08, 0x01}; // Chip 2 - Column 4 - ALL LEDs ON
while(1)
{
//if (pos % 61 == 0) // if WIN_SIZE is 4
if (pos == 63) // if WIN_SIZE is 8
{
pos = 0;
}
for(m=0; m<8; m++)
{
for(matrix_no = 0; matrix_no < 4; matrix_no++){
temp1 = 0x00;
for (n=0; n<8; n++)
{
temp1 = temp1 | ((mat_array1[m][(n + matrix_no*8 + pos)%64]) << ((8-WIN_SIZE) + n));
}
for (k1=0; k1<2; k1++)
{
*outf = 0x00; // CS is set to 0 (Enabling CS)
if (k1 == 0)
{
temp[k1] = address_arr[m];
}
else
{
temp[k1] = temp1;
}
for(k=0; k<8; k++)
{
com_bit1[k] = ((temp[k1] & (1 << (7-k))) ? 1:0);
//com_bit1 = ((com_bit) << 2);
*outf = ((com_bit1[k]) << 2); // Each bit of array elements is serially communicated (DIN)
//delay(1);
*outf = (*outf) | (1<<1); // Enabling CLK signal
//*outf = 0x01; // CS is set to 1 (Disabling CS)
//delay(1);
*outf = (*outf) & (0<<1); // Disabling CLK signal
//delay(1);
}
}
}
*outf = 0x01; // CS is set to 1 (Disabling CS)
}
pos++;
delay(100);
} // while(1) closing bracket
} // Final closing bracket
void loop() {
}