Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 6de51f3c39
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 193 lines (161 sloc) 3.397 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <util/delay.h>

#include "main.h"
#include "timer.h"
#include "TWI_Slave.h"
#include "leds.h"
#include "spi.h"


// BLANC == PB2
// XLAT == PB1
// SCLK == SCK/PB5
// SIN == MOSI/PB3
// MODE == PD5
// XERR == PD2
// SOUT == MISO/PB4
// GSCLK == PB0


int main (void)
{

// set mosi/sck output
DDRB |= (1<<DDB5)|(1<<DDB3)|(1<<DDB2);

//latch output
DDRB |= (1<<DDB1);
//blank output
DDRD |= (1<<DDD7);
//mode output
DDRD |= (1<<DDD5);

// latch off
PORTB &= ~(1<<PORTB1);
// blank = high (all off)
PORTD |= (1<<PORTD7);
// mode = ground
PORTD &= ~(1<<PORTD5);


SPI_Init();
TIMER1_Init();
sei ();



SetDC(0,63,63,63);
SetLed(0,0,0,0);

// address
uint8_t addr = ADDR;

//inital strobe for address identifiction
for(uint8_t j=0;j < (addr-1);j++)
{
for(uint8_t i = 0;i<5;i++)
{
if(i!=0) SetLed(i,0,0,0);
SetLed(i+1,0,0,0);
_delay_ms(10);
}
}
for(uint8_t i = 0;i<5;i++)
{
if(i!=0) SetLed(i,0,0,0);
SetLed(i+1,255,255,255);
_delay_ms(10);
}
SetLed(0,0,0,0);


// all slaves listen to addr 2
TWIS_Init(2, 210526);

uint8_t pixel = 0;
uint8_t module = 0;

uint8_t TWIS_ResonseType;

uint8_t temp_r = 0;
uint8_t temp_g = 0;
uint8_t temp_b = 0;

uint8_t led_1_r = 0;
uint8_t led_1_g = 0;
uint8_t led_1_b = 0;
uint8_t led_2_r = 0;
uint8_t led_2_g = 0;
uint8_t led_2_b = 0;
uint8_t led_3_r = 0;
uint8_t led_3_g = 0;
uint8_t led_3_b = 0;
uint8_t led_4_r = 0;
uint8_t led_4_g = 0;
uint8_t led_4_b = 0;
uint8_t led_5_r = 0;
uint8_t led_5_g = 0;
uint8_t led_5_b = 0;


while(1)
{
if (TWIS_ResonseRequired (&TWIS_ResonseType))
{
switch (TWIS_ResonseType)
{
case TWIS_ReadBytes:

module = TWIS_ReadAck();

if(module == 255)
{
for(uint8_t n=0;n<3;n++)
{
for(uint8_t i=0;i<5;i++)
{
for(uint8_t m=0;m<16;m++)
{
temp_r = TWIS_ReadAck();
temp_g = TWIS_ReadAck();
temp_b = TWIS_ReadAck();


if( (ADDR-1) == n*16+m )
{

if(i == 0)
{
led_1_r = temp_r;
led_1_g = temp_g;
led_1_b = temp_b;
}
if(i == 1)
{
led_2_r = temp_r;
led_2_g = temp_g;
led_2_b = temp_b;
}
if(i == 2)
{
led_3_r = temp_r;
led_3_g = temp_g;
led_3_b = temp_b;
}
if(i == 3)
{
led_4_r = temp_r;
led_4_g = temp_g;
led_4_b = temp_b;
}
if(i == 4)
{
led_5_r = temp_r;
led_5_g = temp_g;
led_5_b = temp_b;
}
}
}
}
}

module = TWIS_ReadNack();
SetLed(1,led_1_r,led_1_g,led_1_b);
SetLed(2,led_2_r,led_2_g,led_2_b);
SetLed(3,led_3_r,led_3_g,led_3_b);
SetLed(4,led_4_r,led_4_g,led_4_b);
SetLed(5,led_5_r,led_5_g,led_5_b);

TWIS_Stop();
}
else
{
pixel = TWIS_ReadAck();
uint8_t red = TWIS_ReadAck();
uint8_t green = TWIS_ReadAck();
uint8_t blue = TWIS_ReadNack();
if((module == ADDR)||(module == 0))
{
SetLed(pixel,red,green,blue);
}
TWIS_Stop();
}

break;
}
}
}
}
Something went wrong with that request. Please try again.