Moin!
Hier die Fortsetzung aus dem Elektronik-thread...
Dieser Code erzeugt Bild1:
Das Bild wird erst komplett eingelesen und anschließend aus dem RAM per RS232 ausgegeben.
Und hier werden die Bytes direkt von der Kamera per RS232 gesendet (Bild2);Code:void getpic() { uint16_t cnt; uint8_t cnt2; unsigned char data; unsigned int addr; uart_putc(0); addr=0; for (cnt=0;cnt<1024;cnt++) { i2c_start_wait(Dev24C02+I2C_WRITE); // set device address and write mode if (i2c_write(5)==0) //update gb_cam buffer { i2c_start_wait(Dev24C02+I2C_READ); for (cnt2=0;cnt2<15;cnt2++) { data = i2c_readAck(); writemem(addr,data); // uart_putc(data); addr++; } data = i2c_readNak(); writemem(addr,data); // uart_putc(data); addr++; } } for (addr=0;addr<=16384;addr++) { data=readmem(addr); uart_putc(data); } }
und hier nochmal die Funktionen für das Ram :Code:void getpic() { uint16_t cnt; uint8_t cnt2; unsigned char data; unsigned int addr; uart_putc(0); addr=0; for (cnt=0;cnt<1024;cnt++) { i2c_start_wait(Dev24C02+I2C_WRITE); // set device address and write mode if (i2c_write(5)==0) //update gb_cam buffer { i2c_start_wait(Dev24C02+I2C_READ); for (cnt2=0;cnt2<15;cnt2++) { data = i2c_readAck(); //writemem(addr,data); uart_putc(data); addr++; } data = i2c_readNak(); //writemem(addr,data); uart_putc(data); addr++; } } /* for (addr=0;addr<=16384;addr++) { data=readmem(addr); uart_putc(data); }*/ }
Code:#include <memory.h> #include <util/delay.h> #define r 1 #define w 1 void initinterface(unsigned char value) { DDRA=0; PORTA=0; DDRB |= 15; PORTB |= (1<<WE); PORTB |= (1<<OE); PORTB &= ~(1<<LE_low); PORTB &= ~(1<<LE_high); } void writemem(unsigned int addr, unsigned char value) { PORTB |= (1<<WE); //WE auf high PORTB |= (1<<OE); //OE auf high DDRA=0xff; //PORTA als Ausgang PORTA = (addr & 255); //Lowbyte der Adresse ausgeben PORTB |= (1<<LE_low); //Latch 2 input enable PORTB &= ~(1<<LE_low); //Latch 2 input disable _delay_us(w); PORTA = (addr / 256); //Highbyte der Adresse ausgeben PORTB |= (1<<LE_high); //Latch 1 input enable PORTB &= ~(1<<LE_high); //Latch 1 input disable _delay_us(w); PORTA = value; //Daten ausgeben PORTB &= ~(1<<WE); //WE auf low _delay_us(w); PORTB |= (1<<WE); //WE auf high DDRA=0x00; PORTA=0x00; } unsigned char readmem(unsigned int addr) { unsigned char value; PORTB |= (1<<WE); //WE auf high PORTB |= (1<<OE); //OE auf high DDRA=0xff; //PORTA als Ausgang PORTA = (addr & 255); //Lowbyte der Adresse ausgeben PORTB |= (1<<LE_low); //Latch 2 input enable PORTB &= ~(1<<LE_low); //Latch 2 input disable _delay_us(r); PORTA = (addr / 256); //Highbyte der Adresse ausgeben PORTB |= (1<<LE_high); //Latch 1 input enable PORTB &= ~(1<<LE_high); //Latch 1 input disable _delay_us(r); DDRA = 0; PORTA = 0; PORTB &= ~(1<<OE); //OE auf low _delay_us(r); value = PINA; //Daten lesen nach 'value' PORTB |= (1<<OE); //OE auf high return value; }
Lesezeichen