bx-cam

Dependencies:   mbed-rtos mbed

Fork of rtos_basic by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 #include "main.h"
00004 #include "ov7670.h"
00005  
00006 
00007  
00008  /*
00009   OV7670(
00010             PinName sda,    // Camera I2C port
00011             PinName scl,    // Camera I2C port
00012             PinName vs, l8 aa    // VS YNC
00013             PinName hr,     // HREF
00014             PinName we,     // WEN
00015                       
00016             PortName port,  // 8bit bus port
00017             int mask,       // 0b0000_0M65_4000_0321_L000_0000_0000_0000 = 0x07878000
00018             
00019             PinName rt,     // /RRST
00020             PinName o,      // /OE
00021             PinName rc      // RCLK      
00022             );
00023  
00024  
00025  */
00026 
00027 
00028                                          //D7-D0
00029  OV7670 camera(PTE0,PTE1,PTD6,PTD7,PTE31,PTC17,PTC16,PTC13,PTC12,PTC6,PTC5,PTC4,PTC3,PTB8,PTB9,PTB10); 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 #define VGA     307200         //640*480
00040 #define QVGA    76800          //320*240
00041 #define QQVGA   19200          //160*120
00042  
00043 
00044 static int resolution =QQVGA ;
00045 //  char in[160][120]; 
00046  
00047 I2C i2c(PTE0, PTE1);
00048  
00049 
00050  
00051 int main() 
00052 {  
00053     pc.baud(115200);       
00054 
00055     led4 = 0;
00056 
00057 
00058 
00059 
00060 
00061 
00062                      if(camera.Init('b', QQVGA) != 1)  // Set up for 160*120 pixels YUV (Only Y)
00063                     {
00064                       pc.printf("Init Fail\r\n");
00065                     }
00066                     pc.printf("Initializing done\r\n");
00067 
00068 
00069     
00070     wait_ms(50);
00071     
00072     //register
00073     int i = 0;
00074                     pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F");
00075                     for (i=0;i<OV7670_REGMAX;i++) 
00076                     {
00077                         int data;
00078                         data = camera.ReadReg(i); // READ REG
00079                         if ((i & 0x0F) == 0) 
00080                         {
00081                             pc.printf("\r\n%02X : ",i);
00082                         }
00083                         pc.printf("%02X ",data);
00084                     }
00085                     pc.printf("\r\n");
00086    
00087     
00088     wait_ms(50);
00089     
00090     CameraSnap();
00091     
00092     
00093    
00094     
00095 }
00096   
00097 void CameraSnap()
00098 {
00099         led4 = 1;
00100     //   pc.printf("++++++++++++++++++++++++++++++");
00101                 // Kick things off by capturing an image
00102         camera.CaptureNext();
00103         while(camera.CaptureDone() == false);      
00104                 // Start reading in the image data from the camera hardware buffer                   
00105         camera.ReadStart();  
00106       
00107         char max_in=0x00;
00108         char min_in=0xff;
00109       
00110    /*
00111          for(int x = 0; x<120; x++)
00112             for(int y=0;y <160;y++){
00113               camera.ReadOnebyte();
00114               
00115               in[x][y] = camera.ReadOnebyte();
00116          
00117              if (  max_in <in[x][y])
00118                      max_in = in[x][y];
00119              
00120        
00121              if(min_in > in[x][y])
00122                   min_in=in[x][y];
00123          
00124          }
00125         
00126         
00127      */   
00128      
00129        
00130         for(int x = 0; x<120; x++){
00131             for(int y=0;y <160;y++)
00132         {
00133              
00134                 
00135            
00136                   
00137                      camera.ReadOnebyte();
00138                     // pc.printf("%1X " ,camera.ReadOnebyte());
00139             
00140                if( camera.ReadOnebyte()  > 0xe0 )
00141                         pc.printf("e");
00142                else if( camera.ReadOnebyte()  > 0xd0 )
00143                       pc.printf("d");    
00144                 else if( camera.ReadOnebyte()  > 0xc0 )
00145                  pc.printf("c"); 
00146                  else if( camera.ReadOnebyte()  > 0xb0 )
00147                  pc.printf("b"); 
00148                   else if( camera.ReadOnebyte()  > 0xa0 )       
00149                pc.printf("a"); 
00150                    else if( camera.ReadOnebyte()  > 0x90 )
00151                     pc.printf("9"); 
00152                     else if( camera.ReadOnebyte()  > 0x80 )
00153                      pc.printf("8"); 
00154                      else if( camera.ReadOnebyte()  > 0x70 )
00155                       pc.printf("7"); 
00156                       else if( camera.ReadOnebyte()  > 0x60 )
00157                        pc.printf("6"); 
00158                        else if( camera.ReadOnebyte()  > 0x50 )
00159                         pc.printf("5"); 
00160                        
00161                         else if( camera.ReadOnebyte()  > 0x40 )
00162                          pc.printf("4"); 
00163                          else if( camera.ReadOnebyte()  > 0x30 )
00164                           pc.printf("3"); 
00165                           else if( camera.ReadOnebyte()  > 0x20 )
00166                       pc.printf("2"); 
00167                           else
00168                            pc.printf("1"); 
00169               
00170               
00171                //     if( (max_in-in[x][y]) > (in[x][y]-min_in) )
00172                //       pc.printf("X");
00173                //      else
00174                //       pc.printf(" ");     
00175                 
00176                   
00177                 
00178                
00179         }
00180         pc.printf("\r\n");
00181        }
00182         camera.ReadStop();
00183         camera.CaptureNext();
00184         while(camera.CaptureDone() == false);             
00185         
00186         pc.printf("\r\nSnap_done\r\n");   
00187         led4 = 0;
00188 }
00189 
00190 
00191