User Tools

Site Tools


octobrite_on_attiny84_with_hw_spi

This is an old revision of the document!


#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
 
#define datapin 5
#define latchpin 0
#define enablepin 1
#define clockpin 4
 
#define NumLEDs 8
int LEDChannels[NumLEDs][3];
 
void USI_ShiftOut(int SendInt) {
 
	USIDR = SendInt >> 4;
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 11
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 10
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 9
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 8
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
	USIDR = SendInt;
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 7
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 6
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 5
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 4
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 3
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 2
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 1
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USITC); // 0
	USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
 
}
 
void Octo_SendPacket(int OB_RedCommand, int OB_GreenCommand, int OB_BlueCommand) {
 
   USI_ShiftOut(OB_BlueCommand);
 
   USI_ShiftOut(OB_GreenCommand);
 
   USI_ShiftOut(OB_RedCommand);
 
}
 
void WriteLEDArray() {
 
   for (int h = 0;h<NumLEDs;h++) {
       Octo_SendPacket(LEDChannels[7-h][0], LEDChannels[7-h][1], LEDChannels[7-h][2]);
   }
 
		//_delay_ms(0.1);
		PORTA |= (1 << latchpin);
   		PORTA |= (1 << enablepin);
		//_delay_ms(0.1);
		PORTA &= ~(1 << enablepin);
		PORTA &= ~(1 << latchpin);
 
}
 
void paintall (int red, int green, int blue) {
 
	for (int LEDindex = 0; LEDindex < NumLEDs; LEDindex++) {
		LEDChannels[LEDindex][0] = blue;
		LEDChannels[LEDindex][1] = green;
		LEDChannels[LEDindex][2] = red;
	}
 
	WriteLEDArray();
 
}
 
int main(void) {
 
	DDRA |= (1 << datapin)|(1 << latchpin)|(1 << enablepin)|(1 << clockpin);
 
	PORTA &= ~((1 << latchpin)|(1 << enablepin)|(1 << clockpin));
 
	while(1) {
 
		paintall(4095,0,0);
 
		__delay_ms(100);
 
		paintall(0,4095,0);
 
		__delay_ms(100);
 
		paintall(0,0,4095);
 
		__delay_ms(100);
 
	}
 
}
/home/macetec/public_html/docs/data/attic/octobrite_on_attiny84_with_hw_spi.1287730834.txt.gz · Last modified: 2010/10/22 03:00 by macegr