/* Name: main.c * Author: Stephen Hansen */ #include #include #define RED 0 #define GREEN 1 #define BLUE 2 unsigned char data[8][8][3] = { {{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}}, {{255,128,0}, {255,128,0}, {255,128,0}, {255,128,0}, {255,128,0}, {255,128,0}, {255,128,0}, {255,128,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {255,255,0}, {255,255,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {128,255,0}, {128,255,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,255,0}, {0,255,0}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,255,128}, {0,255,128}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,255,255}, {0,255,255}, {0,0,0}, {0,0,0}, {0,0,0}}, {{0,0,0}, {0,0,0}, {0,0,0}, {0,128,255}, {0,128,255}, {0,0,0}, {0,0,0}, {0,0,0}}}; void select_row_column_test(const unsigned char r, const unsigned char c, const unsigned char color); void delay(const unsigned char intensity, const unsigned char total); void delay_time(const unsigned char length); int main(void) { DDRA = 0xFF; DDRB = 0xFF; DDRC = 0xFF; DDRD = 0xFF; PORTA = 0x00; //row select (all off) PORTB = 0x00; //red PORTC = 0x00; //green PORTD = 0x00; //blue char r, c, color = 0; /* insert your hardware initialization here */ for(;;){ for(r = 0; r <= 7; r++){ for(c = 0; c <= 7; c++){ for(color = 0; color <= 2; color++){ select_row_column_test(r,c,color); } } } } return 0; /* never reached */ } //r is 0-7 for row 0-7, c is 0-7 for column 0-7, color is 0-2 for red, green, blue respectively void select_row_column_test(const unsigned char r, const unsigned char c, const unsigned char color){ PORTA = (1 << (7-r)); if(color > 0){ switch(color){ case RED: PORTB = (1 << (7-c)); break; case GREEN: PORTC = (1 << (7-c)); break; case BLUE: PORTD = (1 << (7-c)); break; } } unsigned char intensity = data[(short)r][(short)c][(short)color]; delay(intensity,255); } void delay(const unsigned char intensity, const unsigned char total){ //clock frequency = 8 MHz, min frequency for 60 Hz = 3 MHz, trying software approach first, timers will come later with interrupts. // unsigned int i; //leaving LED on for as long as was specified delay_time(intensity); PORTA = 0x00; //turn off all row power (done with this intensity level) //turning off all columns as well PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; //waiting a while before running to next LED delay_time(total-intensity); } void delay_time(const unsigned char length){ unsigned int i; unsigned int max = (unsigned int)(length); max <<= 5;; for(i=0;i