#include #include #include #define LMG6202_DATA_PORT PORTD #define LMG6202_CONTROL_PORT PORTD #define LMG6202_PIN_CP (1 << 4) #define LMG6202_PIN_LD (1 << 5) #define LMG6202_PIN_DR (1 << 6) #define LMG6202_PIN_DF (1 << 7) int main() { int i; int col = 0; uint16_t it = 0; UCSR0B = 0x00; DDRD = 0xff; PORTD = 0xff; _delay_ms(500); while (1) { // VSYNC pulse if (col == 1) { LMG6202_CONTROL_PORT |= LMG6202_PIN_DR; LMG6202_CONTROL_PORT ^= LMG6202_PIN_DF; // _delay_us(1); } else { LMG6202_CONTROL_PORT &= ~LMG6202_PIN_DR; } // Latch data LMG6202_CONTROL_PORT |= LMG6202_PIN_LD; asm("nop");asm("nop");asm("nop"); LMG6202_CONTROL_PORT &= ~LMG6202_PIN_LD; //LMG6202_CONTROL_PORT ^= LMG6202_PIN_DF; _delay_us(1); for (i = 0; i < 120; ++i) { LMG6202_CONTROL_PORT |= LMG6202_PIN_CP; if (it > 2500 && i > 60) { //if (i == 0) { LMG6202_DATA_PORT |= 15; //} } else { LMG6202_DATA_PORT &= ~(15); } //asm("nop"); LMG6202_CONTROL_PORT &= ~LMG6202_PIN_CP; asm("nop"); } LMG6202_DATA_PORT &= ~(15); // LMG6202_CONTROL_PORT &= ~LMG6202_PIN_DR; if (col == 127) { col = 0; } else { col++; } if (it==5000) { it = 0; } else { it++; } } }