TCM8240MD

TCM8240MD Camera Project

800

main.cpp

#include "mbed.h"


LocalFileSystem local("local"); 
I2C             i2c(p9, p10);
Serial          pc(USBTX, USBRX);

int zahl = 0;
FILE *fp = fopen("/local/bild.txt", "w");
char array[100][320]; //not enough memory
int j = 0;
int wert;
#define x 100 
#define y 320

void setCam(char c1,char c2);

extern "C" void EINT3_IRQHandler() {
  //  wert = LPC_GPIO0->FIOPIN; 
  //  wert = bus.read();
   LPC_GPIOINT->IO2IntClr |= (1<<3);
   int i = LPC_GPIO2->FIOPIN;
   
   if((i & 0x30) == 0x30) {
       wert = LPC_GPIO0->FIOPIN;
     //fprintf(fp,"%c",(wert & ((1 <<26)|(1 <<25)|(1 <<24)|(1 <<23)))>> 19 | (wert & (1 <<18)) >> 18 | ((wert & (1 <<17)) >> 16 | ((wert & (1 <<16)) >> 13 | (wert & (1 <<15)) >> 13)));
     
       array[j][zahl] = ((wert & ((1 <<26)|(1 <<25)|(1 <<24)|(1 <<23)))>> 19 | (wert & (1 <<18)) >> 18 | ((wert & (1 <<17)) >> 16 | ((wert & (1 <<16)) >> 13 | (wert & (1 <<15)) >> 13)));
     
       zahl++;
        
       
    }
    if(zahl == y){
      zahl = 0;   
      j++;
    }   
    if(j == x){
        // setCam(0x04,0x8B);
         NVIC_DisableIRQ(EINT3_IRQn);  
         for(int i = 0;i < x; i++){
           // pc.printf("%i      ",(i+1)); 
            for(int j = 0;j < y; j++)
              fprintf(fp,"%x ",array[i][j]); 
            fprintf(fp,"\n\r\n"); 
         }
         zahl = 0;
         j=0;
       //   setCam(0x04,0x0B);
         NVIC_EnableIRQ(EINT3_IRQn);     
    }

}

void setCam(char c1,char c2) {
    int i = 1;
    int address = 122;
    char data[2];
    data[0] = c1;
    data[1] = c2;
    i2c.start();
    while (i != 0) {
        i = i2c.write(address, data,sizeof(data));
    //    pc.printf("%i\n\r",i);

    }
 //   pc.printf("\n\r");
}






int main() {
    pc.baud(921600);
 //  LPC_SC->PCONP |= ( 1 << 15 ); // power up GPIO
   // LPC_PINCON->PINSEL4 = 0x000    ;
    
    
    LPC_PINCON->PINMODE4 = 0xFC0;
    LPC_GPIO2->FIODIR &= ~(1 << 3)|(1 << 4)|(1 << 5); //p21,p22,p23 input mode
    
    // LPC_GPIO1->FIODIR &= ~(1 << 30)|(1 << 31);//p20,p19 input mode
     LPC_GPIO0->FIODIR &= ~(1 << 26)|(1 << 25)|(1 << 24)|(1 << 23)|(1 << 16)|(1 << 15)|(1 << 17)|(1 << 18);//input mode p18-p11
     int speicher = LPC_PINCON->PINMODE1;
     LPC_PINCON->PINMODE1 = (speicher | 0x3FC03F);
     speicher = LPC_PINCON->PINMODE0;
     LPC_PINCON->PINMODE0 = (speicher | 0xC0000000);
   //-----------Interrupt---------------
    LPC_GPIOINT->IO2IntEnF |= (1<<3);   
  
    setCam(0x02,0x00);
   //   wait(0.1);
    setCam(0x02,0x40);
   // wait(0.1);
    setCam(0x03,0x00);
    setCam(0x02,0x00);
   
   
    setCam(0x05,0x00);
    setCam(0x0B,0x00);
    setCam(0x58,0x20);
   
    //setCam(0x6d,0xa1);
   // setCam(0x58,0x10);
    //setCam(0x1D,0x1F);


     setCam(0x1a,0xFF);
     setCam(0x1b,0xB3);
     setCam(0x1C,0xA1);
  
     setCam(0x11,0x4A);
     setCam(0x14,0x23);
     setCam(0x1f,0x0F);
     setCam(0x1e,0x23);
     setCam(0x0e,0x00);
     setCam(0x04,0x0B);//0d     

    NVIC_EnableIRQ(EINT3_IRQn);   
  
    
    while(true){
    
    }
    //Enable GPIO interrupt  P0.25/AD0.2   
}


Please log in to post comments.