// DvalleyElectronics sharing knowledge for public domain // Emanuel Cesar Dec/2018 #define NOP asm("nop") #define BLACK PORTB = B00000000; #define BLUE PORTB = B00000001; #define GREEN PORTB = B00000010; #define CYAN PORTB = B00000011; #define RED PORTB = B00000100; #define MAGENTA PORTB = B00000101; #define YELLOW PORTB = B00000110; #define WHITE PORTB = B00000111; unsigned int counterlines = 1; void setup() { //Sets pins 5, 6 , 7 ,8 and 9 outputs // 7 - HSYNC // 6 - VSYNC // 5 - R // 8 - G // 9 - B DDRD |= B11100000; DDRB |= B11100111; PORTD |= B11000000; //set timer TCCR2A = 0x02; // WGM22=0 + WGM21=1 + WGM20=0 = Mode2 (CTC) TCCR2B |= (1 << CS20); // TCCR2B |= (1 << CS21); // Sets prescaler TCCR2B &= ~(1 << CS22); // TCNT2 = 0; // clear th counter //OCR2A = 0x03; // sets counter to comp TIMSK2 &= ~(1< 0x0f){ delayMicroseconds(1); NOP;NOP;NOP;NOP; TCNT2 = 0x00; // #### HSYNC ### PORTD &= ~(1 << 7); if (++counterlines >= 525){ // 525 OR 625 scan lines... just 483 lines can be seen counterlines = 1; } PORTD |= (1 << 7); // ### VSYNC ### if ((counterlines == 1)||(counterlines == 2)){ // 492 e 493 PORTD &= ~(1 << 6); } else { PORTD |= (1 << 6); NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; NOP;NOP;NOP;NOP;NOP; if ((counterlines >= 9) && (counterlines <= 489)){ // 2 e 482 WHITE; delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; BLACK; delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; BLUE; delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; GREEN; delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; CYAN; delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; RED; delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; MAGENTA; delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; YELLOW; delayMicroseconds(3);NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; BLACK; NOP;NOP;NOP;NOP; } } } }while(1); }