Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of rtos_basic by
Revision 8:025a9d74a731, committed 2014-07-08
- Comitter:
- backman
- Date:
- Tue Jul 08 06:21:37 2014 +0000
- Parent:
- 7:f990f03bc2b2
- Commit message:
- wang
Changed in this revision
--- a/main.cpp Fri Jul 04 14:29:56 2014 +0000
+++ b/main.cpp Tue Jul 08 06:21:37 2014 +0000
@@ -25,8 +25,8 @@
*/
-
- OV7670 camera(PTE0,PTE1,PTD6,PTD7,PTE31,PortC,0x1983C,PTB8,PTB9,PTB10);
+ //D7-D0
+ OV7670 camera(PTE0,PTE1,PTD6,PTD7,PTE31,PTC17,PTC16,PTC13,PTC12,PTC6,PTC5,PTC4,PTC3,PTB8,PTB9,PTB10);
@@ -40,187 +40,37 @@
#define QVGA 76800 //320*240
#define QQVGA 19200 //160*120
-static char format = ' ';
-static int resolution = 0;
-
+
+static int resolution =QQVGA ;
+// char in[160][120];
-void rxCallback()
-{
- pc.putc( pc.getc() );
- new_send = true;
-}
-
I2C i2c(PTE0, PTE1);
- /*
-int main() {
-
- while (1) {
-
- i2c.write('l');
-
- wait(0.5);
-
-
-
- }
-}*/
-
int main()
{
pc.baud(115200);
- pc.printf("SystemCoreClock: %dMHz\r\n", SystemCoreClock/1000000); // print the clock frequency
+
led4 = 0;
-
-
- t.start();
- //pc.attach(&rxCallback);
-
- strcpy(word,"init_yuv_QQVGA");
- parse_cmd();
-
-
- wait_ms(50);
-
- strcpy(word,"snap");
- parse_cmd();
-
-
-
-
- /*while(1)
- {
-
- if(new_send)
- {
- int i = 0;
-
-
-
-
- while(pc.readable())
- {
- word[i] = pc.getc();
- i++;
- }
- parse_cmd();
- i=0;
- }
-
- wait_ms(50);
- }*/
-
-}
+
-
-void parse_cmd()
-{
- new_send = false;
-
- if(strcmp("snap", word) == 0)
- {
- CameraSnap();
- memset(word, 0, sizeof(word));
- }else
- if(strcmp("init_bw_VGA", word) == 0) // Set up for 640*480 pixels RAW
- {
-
- format = 'b';
- resolution = VGA;
- if(camera.Init('b', VGA) != 1)
+
+
+ if(camera.Init('b', QQVGA) != 1) // Set up for 160*120 pixels YUV (Only Y)
{
pc.printf("Init Fail\r\n");
}
pc.printf("Initializing done\r\n");
- memset(word, 0, sizeof(word));
- }else
- if(strcmp("init_yuv_QVGA", word) == 0) // Set up for 320*240 pixels YUV422
- {
- format = 'y';
- resolution = QVGA;
- if(camera.Init('b', QVGA) != 1)
- {
- pc.printf("Init Fail\r\n");
- }
- pc.printf("Initializing done\r\n");
- memset(word, 0, sizeof(word));
- }else
- if(strcmp("init_rgb_QVGA", word) == 0) // Set up for 320*240 pixels RGB565
- {
- format = 'r';
- resolution = QVGA;
- if(camera.Init('r', QVGA) != 1)
- {
- pc.printf("Init Fail\r\n");
- }
- pc.printf("Initializing done\r\n");
- memset(word, 0, sizeof(word));
- }else
- if(strcmp("init_bw_QVGA", word) == 0) // Set up for 320*240 pixels YUV (Only Y)
- {
- format = 'b';
- resolution = QVGA;
-
- if(camera.Init('b', QVGA) != 1)
- {
- pc.printf("Init Fail\r\n");
- }
- pc.printf("Initializing done\r\n");
- memset(word, 0, sizeof(word));
- }else
- if(strcmp("init_yuv_QQVGA", word) == 0) // Set up for 160*120 pixels YUV422 ////////
- {
-
- format = 'y';
- resolution = QQVGA;
-
- //pc.printf("ReadReg = %o\r\n",camera.Init('b', QQVGA));
-
- if(camera.Init('b', QQVGA) != 1)
- {
- pc.printf("Init Fail\r\n");
- }
- pc.printf("Initializing done\r\n");
- memset(word, 0, sizeof(word));
- }else
- if(strcmp("init_rgb_QQVGA", word) == 0) // Set up for 160*120 pixels RGB565
- {
- format = 'r';
- resolution = QQVGA;
- if(camera.Init('r', QQVGA) != 1)
- {
- pc.printf("Init Fail\r\n");
- }
- pc.printf("Initializing done\r\n");
- memset(word, 0, sizeof(word));
- }else
- if(strcmp("init_bw_QQVGA", word) == 0) // Set up for 160*120 pixels YUV (Only Y)
- {
- format = 'b';
- resolution = QQVGA;
- if(camera.Init('b', QQVGA) != 1)
- {
- pc.printf("Init Fail\r\n");
- }
- pc.printf("Initializing done\r\n");
- memset(word, 0, sizeof(word));
- }else
- if(strcmp("reset", word) == 0)
- {
- mbed_reset();
- }else
- if(strcmp("time", word) == 0)
- {
- pc.printf("Tot time acq + send (mbed): %dms\r\n", t2-t1);
- memset(word, 0, sizeof(word));
- }else
- if(strcmp("reg_status", word) == 0)
- {
- int i = 0;
+
+
+
+ wait_ms(50);
+
+ //register
+ int i = 0;
pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F");
for (i=0;i<OV7670_REGMAX;i++)
{
@@ -233,49 +83,107 @@
pc.printf("%02X ",data);
}
pc.printf("\r\n");
- }
-
- memset(word, 0, sizeof(word));
-
+
+
+ wait_ms(50);
+
+ CameraSnap();
+
+
+
+
}
-
-
+
void CameraSnap()
{
led4 = 1;
-
+ // pc.printf("++++++++++++++++++++++++++++++");
// Kick things off by capturing an image
camera.CaptureNext();
while(camera.CaptureDone() == false);
// Start reading in the image data from the camera hardware buffer
camera.ReadStart();
- t1 = t.read_ms();
- pc.printf("re: %d",resolution);
- for(int x = 0; x<resolution; x++)
+
+ char max_in=0x00;
+ char min_in=0xff;
+
+ /*
+ for(int x = 0; x<120; x++)
+ for(int y=0;y <160;y++){
+ camera.ReadOnebyte();
+
+ in[x][y] = camera.ReadOnebyte();
+
+ if ( max_in <in[x][y])
+ max_in = in[x][y];
+
+
+ if(min_in > in[x][y])
+ min_in=in[x][y];
+
+ }
+
+
+ */
+
+
+ for(int x = 0; x<120; x++){
+ for(int y=0;y <160;y++)
{
+
+
+
+ camera.ReadOnebyte();
+ // pc.printf("%1X " ,camera.ReadOnebyte());
+
+ if( camera.ReadOnebyte() > 0xe0 )
+ pc.printf("e");
+ else if( camera.ReadOnebyte() > 0xd0 )
+ pc.printf("d");
+ else if( camera.ReadOnebyte() > 0xc0 )
+ pc.printf("c");
+ else if( camera.ReadOnebyte() > 0xb0 )
+ pc.printf("b");
+ else if( camera.ReadOnebyte() > 0xa0 )
+ pc.printf("a");
+ else if( camera.ReadOnebyte() > 0x90 )
+ pc.printf("9");
+ else if( camera.ReadOnebyte() > 0x80 )
+ pc.printf("8");
+ else if( camera.ReadOnebyte() > 0x70 )
+ pc.printf("7");
+ else if( camera.ReadOnebyte() > 0x60 )
+ pc.printf("6");
+ else if( camera.ReadOnebyte() > 0x50 )
+ pc.printf("5");
+
+ else if( camera.ReadOnebyte() > 0x40 )
+ pc.printf("4");
+ else if( camera.ReadOnebyte() > 0x30 )
+ pc.printf("3");
+ else if( camera.ReadOnebyte() > 0x20 )
+ pc.printf("2");
+ else
+ pc.printf("1");
+
+
+ // if( (max_in-in[x][y]) > (in[x][y]-min_in) )
+ // pc.printf("X");
+ // else
+ // pc.printf(" ");
+
+
+
- // Read in the first half of the image
- if(format == 'b' && resolution != VGA)
- {
- camera.ReadOnebyte();
- }else
- if(format == 'y' || format == 'r')
- {
- // pc.printf("XDDDD");
- pc.putc(camera.ReadOnebyte());
- }
- // Read in the Second half of the image
- pc.putc(camera.ReadOnebyte()); // Y only
}
-
+ pc.printf("\r\n");
+ }
camera.ReadStop();
- t2 = t.read_ms();
-
camera.CaptureNext();
while(camera.CaptureDone() == false);
- pc.printf("Snap_done\r\n");
+ pc.printf("\r\nSnap_done\r\n");
led4 = 0;
}
--- a/ov7670.cpp Fri Jul 04 14:29:56 2014 +0000
+++ b/ov7670.cpp Tue Jul 08 06:21:37 2014 +0000
@@ -5,10 +5,10 @@
//i2c data i2c clk //ver //her //write enable //data //reset //chip en //clock
-OV7670::OV7670(PinName sda, PinName scl, PinName vs, PinName hr, PinName we, PortName port, int mask, PinName rt, PinName o, PinName rc) : _i2c(sda,scl),vsync(vs),href(hr),wen(we),data(port,mask),rrst(rt),oe(o),rclk(rc)
+OV7670::OV7670(PinName sda, PinName scl, PinName vs, PinName hr, PinName we, PinName d7, PinName d6,PinName d5,PinName d4, PinName d3, PinName d2, PinName d1, PinName d0, PinName rt, PinName o, PinName rc): _i2c(sda,scl),vsync(vs),href(hr),wen(we),data(d0,d1,d2,d3,d4,d5,d6,d7),rrst(rt),oe(o),rclk(rc)
{
- //pc.baud(115200);
+
_i2c.stop();
_i2c.frequency(OV7670_I2CFREQ);
@@ -22,11 +22,12 @@
oe = 1;
rclk = 1;
wen = 0;
- //pc.printf("=///=");
+
}
+
OV7670::~OV7670()
{
@@ -81,9 +82,11 @@
// Data Read
int OV7670::ReadOnebyte(void)
{
- int B1;
+ char B1;
rclk = 1;
- B1 = (((data&0x07800000)>>19)|((data&0x078000)>>15));
+ // B1 = (((data&0x07800000)>>19)|((data&0x078000)>>15));
+ B1 = data;
+
rclk = 0;
return B1;
}
--- a/ov7670.h Fri Jul 04 14:29:56 2014 +0000
+++ b/ov7670.h Tue Jul 08 06:21:37 2014 +0000
@@ -25,8 +25,14 @@
PinName hr, // HREF
PinName we, // WEN
- PortName port, // 8bit bus port
- int mask, // 0b0000_0M65_4000_0321_L000_0000_0000_0000 = 0x07878000
+ PinName d7, // D7
+ PinName d6, // D6
+ PinName d5, // D5
+ PinName d4, // D4
+ PinName d3, // D3
+ PinName d2, // D2
+ PinName d1, // D1
+ PinName d0, // D0 // 0b0000_0M65_4000_0321_L000_0000_0000_0000 = 0x07878000
PinName rt, // /RRST
PinName o, // /OE
@@ -48,13 +54,13 @@
void ReadStart(void); // Data Start
void ReadStop(void); // Data Stop
-
+ void InitQQVGA(void);
private:
I2C _i2c;
InterruptIn vsync,href;
DigitalOut wen;
- PortIn data;
+ BusIn data ;
DigitalOut rrst,oe,rclk;
volatile int LineCounter;
volatile int LastLines;
