ov7670测试程序,用于图像识别,未完善
单片机源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "string.h"
- #include "ov7670.h"
- #include "tpad.h"
- #include "timer.h"
- #include "exti.h"
- #include "usmart.h"
- #include "EasyTracer.h"
- #define min3v(v1, v2, v3) ((v1)>(v2)? ((v2)>(v3)?(v3):(v2)):((v1)>(v3)?(v3):(v1)))
- #define max3v(v1, v2, v3) ((v1)<(v2)? ((v2)<(v3)?(v3):(v2)):((v1)<(v3)?(v3):(v1)))
-
- /************************************************
- ************************************************/
- const u8*LMODE_TBL[5]={"Auto","Sunny","Cloudy","Office","Home"}; //5种光照模式
- const u8*EFFECTS_TBL[7]={"Normal","Negative","B&W","Redish","Greenish","Bluish","Antique"}; //7种特效
- extern u8 ov_sta; //在exit.c里 面定义
- extern u8 ov_frame; //在timer.c里面定义
- u16 data1[500];
- //更新LCD显示
- void camera_refresh(void)
- { u8 r,g,b,maxVal,minVal;
- u32 j;
- u16 color;
- if(ov_sta)//有帧中断更新?
- {
- LCD_Scan_Dir(U2D_L2R); //从上到下,从左到右
- if(lcddev.id==0X1963)LCD_Set_Window((lcddev.width-240)/2,(lcddev.height-320)/2,240,320);//将显示区域设置到屏幕中央
- else if(lcddev.id==0X5510||lcddev.id==0X5310)LCD_Set_Window((lcddev.width-320)/2,(lcddev.height-240)/2,320,240);//将显示区域设置到屏幕中央
- LCD_WriteRAM_Prepare(); //开始写入GRAM
- OV7670_RRST=0; //开始复位读指针
- OV7670_RCK_L;
- OV7670_RCK_H;
- OV7670_RCK_L;
- OV7670_RRST=1; //复位读指针结束
- OV7670_RCK_H;
- for(j=0;j<76800;j++)
- {
- OV7670_RCK_L;
- color=GPIOC->IDR&0XFF; //读数据
- OV7670_RCK_H;
- color<<=8;
- OV7670_RCK_L;
- color|=GPIOC->IDR&0XFF; //读数据
- OV7670_RCK_H;
- r = (unsigned char)((color&0xf800)>>8);
- g = (unsigned char)((color&0x07e0)>>3);
- b = (unsigned char)((color&0x001f)<<3);
- maxVal = max3v(r, g, b);
- minVal = min3v(r, g, b);
- color = (maxVal+minVal)*240/255/2;
- if(j<400)data1[j]=color;
- if(color>55)color=0xffff;
- else color=0;
-
- LCD->LCD_RAM=color;
- }
- ov_sta=0; //清零帧中断标记
- ov_frame++;
- LCD_Scan_Dir(DFT_SCAN_DIR); //恢复默认扫描方向
- }
- }
- int main(void)
- {
- RESULT Resu;
- TARGET_CONDI Condition={180,230,20,250,20,200,32,32,320,240};
- int ch;
- int cl=0;
- int cr=0;
- int cf=0;
- int cb=0;
- /*四轴行动参数*/
- int zuoyou=0;
- int qianhou=0;
-
- // u8 key;
- u8 lightmode=0,saturation=0,brightness=0,contrast=0;
- u8 effect=0;
-
- // u8 i=0;
- // u8 msgbuf[15]; //消息缓存区
- // u8 tm=0;
- delay_init(); //延时函数初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为 115200
- usmart_dev.init(72); //初始化USMART
- LED_Init(); //初始化与LED连接的硬件接口
- // KEY_Init(); //初始化按键
- LCD_Init(); //初始化LCD
- // TPAD_Init(6); //触摸按键初始化
- POINT_COLOR=RED; //设置字体为红色
- LCD_ShowString(30,50,200,16,16,"WarShip STM32");
- LCD_ShowString(30,70,200,16,16,"OV7670 TEST");
- LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
- LCD_ShowString(30,110,200,16,16,"2015/1/18");
- LCD_ShowString(30,130,200,16,16,"KEY0:Light Mode");
- LCD_ShowString(30,150,200,16,16,"KEY1:Saturation");
- LCD_ShowString(30,170,200,16,16,"KEY2:Brightness");
- LCD_ShowString(30,190,200,16,16,"KEY_UP:Contrast");
- LCD_ShowString(30,210,200,16,16,"TPAD:Effects");
- LCD_ShowString(30,230,200,16,16,"OV7670 Init...");
- while(OV7670_Init())//初始化OV7670
- {
- LCD_ShowString(30,230,200,16,16,"OV7670 Error!!");
- delay_ms(200);
- LCD_Fill(30,230,239,246,WHITE);
- delay_ms(200);
- }
- LCD_ShowString(30,230,200,16,16,"OV7670 Init OK");
- delay_ms(1500);
- OV7670_Light_Mode(lightmode);
- OV7670_Color_Saturation(saturation);
- OV7670_Brightness(brightness);
- OV7670_Contrast(contrast);
- OV7670_Special_Effects(effect);
- TIM6_Int_Init(10000,7199); //10Khz计数频率,1秒钟中断
- EXTI8_Init(); //使能定时器捕获
- OV7670_Window_Set(12,176,240,320); //设置窗口
- OV7670_CS=0;
- LCD_Clear(BLACK);
- while(1)
- {
- // key=KEY_Scan(0);//不支持连按
- // if(key)
- // {
- // tm=20;
- // switch(key)
- // {
- // case KEY0_PRES: //灯光模式Light Mode
- // lightmode++;
- // if(lightmode>4)lightmode=0;
- // OV7670_Light_Mode(lightmode);
- // sprintf((char*)msgbuf,"%s",LMODE_TBL[lightmode]);
- // break;
- // case KEY1_PRES: //饱和度Saturation
- // saturation++;
- // if(saturation>4)saturation=0;
- // OV7670_Color_Saturation(saturation);
- // sprintf((char*)msgbuf,"Saturation:%d",(signed char)saturation-2);
- // break;
- // case KEY2_PRES: //亮度Brightness
- // brightness++;
- // if(brightness>4)brightness=0;
- // OV7670_Brightness(brightness);
- // sprintf((char*)msgbuf,"Brightness:%d",(signed char)brightness-2);
- // break;
- // case WKUP_PRES: //对比度Contrast
- // contrast++;
- // if(contrast>4)contrast=0;
- // OV7670_Contrast(contrast);
- // sprintf((char*)msgbuf,"Contrast:%d",(signed char)contrast-2);
- // break;
- // }
- // }
- // if(TPAD_Scan(0))//检测到触摸按键
- // {
- // effect++;
- // if(effect>6)effect=0;
- // OV7670_Special_Effects(effect);//设置特效
- // sprintf((char*)msgbuf,"%s",EFFECTS_TBL[effect]);
- // tm=20;
- // }
- delay_ms(1);
- camera_refresh();//更新显示
- // LCD_Fill(100,100,200, 200,RED);
-
- if(Trace(&Condition,&Resu))
- {
- // LCD_Fill(Resu.x-Resu.w/2,Resu.y-Resu.h/2,Resu.x+Resu.w/2, Resu.y-Resu.h/2+20,RED);
- LCD_Draw_Circle(Resu.x,Resu.y,20);
- LED0=0;
- /*四轴行动*/
-
- zuoyou=Resu.x-120;
- qianhou=Resu.y-160;
-
- if(abs(zuoyou)>3)
- {
- if(zuoyou<0)
- {left=0;right=1;}
- else{left=1;right=0;}
- }
- else {left=0;right=0;}
- if(abs(qianhou)>3)
- {
- if(qianhou<0)
- {forward=0;backward=1;}
- else{forward=1;backward=0;}
- }
- else {forward=0;backward=0;}
-
- LCD_Draw_Circle(120,160,ch*5);
- LCD_Draw_Circle(80,160,cl*10);
- LCD_Draw_Circle(160,160,cr*10);
- LCD_Draw_Circle(120,120,cf*10);
- LCD_Draw_Circle(120,200,cb*10);
-
- // GUI_Fill(Resu.x-Resu.w/2,Resu.y-Resu.h/2,Resu.w,1,0xf800);
- // GUI_Fill(Resu.x-Resu.w/2,Resu.y-Resu.h/2,1,Resu.h,0xf800);
- // GUI_Fill(Resu.x-Resu.w/2,Resu.y+Resu.h/2,Resu.w,1,0xf800);
- // GUI_Fill(Resu.x+Resu.w/2,Resu.y-Resu.h/2,1,Resu.h,0xf800);
- // GUI_Fill(Resu.x-2,Resu.y-2,4,4,0xf800);
- }
- else
- {LCD_ShowString(30,240,200,16,16,"Target is not found");
- Resu->x=120,Resu->y,=160;
- LED0=1;}
- // if(tm)
- // {
- // LCD_ShowString((lcddev.width-240)/2+30,(lcddev.height-320)/2+60,200,16,16,msgbuf);
- // tm--;
- // }
- // i++;
- // if(i==15)//DS0闪烁.
- // {
- // i=0;
- // LED0=!LED0;
- // }
- }
- }
复制代码
所有资料51hei提供下载:
ov7670测试程序.rar
(395.23 KB, 下载次数: 25)
|