Skip to content

Instantly share code, notes, and snippets.

@taylanpince
Created December 21, 2014 13:32
Show Gist options
  • Save taylanpince/01e701dca986648de364 to your computer and use it in GitHub Desktop.
Save taylanpince/01e701dca986648de364 to your computer and use it in GitHub Desktop.
Arduino OV7670 Port Register Integration
#include <avr/io.h>
#include <avr/interrupt.h>
static inline void serialWrB(uint8_t dat){
while(!( UCSR0A & (1<<UDRE0))); //wait for byte to transmit
UDR0=dat;
while(!( UCSR0A & (1<<UDRE0))); //wait for byte to transmit
}
static void StringPgm(char * str){
do {
serialWrB(pgm_read_byte_near(str));
} while(pgm_read_byte_near(++str));
}
void setup() {
cli();
// TODO: These need to be cleaned up to make sense, using 15 and 252 is unacceptable
DDRC &= ~15; // low d0-d3 camera
DDRD &= ~252; // d7-d4 and interrupt pins
delay(3000);
// TODO: These need to be commented and cleaned when I understand them
UBRR0H=0;
UBRR0L=207;//0 = 2M baud rate. 1 = 1M baud. 3 = 0.5M. 7 = 250k 207 is 9600 baud rate.
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
StringPgm(PSTR("READY\n"));
// Just loop
while (1) {
captureImg(320, 120);
}
}
static void captureImg(uint16_t wg, uint16_t hg) {
uint16_t lg2;
StringPgm(PSTR("===========CAPTURE_BEGIN===========\n"));
while(!(PIND & B00001000)); // Wait for high VSYNC
while((PIND & B00001000)); // Wait for low VSYNC
while(hg--) {
lg2 = wg;
while(lg2--) {
while((PIND & B00000100)); // Wait for low HREF
// Attempt to read D0-D7 values one by one (I have no idea what I am doing here)
// Results in NUL values all the time
UDR0 = (PINC & B00000001);
UDR0 = (PINC & B00000010);
UDR0 = (PINC & B00000100);
UDR0 = (PINC & B00001000);
UDR0 = (PIND & B00010000);
UDR0 = (PIND & B00100000);
UDR0 = (PIND & B01000000);
UDR0 = (PIND & B10000000);
while(!(PIND & B00000100)); // Wait for high HREF
}
}
StringPgm(PSTR("\n===========CAPTURE_DONE===========n"));
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment