|
stm32F407單片機(jī)+ov7670攝像頭識別
實(shí)驗(yàn)現(xiàn)象.jpg (294.16 KB, 下載次數(shù): 53)
下載附件
2019-5-12 17:15 上傳
單片機(jī)源程序如下:
- #include "system.h"
- #include "SysTick.h"
- #include "led.h"
- #include "usart.h"
- #include "tftlcd.h"
- #include "malloc.h"
- #include "sdio_sdcard.h"
- #include "flash.h"
- #include "ff.h"
- #include "fatfs_app.h"
- #include "key.h"
- #include "font_show.h"
- #include "exti.h"
- #include "time.h"
- #include "string.h"
- #include "math.h"
- #include "OV7670_DCMI.h"
- extern u8 ov_sta; //在exit.c里面定義
- extern u8 ov_frame; //在time.c里面定義
- //更新LCD顯示
- void camera_refresh(void)
- {
- u32 j;
- u16 i;
- u16 color;
- u16 temp;
- if(ov_sta)//有幀中斷更新?
- {
- LCD_Display_Dir(1);
- //LCD_Set_Window((tftlcd_data.width-320)/2,(tftlcd_data.height-240)/2,320,240-1);//將顯示區(qū)域設(shè)置到屏幕中央
- LCD_Set_Window(0,(tftlcd_data.height-240)/2,320-1,240-1);//將顯示區(qū)域設(shè)置到屏幕中央
-
- OV7670_RRST=0; //開始復(fù)位讀指針
- OV7670_RCK_L;
- OV7670_RCK_H;
- OV7670_RCK_L;
- OV7670_RRST=1; //復(fù)位讀指針結(jié)束
- OV7670_RCK_H;
- /*for(i=0;i<240;i++) //此種方式可以兼容任何彩屏
- {
- for(j=0;j<320;j++)
- {
- OV7670_RCK_L;
- color=OV7670_DATA; //讀數(shù)據(jù)
- OV7670_RCK_H;
- color>>=8;
- OV7670_RCK_L;
- color|=OV7670_DATA; //讀數(shù)據(jù)
- OV7670_RCK_H;
- LCD_WriteData_Color(color);
- }
- }*/
- for(j=0;j<76800;j++) //此種方式需清楚TFT內(nèi)部顯示方向控制寄存器值
- {
- OV7670_RCK_L;
- color=OV7670_DATA; //讀數(shù)據(jù)
- OV7670_RCK_H;
- color<<=8;
- OV7670_RCK_L;
- color|=OV7670_DATA; //讀數(shù)據(jù)
- OV7670_RCK_H;
- LCD_WriteData_Color(color);
- //printf("%x ",color);
- //if(j%20==0)printf("\r\n");
- //delay_us(50);
- }
- ov_sta=0; //清零幀中斷標(biāo)記
- ov_frame++; //統(tǒng)計(jì)幀數(shù)
- LCD_Display_Dir(0);
- }
- }
- const u8*LMODE_TBL[5]={"Auto","Sunny","Cloudy","Office","Home"};
- const u8 *EFFECTS_TBL[7]={"Normal","Negative","B&W","Redish","Greenish","Bluish","Antique"}; //7種特效
- int main()
- {
- u8 i=0;
- u8 key;
- u8 lightmode=0,saturation=2,brightness=2,contrast=2;
- u8 effect=0;
- u8 sbuf[15];
- u8 count;
-
- SysTick_Init(168);
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //中斷優(yōu)先級分組 分2組
- LED_Init();
- KEY_Init();
- USART1_Init(9600);
- TFTLCD_Init(); //LCD初始化
- EN25QXX_Init(); //初始化EN25Q128
-
- my_mem_init(SRAMIN); //初始化內(nèi)部內(nèi)存池
-
- FRONT_COLOR=RED;//設(shè)置字體為紅色
- // while(SD_Init()!=0)
- // {
- // LCD_ShowString(10,10,tftlcd_data.width,tftlcd_data.height,16,"SD Card Error!");
- // }
- // FATFS_Init(); //為fatfs相關(guān)變量申請內(nèi)存
- // f_mount(fs[0],"0:",1); //掛載SD卡
- // f_mount(fs[1],"1:",1); //掛載FLASH.
-
- LCD_ShowFont12Char(10, 10, "xx科技");
- LCD_ShowFont12Char(10, 30, "wwwxxxxnet");
- LCD_ShowFont12Char(10, 50, "攝像頭應(yīng)用--OV7670");
-
- while(OV7670_Init())//初始化OV7670
- {
- LCD_ShowString(10,80,tftlcd_data.width,tftlcd_data.height,16,"OV7670 Error!");
- delay_ms(200);
- LCD_Fill(10,80,239,206,WHITE);
- delay_ms(200);
- }
- LCD_ShowString(10,80,tftlcd_data.width,tftlcd_data.height,16,"OV7670 OK! ");
- delay_ms(1500);
- OV7670_Light_Mode(0); //默認(rèn)設(shè)置自動白平衡
- OV7670_Color_Saturation(2); // 色度調(diào)節(jié)
- OV7670_Brightness(2); //亮度調(diào)節(jié)
- OV7670_Contrast(2); //對比度
- OV7670_Special_Effects(0); //特效
-
- TIM4_Init(10000,8399); //10Khz計(jì)數(shù)頻率,1秒鐘中斷
- EXTI7_Init();
- OV7670_Window_Set(12,176,240,320); //設(shè)置窗口
- OV7670_CS=0;
- LCD_Clear(BLACK);
- while(1)
- {
- key=KEY_Scan(0);
- if(key)count=20;
- switch(key)
- {
- case KEY_UP: //燈光模式設(shè)置
- lightmode++;
- if(lightmode>4)lightmode=0;
- OV7670_Light_Mode(lightmode);
- sprintf((char*)sbuf,"%s",LMODE_TBL[lightmode]);
- break;
- case KEY_DOWN: //飽和度
- saturation++;
- if(saturation>4)saturation=0;
- OV7670_Color_Saturation(saturation);
- sprintf((char*)sbuf,"Saturation:%d",(char)saturation-2);
- break;
- case KEY_LEFT: //亮度
- brightness++;
- if(brightness>4)brightness=0;
- OV7670_Brightness(brightness);
- sprintf((char*)sbuf,"Brightness:%d",(char)brightness-2);
- break;
- case KEY_RIGHT: //對比度
- contrast++;
- if(contrast>4)contrast=0;
- OV7670_Contrast(contrast);
- sprintf((char*)sbuf,"Contrast:%d",(char)contrast-2);
- break;
- }
- if(count)
- {
- count--;
- LCD_ShowString((tftlcd_data.width-240)/2+30,(tftlcd_data.height-320)/2+60,200,16,16,sbuf);
- }
- camera_refresh();//更新顯示
- i++;
- if(i%20==0)
- {
- led1=!led1;
- }
- //delay_ms(10);
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
攝像頭應(yīng)用程序--OV7670--DCMI.7z
(756.84 KB, 下載次數(shù): 333)
2019-5-12 22:23 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|