#define DDR_SPI DDRB
#define DD_MOSI PB2
#define DD_SCK PB1
#define DD_SS PB0
#define DD_SS1 PB3
unsigned int centeredsquare1_B[]= {0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00};
unsigned int thincheck_B[] = {0x00, 0x00, 0x01, 0x02, 0x04, 0x88, 0x50, 0x20};
const uint8_t angryface_B[] = {0x00, 0x66, 0x66, 0x00, 0x18, 0x24, 0x42, 0x81};
char characters[96][5] = {
{0b00000000,0b00000000,0b00000000,0b00000000,0b00000000}, // space
{0b00000000,0b00000000,0b01001111,0b00000000,0b00000000}, // !
{0b00000000,0b00000111,0b00000000,0b00000111,0b00000000}, // "
{0b00010100,0b01111111,0b00010100,0b01111111,0b00010100}, // #
{0b00100100,0b00101010,0b01111111,0b00101010,0b00010010}, // $
{0b00100011,0b00010011,0b00001000,0b01100100,0b01100010}, // %
{0b00110110,0b01001001,0b01010101,0b00100010,0b01010000}, // &
{0b00000000,0b00000101,0b00000011,0b00000000,0b00000000}, // '
{0b00000000,0b00011100,0b00100010,0b01000001,0b00000000}, // (
{0b00000000,0b01000001,0b00100010,0b00011100,0b00000000}, // )
{0b00010100,0b00001000,0b00111110,0b00001000,0b00010100}, // *
{0b00001000,0b00001000,0b00111110,0b00001000,0b00001000}, // +
{0b00000000,0b01010000,0b00110000,0b00000000,0b00000000}, // ,
{0b00001000,0b00001000,0b00001000,0b00001000,0b00001000}, // -
{0b00000000,0b01100000,0b01100000,0b00000000,0b00000000}, // .
{0b00100000,0b00010000,0b00001000,0b00000100,0b00000010}, // /
{0b00111110,0b01010001,0b01001001,0b01000101,0b00111110}, // 0
{0b00000000,0b01000010,0b01111111,0b01000000,0b00000000}, // 1
{0b01000010,0b01100001,0b01010001,0b01001001,0b01000110}, // 2
{0b00100001,0b01000001,0b01000101,0b01001011,0b00110001}, // 3
{0b00011000,0b00010100,0b00010010,0b01111111,0b00010000}, // 4
{0b00100111,0b01000101,0b01000101,0b01000101,0b00111001}, // 5
{0b00111100,0b01001010,0b01001001,0b01001001,0b00110000}, // 6
{0b00000011,0b01110001,0b00001001,0b00000101,0b00000011}, // 7
{0b00110110,0b01001001,0b01001001,0b01001001,0b00110110}, // 8
{0b00000110,0b01001001,0b01001001,0b00101001,0b00011110}, // 9
{0b00000000,0b01101100,0b01101100,0b00000000,0b00000000}, // :
{0b00000000,0b01010110,0b00110110,0b00000000,0b00000000}, // ;
{0b00001000,0b00010100,0b00100010,0b01000001,0b00000000}, // <
{0b00010100,0b00010100,0b00010100,0b00010100,0b00010100}, // =
{0b00000000,0b01000001,0b00100010,0b00010100,0b00001000}, // >
{0b00000010,0b00000001,0b01010001,0b00001001,0b00000110}, // ?
{0b00110010,0b01001001,0b01111001,0b01000001,0b00111110}, // @
{0b01111110,0b00010001,0b00010001,0b00010001,0b01111110}, // A
{0b01111111,0b01001001,0b01001001,0b01001001,0b00111110}, // B
{0b00111110,0b01000001,0b01000001,0b01000001,0b00100010}, // C
{0b01111111,0b01000001,0b01000001,0b01000001,0b00111110}, // D
{0b01111111,0b01001001,0b01001001,0b01001001,0b01001001}, // E
{0b01111111,0b00001001,0b00001001,0b00001001,0b00000001}, // F
{0b00111110,0b01000001,0b01001001,0b01001001,0b00111010}, // G
{0b01111111,0b00001000,0b00001000,0b00001000,0b01111111}, // H
{0b01000001,0b01000001,0b01111111,0b01000001,0b01000001}, // I
{0b00110000,0b01000001,0b01000001,0b00111111,0b00000001}, // J
{0b01111111,0b00001000,0b00010100,0b00100010,0b01000001}, // K
{0b01111111,0b01000000,0b01000000,0b01000000,0b01000000}, // L
{0b01111111,0b00000010,0b00001100,0b00000010,0b01111111}, // M
{0b01111111,0b00000100,0b00001000,0b00010000,0b01111111}, // N
{0b00111110,0b01000001,0b01000001,0b01000001,0b00111110}, // O
{0b01111111,0b00001001,0b00001001,0b00001001,0b00000110}, // P
{0b00111110,0b01000001,0b01010001,0b00100001,0b01011110}, // Q
{0b01111111,0b00001001,0b00001001,0b00011001,0b01100110}, // R
{0b01000110,0b01001001,0b01001001,0b01001001,0b00110001}, // S
{0b00000001,0b00000001,0b01111111,0b00000001,0b00000001}, // T
{0b00111111,0b01000000,0b01000000,0b01000000,0b00111111}, // U
{0b00001111,0b00110000,0b01000000,0b00110000,0b00001111}, // V
{0b00111111,0b01000000,0b00111000,0b01000000,0b00111111}, // W
{0b01100011,0b00010100,0b00001000,0b00010100,0b01100011}, // X
{0b00000011,0b00000100,0b01111000,0b00000100,0b00000011}, // Y
{0b01100001,0b01010001,0b01001001,0b01000101,0b01000011}, // Z
{0b01111111,0b01000001,0b01000001,0b00000000,0b00000000}, // [
{0b00000010,0b00000100,0b00001000,0b00010000,0b00100000}, // '\'
{0b00000000,0b00000000,0b01000001,0b01000001,0b01111111}, // ]
{0b00000100,0b00000010,0b00000001,0b00000010,0b00000100}, // ^
{0b01000000,0b01000000,0b01000000,0b01000000,0b01000000}, // _
{0b00000000,0b00000001,0b00000010,0b00000100,0b00000000}, // `
{0b00100000,0b01010100,0b01010100,0b01010100,0b01111000}, // a
{0b01111111,0b01001000,0b01000100,0b01000100,0b00111000}, // 0b
{0b00111000,0b01000100,0b01000100,0b01000100,0b00100000}, // c
{0b00111000,0b01000100,0b01000100,0b01001000,0b01111111}, // d
{0b00111000,0b01010100,0b01010100,0b01010100,0b00011000}, // e
{0b00001000,0b01111110,0b00001001,0b00000001,0b00000010}, // f
{0b00001100,0b01010010,0b01010010,0b01010010,0b00111110}, // g
{0b01111111,0b00001000,0b00000100,0b00000100,0b01111000}, // h
{0b00000000,0b01000100,0b01111101,0b01000000,0b00000000}, // i
{0b00100000,0b01000000,0b01000100,0b00111101,0b00000000}, // j
{0b01111111,0b00010000,0b00101000,0b01000100,0b00000000}, // k
{0b00000000,0b01000001,0b01111111,0b01000000,0b00000000}, // l
{0b01111000,0b00000100,0b00001000,0b00000100,0b01111000}, // m
{0b01111100,0b00001000,0b00000100,0b00000100,0b01111000}, // n
{0b00111000,0b01000100,0b01000100,0b01000100,0b00111000}, // o
{0b01111100,0b00010100,0b00010100,0b00010100,0b00001000}, // p
{0b00001000,0b00010100,0b00010100,0b01111100,0b00000000}, // q
{0b01111100,0b00001000,0b00000100,0b00000100,0b00001000}, // r
{0b01001000,0b01010100,0b01010100,0b01010100,0b00100000}, // s
{0b00000100,0b00111111,0b01000100,0b01000000,0b00100000}, // t
{0b00111100,0b01000000,0b01000000,0b00100000,0b01111100}, // u
{0b00011100,0b00100000,0b01000000,0b00100000,0b00011100}, // v
{0b00111100,0b01000000,0b00110000,0b01000000,0b00111100}, // w
{0b01000100,0b00101000,0b00010000,0b00101000,0b01000100}, // x
{0b00001100,0b01010000,0b01010000,0b01010000,0b00111100}, // y
{0b01000100,0b01100100,0b01010100,0b01001100,0b01000100}, // z
{0b00000000,0b00001000,0b00110110,0b01000001,0b00000000}, // {
{0b00000000,0b00000000,0b01111111,0b00000000,0b00000000}, // |
{0b00000000,0b01000001,0b00110110,0b00001000,0b00000000}, // }
{0b00001000,0b00000100,0b00000100,0b00001000,0b00000100} // ~
}; // characters[95]
void SPI_MasterInit(void)
{
PORTB|=1<<PB0;
PORTB|=1<<PB3;
/* Set MOSI and SCK output, all others input */
DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS)|(1<<DD_SS1);
/* Enable SPI, Master, set clock rate fck/16 */
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0)|(0<<DORD);
}
void SPI_MasterTransmit(char cData)
{
// PORTB&= ~1<<PB0;
/* Start transmission */
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)))
{
}
}
void abv(char adr, char dt)
{
PORTB&= ~1<<DD_SS;
SPI_MasterTransmit(adr);
SPI_MasterTransmit(dt);
PORTB|=1<<DD_SS;
}
void abv1(char adr1, char dt1)
{
PORTB&= ~1<<DD_SS1;
SPI_MasterTransmit(adr1);
SPI_MasterTransmit(dt1);
PORTB|=1<<DD_SS1;
}
void sendColumn(char adr, char dt) {
PORTB &= ~(1<<DD_SS); // Enable slave
SPI_MasterTransmit(7-adr); // Send address
SPI_MasterTransmit(dt); // Send data
PORTB |= (1<<DD_SS); // Disable slave
}
void lala(char adr, char dt)
{
PORTB&= ~1<<DD_SS;
SPI_MasterTransmit(adr);
SPI_MasterTransmit(dt);
PORTB|=1<<DD_SS;
}
void clearMatrix() {
// Sending blank data for each column to clear the matrix
for(int i = 1; i <= 8; i++) {
sendColumn(i, 0x00);
}
}
int main()
{volatile char c;
Serial.begin(9600);
Serial.print("1");
SPI_MasterInit();
sei();
// put your setup code here, to run once:
char numbers[][8] = {
{0b00001000, 0b00001100, 0b00001010, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b11111111}, // number 1
{0b00001110, 0b00010010, 0b00010000, 0b00011000, 0b00000100, 0b00000100, 0b00001000, 0b11111111}, // number 2
{0b00011100, 0b00100010, 0b00100001, 0b00010000, 0b00100000, 0b01000000, 0b00100000, 0b00011100}, // number 3
{0b01000010, 0b01000010, 0b01000010, 0b01111110, 0b01000000, 0b01000000, 0b01000000, 0b01000000}, // number 4
{0b11111000, 0b00001000, 0b00001000, 0b00011000, 0b00100000, 0b01000000, 0b00100000, 0b00011110} // number 5
};
char number_2[8] = {
0b00000000,
0b01000100,
0b00000000,
0b00000000,
0b10000010,
0b01111100,
0b00000000,
0b00000000
};
// Sending data for each column
for (int i =0;i<9;i++)
{
abv1(i,angryface_B[i]);
}
while(1) {
// Display each number with a delay
for(int i = 0; i < 96; i++) {
if (Serial.available() > 0)
{
c = Serial.read();
Serial.read();
Serial.println(c,HEX);
}
// Sending data for each column to display the number
for(int j = 0; j < 5; j++) {
sendColumn(j+1, characters[c-32][j]);
}
_delay_ms(1000); // Delay for 1 second
clearMatrix(); // Clear the matrix before displaying next number
//_delay_ms(1000); // Delay for 1 second before displaying next number
}
}
return 0;
}