//video gen //D.5 is sync:1000 ohm + diode to 75 ohm resistor //D.6 is video:330 ohm + diode to 75 ohm resistor #include #define lineTime 507 //cycles = 63.5 * 8 #define begin { #define end } #define ScreenTop 30 #define ScreenBot 230 char syncON, syncOFF, v1, v2, v3, v4, v5, v6, v7, v8; int i,LineCount; //#pragma regalloc- //register char temp @16; //#pragma regalloc+ int j; char screen[800]; flash char bitmap[8]={ 0b00000000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00111000}; interrupt [TIM1_COMPA] void t1_cmpA(void) begin //start the Horizontal sync pulse PORTD = syncON; //count timer 0 at 1/usec TCNT0=0; //update the curent scanline number LineCount ++ ; //begin inverted synch after line 247 if (LineCount==248) begin syncON = 0b00100000; syncOFF = 0; end //back to regular sync after line 250 if (LineCount==251) begin syncON = 0; syncOFF = 0b00100000; end //start new frame after line 262 if (LineCount==263) begin LineCount = 1; end //end sync pulse PORTD = syncOFF; end void main(void) begin //init timer 1 to generate sync OCR1A = lineTime; //One NTSC line TCCR1B = 9; //full speed; clear-on-match TCCR1A = 0x00; //turn off pwm and oc lines TIMSK = 0x10; //enable interrupt //init ports DDRD = 0xf0; //video out and switches //D.5 is sync:1000 ohm + diode to 75 ohm resistor //D.6 is video:330 ohm + diode to 75 ohm resistor //init timer 0 to 1/uSec TCCR0 = 2; //initialize synch constants LineCount = 1; syncON = 0b00000000; syncOFF = 0b00100000; //initialize screen for (i=0;i<799;i=i+16) begin for(j=0;j<8;j=j+1) begin screen[i+j]=0b10101010; end for(j=0;j<8;j=j+1) begin screen[i+j+8]=0b01010101; end end //top line for (i=0;i<8;i++) begin //screen[i+8]=0b11111111; //screen[i+32]=0b11111111; //screen[i+256]=0b11111111; end MCUCR = 0b01000000; #asm ("sei"); while(1) begin //precompute pixel index for next line if (LineCount=ScreenTop) begin //left-shift 3 would be individual lines // <<2 means line-double the pixels i=(LineCount-ScreenTop)<<2 & 0xfff8; end //stall here until next line starts //sleep enable; mode=idle //use sleep to make entry into sync ISR uniform time #asm ("sleep"); //Put code here to execute once/line //During the active portion of a line; //--TCNT1 goes from about 130 to about 480 //--Usable lines 1 to about 240 if (LineCountScreenTop) begin //load the pixels into registers v1 = screen[i]; v2 = screen[i+1]; v3 = screen[i+2]; v4 = screen[i+3]; v5 = screen[i+4]; v6 = screen[i+5]; v7 = screen[i+6]; v8 = screen[i+7]; //now blast them out to the screen PORTD.6=v1 & 0b10000000; PORTD.6=v1 & 0b01000000; PORTD.6=v1 & 0b00100000; PORTD.6=v1 & 0b00010000; PORTD.6=v1 & 0b00001000; PORTD.6=v1 & 0b00000100; PORTD.6=v1 & 0b00000010; PORTD.6=v1 & 0b00000001; PORTD.6=v2 & 0b10000000; PORTD.6=v2 & 0b01000000; PORTD.6=v2 & 0b00100000; PORTD.6=v2 & 0b00010000; PORTD.6=v2 & 0b00001000; PORTD.6=v2 & 0b00000100; PORTD.6=v2 & 0b00000010; PORTD.6=v2 & 0b00000001; PORTD.6=v3 & 0b10000000; PORTD.6=v3 & 0b01000000; PORTD.6=v3 & 0b00100000; PORTD.6=v3 & 0b00010000; PORTD.6=v3 & 0b00001000; PORTD.6=v3 & 0b00000100; PORTD.6=v3 & 0b00000010; PORTD.6=v3 & 0b00000001; PORTD.6=v4 & 0b10000000; PORTD.6=v4 & 0b01000000; PORTD.6=v4 & 0b00100000; PORTD.6=v4 & 0b00010000; PORTD.6=v4 & 0b00001000; PORTD.6=v4 & 0b00000100; PORTD.6=v4 & 0b00000010; PORTD.6=v4 & 0b00000001; PORTD.6=v5 & 0b10000000; PORTD.6=v5 & 0b01000000; PORTD.6=v5 & 0b00100000; PORTD.6=v5 & 0b00010000; PORTD.6=v5 & 0b00001000; PORTD.6=v5 & 0b00000100; PORTD.6=v5 & 0b00000010; PORTD.6=v5 & 0b00000001; PORTD.6=v6 & 0b10000000; PORTD.6=v6 & 0b01000000; PORTD.6=v6 & 0b00100000; PORTD.6=v6 & 0b00010000; PORTD.6=v6 & 0b00001000; PORTD.6=v6 & 0b00000100; PORTD.6=v6 & 0b00000010; PORTD.6=v6 & 0b00000001; PORTD.6=v7 & 0b10000000; PORTD.6=v7 & 0b01000000; PORTD.6=v7 & 0b00100000; PORTD.6=v7 & 0b00010000; PORTD.6=v7 & 0b00001000; PORTD.6=v7 & 0b00000100; PORTD.6=v7 & 0b00000010; PORTD.6=v7 & 0b00000001; PORTD.6=v8 & 0b10000000; PORTD.6=v8 & 0b01000000; PORTD.6=v8 & 0b00100000; PORTD.6=v8 & 0b00010000; PORTD.6=v8 & 0b00001000; PORTD.6=v8 & 0b00000100; PORTD.6=v8 & 0b00000010; PORTD.6=v8 & 0b00000001; PORTD.6=0 ; end //following code executes during the vertical blanking //Code here can be as long as 63 uSec/line //20 lines x 63.5 uSec/line x 8 cycles/uSec // if (LineCount>170 && LineCount<178) // begin // i=LineCount-170; // end if (LineCount==243) begin end //if (LineCount==243) end //while end //main