Exemplo n.º 1
0
__attribute__((noreturn)) void main(void){
	cli();
	//set-up serial communications
	DDRD=28;//3 serial pins on d.2 to d.4 d.5 to d.7 contain msbs for flash data d.0 to d.4 is in port C
	DDRB=62;//serial clocks (B.1 SHCP) (B.2 Latch) (B.3 CE#) (B.4 OE#) (B.5 WE#)
	UBRR0H=0;
	UBRR0L=3;//set to 0.5M baud
	UCSR0A|=2;//double speed aysnc
	UCSR0B = (1<<RXEN0)|(1<<TXEN0);//Enable receiver and transmitter
	UCSR0C=6;//async 1 stop bit 8bit char no parity bits
	_delay_ms(50);
	StringPgm(PSTR("RDY"));
	USART_Receive();//wait for handshake
	char mode = USART_Receive();//wait for mode
	StringPgm(PSTR("RDY"));
	serialWrB(readId(0));
	uint8_t cap=readId(1);
	serialWrB(cap);
	__uint24 capacity=524288L;
	switch(cap){
		case 0xB5:
			capacity=131072L;
		case 0xB6:
			capacity=262144L;
		break;
	}
	if(mode=='W'){
		chipErase();
		serialWrB('D');
		verifyF(capacity);
		__uint24 x;
		for (x=0;x<capacity;++x){
			pgmB(x,USART_Receive());
			serialWrB(readB(x));
		}
	}else if(mode=='R')
		ReadChip(capacity);
	while(1);
}
Exemplo n.º 2
0
static void captureImg(uint16_t wg,uint16_t hg){
	uint16_t lg2;
#ifdef useQvga
	uint8_t buf[640];
#elif defined(useQqvga)
	uint8_t buf[320];
#endif
	StringPgm(PSTR("RDY"));
	//Wait for vsync it is on pin 3 (counting from 0) portD
	while(!(PIND&8));//wait for high
	while((PIND&8));//wait for low
#ifdef useVga
	while(hg--){
		lg2=wg;
		while(lg2--){
			while((PIND&4));//wait for low
			UDR0=(PINC&15)|(PIND&240);
			while(!(PIND&4));//wait for high
		}
	}
#elif defined(useQvga)
	/*We send half of the line while reading then half later */
	while(hg--){
		uint8_t*b=buf,*b2=buf;
		lg2=wg/2;
		while(lg2--){
			while((PIND&4));//wait for low
			*b++=(PINC&15)|(PIND&240);
			while(!(PIND&4));//wait for high
			while((PIND&4));//wait for low
			*b++=(PINC&15)|(PIND&240);
			UDR0=*b2++;
			while(!(PIND&4));//wait for high
		}
		/* Finish sending the remainder during blanking */
		lg2=wg/2;
		while(!( UCSR0A & (1<<UDRE0)));//wait for byte to transmit
		while(lg2--){
			UDR0=*b2++;
			while(!( UCSR0A & (1<<UDRE0)));//wait for byte to transmit
		}
	}
#else
	/* This code is very similar to qvga sending code except we have even more blanking time to take advantage of */
	while(hg--){
		uint8_t*b=buf,*b2=buf;
		lg2=wg/5;
		while(lg2--){
			while((PIND&4));//wait for low
			*b++=(PINC&15)|(PIND&240);
			while(!(PIND&4));//wait for high
			while((PIND&4));//wait for low
			*b++=(PINC&15)|(PIND&240);
			while(!(PIND&4));//wait for high
			while((PIND&4));//wait for low
			*b++=(PINC&15)|(PIND&240);
			while(!(PIND&4));//wait for high
			while((PIND&4));//wait for low
			*b++=(PINC&15)|(PIND&240);
			while(!(PIND&4));//wait for high
			while((PIND&4));//wait for low
			*b++=(PINC&15)|(PIND&240);
			UDR0=*b2++;
			while(!(PIND&4));//wait for high
		}
		/* Finish sending the remainder during blanking */
		lg2=320-(wg/5);
		while(!( UCSR0A & (1<<UDRE0)));//wait for byte to transmit
		while(lg2--){
			UDR0=*b2++;
			while(!( UCSR0A & (1<<UDRE0)));//wait for byte to transmit
		}
	}
#endif
}