#include <stdio.h>
#include <string.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <stdint.h>
typedef struct {
unsigned char adr;
unsigned char dat;
} _send_data;
int main(void)
{
int fd;
static _send_data data[8];
static unsigned char set_data[2];
/* Setup SPI libraly */
wiringPiSetup();
if((fd = wiringPiSPISetup(0,500000)) < 0){
printf("SPI initialize error\n");
return -1;
}
/* Initialize MAX7219 */
memset((void *)data,0,sizeof(data));
set_data[0] = 0x09, set_data[1] = 0x00; wiringPiSPIDataRW(0,set_data,2);
set_data[0] = 0x0a, set_data[1] = 0x04; wiringPiSPIDataRW(0,set_data,2);
set_data[0] = 0x0b, set_data[1] = 0x07; wiringPiSPIDataRW(0,set_data,2);
set_data[0] = 0x0c, set_data[1] = 0x01; wiringPiSPIDataRW(0,set_data,2);
set_data[0] = 0x0f, set_data[1] = 0x00; wiringPiSPIDataRW(0,set_data,2);
set_data[0] = 0x00, set_data[1] = 0x00; wiringPiSPIDataRW(0,set_data,2);
set_data[0] = 0x00, set_data[1] = 0x00; wiringPiSPIDataRW(0,set_data,2);
set_data[0] = 0x00, set_data[1] = 0x00; wiringPiSPIDataRW(0,set_data,2);
delay(100);
/* Draw LED matrix */
int i,j;
loop:
for(i=1; i<=8; i++){
for(j=0; j<4; j++){
data[j].adr = i;
data[j].dat = 1 << (i-1);
}
wiringPiSPIDataRW(0,(unsigned char *)data,8);
}
delay(1000);
for(i=1; i<=8; i++){
for(j=0; j<4; j++){
data[j].adr = i;
data[j].dat = 0x80 >> (i-1);
}
wiringPiSPIDataRW(0,(unsigned char *)data,8);
}
delay(1000);
goto loop;
}
|