OV7670 with FIFO AL422B (TORAGI Camera TYPE B) test program

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //
00002 // OV7670 + FIFO AL422B camera board test
00003 //
00004 #include "mbed.h"
00005 #include "ov7670.h"
00006 
00007 OV7670 camera(
00008     p28,p27,       // SDA,SCL(I2C / SCCB)
00009     p21,p22,p20,   // VSYNC,HREF,WEN(FIFO)
00010     p19,p18,p17,p16,p15,p14,p13,p12, // D7-D0
00011     p23,p24,p25) ; // RRST,OE,RCLK
00012 
00013 Serial pc(USBTX,USBRX) ;
00014 
00015 #define SIZEX (160)
00016 #define SIZEY (120)
00017 
00018 int main() {
00019     int i ;
00020     pc.baud(115200) ;
00021     pc.printf("Camera resetting..\r\n") ;
00022 
00023     camera.Reset() ;
00024 
00025     pc.printf("Before Init...\r\n") ;    
00026     pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F") ;
00027     for (i=0;i<OV7670_REGMAX;i++) {
00028         int data ;
00029         data = camera.ReadReg(i) ; // READ REG
00030         if ((i & 0x0F) == 0) {
00031             pc.printf("\r\n%02X : ",i) ;
00032         }
00033         pc.printf("%02X ",data) ;
00034     }
00035     pc.printf("\r\n") ;
00036 
00037     camera.InitQQVGA() ;
00038 
00039     pc.printf("After Init...\r\n") ;    
00040     pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F") ;
00041     for (i=0;i<OV7670_REGMAX;i++) {
00042         int data ;
00043         data = camera.ReadReg(i) ; // READ REG
00044         if ((i & 0x0F) == 0) {
00045             pc.printf("\r\n%02X : ",i) ;
00046         }
00047         pc.printf("%02X ",data) ;
00048     }
00049     pc.printf("\r\n") ;
00050     
00051     // CAPTURE and SEND LOOP
00052     while(1)
00053     {
00054         pc.printf("Hit Any Key to send RGBx160x120 Capture Data.\r\n") ;
00055         while(!pc.readable()) ;
00056         pc.getc() ;
00057         camera.CaptureNext() ;
00058         while(camera.CaptureDone() == false) ;
00059         pc.printf("*\r\n") ;
00060         camera.ReadStart() ;
00061         i = 0 ;
00062         for (int y = 0;y < SIZEY;y++) {
00063             int r,g,b,d1,d2 ;
00064             for (int x = 0;x < SIZEX;x++) {
00065                 d1 = camera.ReadOneByte() ; // upper nibble is XXX , lower nibble is B
00066                 d2 = camera.ReadOneByte() ; // upper nibble is G   , lower nibble is R
00067                 b = (d1 & 0x0F) ;
00068                 g = (d2 & 0xF0) >> 4 ;
00069                 r = (d2 & 0x0F) ;
00070                 pc.printf ("%1X%1X%1X",r,g,b) ;
00071             }
00072             pc.printf("\r\n") ;
00073         }
00074         camera.ReadStop() ;        
00075     }
00076 }