#define RED 0 #define GREEN 1 #define BLUE 2 #include #include #include "screens.h" #include "old_funcs.h" void upd_all(char r, char c, unsigned char color); unsigned char simple_colors[8][3] = { {0,0,0}, {TOTAL,0,0}, {TOTAL,10,0}, {TOTAL,100,0}, {0,TOTAL,0}, {0,0,TOTAL}, {TOTAL,0,TOTAL-20}, {TOTAL,TOTAL,TOTAL-20}}; unsigned char secs,mins,hrs=0; unsigned char sec_col,min_col,hr_col; const unsigned char points[6][2]={{2,1},{1,1},{0,1},{2,0},{1,0},{0,0}}; /* //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 char select_row_column_test(const unsigned char r, const unsigned char c, const unsigned char color){ unsigned char intensity = data[r][c][color]; if(intensity == 0){ _delay_loop_1(TOTAL); return 0; } PORTA = (1 << (7-r)); switch(color){ case RED: PORTB = (1 << (7-c)); break; case GREEN: PORTC = (1 << (7-c)); break; case BLUE: PORTD = (1 << (7-c)); break; } delay(intensity); } */ void delay(unsigned char intensity){ if(intensity > 0){ //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 if(intensity > TOTAL) intensity = TOTAL; _delay_loop_1(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 if(TOTAL - intensity != 0) _delay_loop_1(TOTAL-intensity); } void init_bclock(){ sec_col=c_blu; min_col=c_blu+(c_g << 3); hr_col=c_blu+(c_r << 3); secs=0; mins=15; hrs=13; upd_pixels(0,hrs,hr_col); upd_pixels(3,mins,min_col); upd_pixels(6,secs,sec_col); } void upd_time(){ secs++; if(secs == 60){ mins++; secs=0; if(mins == 60){ hrs++; mins=0; if(hrs == 24){ hrs = 0; } upd_pixels(0,hrs,hr_col); } upd_pixels(3,mins,min_col); } upd_pixels(6,secs,sec_col); } void upd_pixels(char x_offs,unsigned char val,unsigned char colors){ //goes LSB to MSB // const unsigned char* points[6][2]={{7,7},{6,7},{5,7},{7,6},{6,6},{5,6}}; unsigned char i; for(i=0;i<=5;i++){ if(val & 0x01 << i){ upd_all(points[i][0]+5,points[i][1]+x_offs,colors&0x07); } else { upd_all(points[i][0]+5,points[i][1]+x_offs,colors>>3); } } } void color_display(unsigned char r, unsigned char c, unsigned char color){ unsigned char* intensity = simple_colors[color]; if(intensity[0] != 0){ PORTA = (1 << (7-r)); PORTB = (1 << (7-c)); } else { PORTA = 0; PORTB = 0; } delay(intensity[0]); if(intensity[1] != 0){ PORTA = (1 << (7-r)); PORTC = (1 << (7-c)); } else { PORTA = 0; PORTC = 0; } delay(intensity[1]); if(intensity[2] != 0){ PORTA = (1 << (7-r)); PORTD = (1 << (7-c)); } else { PORTA = 0; PORTD = 0; } delay(intensity[2]); }