for use with ATtiny devices:
#include #include
#define bit_get(p,m) ((p) & (m)) #define bit_set(p,m) ((p) |= (m)) #define bit_clear(p,m) ((p) &= ~(m)) #define bit_flip(p,m) ((p) ^= (m)) #define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m)) #define BIT(x) (0x01 << (x)) #define LONGBIT(x) ((unsigned long)0x00000001 << (x)) #define NOP asm("nop")
#define E_S bit_set(PORTA,BIT(0)); #define E_C bit_clear(PORTA,BIT(0)); //OE is active low, this turns lights on
#define L_S bit_set(PORTA,BIT(1)); #define L_C bit_clear(PORTA,BIT(1));
#define LED_OFF bit_clear(PORTA,BIT(7)); #define LED_ON bit_set(PORTA,BIT(7));
#define shift USICR|=(1<24) & 0xff); shft8bit((packet>>16) & 0xff); shft8bit((packet>>8) & 0xff); shft8bit((packet>>0) & 0xff); L_S; _delay_us(40); L_C; }
void LED_setup(void) { shft8bit(0b11111111); shft8bit(0b11111111); shft8bit(0b11111111); shft8bit(0b00111111); L_S; _delay_us(40); L_C; }
void Blue(void) { // blue shft8bit(0b10111111); shft8bit(0b11110000); shft8bit(0b00000000); shft8bit(0b00000000); L_S; _delay_us(40); L_C; }
void Red(void) { // red shft8bit(0b10000000); shft8bit(0b00001111); shft8bit(0b11111100); shft8bit(0b00000000); L_S; _delay_us(40); L_C; }
void Green(void) { // green shft8bit(0b10000000); shft8bit(0b00000000); shft8bit(0b00000011); shft8bit(0b11111111); L_S; _delay_us(40); L_C; }
void Clear(void) { // green shft8bit(0b10000000); shft8bit(0b00000000); shft8bit(0b00000000); shft8bit(0b00000000); L_S; _delay_us(40); L_C; }
void Delay(void) { _delay_ms(40); }
int main (void) { E_S; Delay(); Port_setup(); LED_setup(); Clear(); Clear(); E_C; LED_ON; for(;;) { int y=0; for(int i=1023;i>0;i--) { y++; colors(i,y,0); Delay(); } y=0; for(int i=1023;i>0;i--) { y++; colors(0,i,y); Delay(); } y=0; for(int i=1023;i>0;i--) { y++; colors(y,0,i); Delay(); } } }
More information about formatting options
for use with ATtiny
for use with ATtiny devices:
#include
#include
#define bit_get(p,m) ((p) & (m))
#define bit_set(p,m) ((p) |= (m))
#define bit_clear(p,m) ((p) &= ~(m))
#define bit_flip(p,m) ((p) ^= (m))
#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
#define BIT(x) (0x01 << (x))
#define LONGBIT(x) ((unsigned long)0x00000001 << (x))
#define NOP asm("nop")
#define E_S bit_set(PORTA,BIT(0));
#define E_C bit_clear(PORTA,BIT(0)); //OE is active low, this turns lights on
#define L_S bit_set(PORTA,BIT(1));
#define L_C bit_clear(PORTA,BIT(1));
#define LED_OFF bit_clear(PORTA,BIT(7));
#define LED_ON bit_set(PORTA,BIT(7));
#define shift USICR|=(1<24) & 0xff);
shft8bit((packet>>16) & 0xff);
shft8bit((packet>>8) & 0xff);
shft8bit((packet>>0) & 0xff);
L_S;
_delay_us(40);
L_C;
}
void LED_setup(void)
{
shft8bit(0b11111111);
shft8bit(0b11111111);
shft8bit(0b11111111);
shft8bit(0b00111111);
L_S;
_delay_us(40);
L_C;
}
void Blue(void)
{
// blue
shft8bit(0b10111111);
shft8bit(0b11110000);
shft8bit(0b00000000);
shft8bit(0b00000000);
L_S;
_delay_us(40);
L_C;
}
void Red(void)
{
// red
shft8bit(0b10000000);
shft8bit(0b00001111);
shft8bit(0b11111100);
shft8bit(0b00000000);
L_S;
_delay_us(40);
L_C;
}
void Green(void)
{
// green
shft8bit(0b10000000);
shft8bit(0b00000000);
shft8bit(0b00000011);
shft8bit(0b11111111);
L_S;
_delay_us(40);
L_C;
}
void Clear(void)
{
// green
shft8bit(0b10000000);
shft8bit(0b00000000);
shft8bit(0b00000000);
shft8bit(0b00000000);
L_S;
_delay_us(40);
L_C;
}
void Delay(void)
{
_delay_ms(40);
}
int main (void)
{
E_S;
Delay();
Port_setup();
LED_setup();
Clear();
Clear();
E_C;
LED_ON;
for(;;)
{
int y=0;
for(int i=1023;i>0;i--)
{
y++;
colors(i,y,0);
Delay();
}
y=0;
for(int i=1023;i>0;i--)
{
y++;
colors(0,i,y);
Delay();
}
y=0;
for(int i=1023;i>0;i--)
{
y++;
colors(y,0,i);
Delay();
}
}
}