下載:
實驗33 攝像頭實驗 最終確定.rar
(404.07 KB, 下載次數: 15)
2017-9-21 23:43 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
- #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 "color.h"
-
- /************************************************
- ALIENTEK精英STM32開發板實驗33
- 攝像頭OV7670 實驗
-
- ************************************************/
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- void TIM_Configuration(u16 value);
- void TIM_Configuration1(u16 value);
- //int key_Read(void);
- int flag = 0;
- #define vole(tem) (0.5+0.5/45*(tem+45))*1000/*換算公式*/
- 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里面定義
- //更新LCD顯示
- void camera_refresh(void)
- {
- 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;
- // if(color>25500)
- // color=0x0000;
- // else
- // color=0xffff;
- LCD->LCD_RAM=color;
- }
-
- ov_sta=0; //清零幀中斷標記
- // ov_frame++;
- LCD_Scan_Dir(DFT_SCAN_DIR); //恢復默認掃描方向
- if(Trace(&condition, &result))
- {
- LCD_DrawRectangle( result.x-result.w/2, result.y-result.h/2, result.x-result.w/2+result.w, result.y-result.h/2+result.h);
- LCD_DrawRectangle( result.x-2, result.y-2,result.x+2, result.y+2);
-
- }
- }
- }
- int main(void)
- {
- u8 key;
- u8 lightmode=0,saturation=2,contrast=2;
- u8 effect=0;
- u8 i=0;
- u8 msgbuf[15]; //消息緩存區
- u8 tm=0;
- int volume = vole(0);
- // u16 t=0;
- // u16 a,b,c;
- RCC_Configuration();
- GPIO_Configuration();
- TIM_Configuration(volume);
- TIM_Configuration1(volume);
-
- 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; //設置字體為紅色
-
- TIM_Configuration(1500);
- delay_ms(20);
- TIM_Configuration(1500);
- delay_ms(20);
- TIM_Configuration(1500);
- delay_ms(20);
-
- TIM_Configuration1(1500);
- delay_ms(20);
- TIM_Configuration1(1500);
- delay_ms(20);
- TIM_Configuration1(1500);
- delay_ms(20);
- LCD_ShowString(30,50,200,16,16,"ELITE STM32F103 ^_^");
- 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,"KEY_UP:Contrast");
- LCD_ShowString(30,190,200,16,16,"TPAD:Effects");
- LCD_ShowString(30,210,200,16,16,"OV7670 Init...");
- while(OV7670_Init())//初始化OV7670
- {
- LCD_ShowString(30,210,200,16,16,"OV7670 Error!!");
- delay_ms(200);
- LCD_Fill(30,210,239,246,WHITE);
- delay_ms(200);
- }
- LCD_ShowString(30,210,200,16,16,"OV7670 Init OK");
- delay_ms(1500);
- OV7670_Light_Mode(lightmode);
- OV7670_Color_Saturation(saturation);
- 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);
- // if(result.x!=0&&result.y!=0)
- // {
- printf("ZB= %d,%d ",result.x,result.y);
- // }
- while(1)
- {
- POINT_COLOR=BLUE;
- key=KEY_Scan(0);//不支持連按
- camera_refresh();//更新顯示
-
- if(KEY0==1)
- {
- if((result.x<170|result.x>140)&&(result.y<210|result.x>190))
- {
- if((160-result.x<200-result.y)||(160+result.x<200+result.y))
- {
- TIM_Configuration(1500);
- delay_ms(30);
-
- TIM_Configuration(1725);
- delay_ms(20);
-
- TIM_Configuration(1500);
- delay_ms(30);
-
- TIM_Configuration(1550);
- delay_ms(20);
-
- TIM_Configuration(1500);
- delay_ms(20);
- camera_refresh();
- }
- else
- {
- TIM_Configuration1(1500);
- delay_ms(30);
-
-
- TIM_Configuration1(1725);
- delay_ms(20);
-
- TIM_Configuration1(1500);
- delay_ms(20);
-
- TIM_Configuration1(1550);
- delay_ms(20);
-
- TIM_Configuration1(1500);
- delay_ms(20);
- camera_refresh();
- }
- if(result.x<160&&result.x!=0)
- {
-
- TIM_Configuration(1500);
- delay_ms(30);
-
-
- TIM_Configuration(1725);
- delay_ms(20);
-
- TIM_Configuration(1800);
- delay_ms(30);
- TIM_Configuration(1400);
- delay_ms(20);
-
- TIM_Configuration(1525);
- delay_ms(20);
-
- TIM_Configuration(1500);
- delay_ms(20);
- camera_refresh();
- }
-
- else
- {
- TIM_Configuration1(1500);
- delay_ms(20);
-
- TIM_Configuration1(1400);
- delay_ms(20);
-
- TIM_Configuration1(1350);
- delay_ms(20);
- TIM_Configuration1(1250);
- delay_ms(20);
-
- TIM_Configuration1(1100);
- delay_ms(20);
-
- TIM_Configuration1(1350);
- delay_ms(20);
-
- TIM_Configuration1(1500);
- delay_ms(20);
-
- TIM_Configuration1(1500);
- delay_ms(20);
- camera_refresh();
- }
-
- if(result.y<200 && result.y!=0)
- {
- TIM_Configuration1(1500);
- delay_ms(20);
-
- TIM_Configuration1(1725);
- delay_ms(20);
-
- TIM_Configuration1(1800);
- delay_ms(20);
- TIM_Configuration1(1400);
- delay_ms(20);
-
- TIM_Configuration1(1500);
- delay_ms(20);
-
- TIM_Configuration1(1500);
- delay_ms(20);
- camera_refresh();
- }
- else
- {
- TIM_Configuration1(1500);
- delay_ms(20);
-
- TIM_Configuration1(1400);
- delay_ms(20);
-
- TIM_Configuration1(1350);
- delay_ms(20);
- TIM_Configuration1(1200);
- delay_ms(20);
-
- TIM_Configuration1(1100);
- delay_ms(20);
-
- TIM_Configuration1(1350);
- delay_ms(20);
-
- TIM_Configuration1(1500);
- delay_ms(20);
-
- TIM_Configuration1(1500);
- delay_ms(20);
- camera_refresh();
- }
- }
-
- else
- {
- TIM_Configuration1(1500);
- delay_ms(20);
- TIM_Configuration1(1500);
- delay_ms(20);
- }
- }
-
- if(KEY1==1)
- {
- TIM_Configuration(1500);
- delay_ms(20);
- TIM_Configuration1(1500);
- delay_ms(20);
- camera_refresh();
- TIM_Configuration1(1400);
- delay_ms(20);
- TIM_Configuration(1400);
- delay_ms(20);
-
- TIM_Configuration1(1350);
- delay_ms(20);
- TIM_Configuration(1350);
- delay_ms(20);
- camera_refresh();
- TIM_Configuration1(1250);
- delay_ms(20);
- TIM_Configuration(1250);
- delay_ms(20);
-
- TIM_Configuration1(1100);
- delay_ms(20);
- TIM_Configuration(1100);
- delay_ms(20);
- camera_refresh();
- TIM_Configuration1(1350);
- delay_ms(20);
- TIM_Configuration(1350);
- delay_ms(20);
-
- TIM_Configuration1(1500);
- delay_ms(20);
-
- TIM_Configuration(1500);
- delay_ms(20);
- camera_refresh();
- }
- if(WK_UP==0)
- {
- TIM_Configuration(1500);
- delay_ms(20);
- TIM_Configuration1(1500);
- delay_ms(20);
- camera_refresh();
-
- }
-
- 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;
- }
- }
- }
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- /*TIM1的通道1*/
- GPIO_InitStruct.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3;
- GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOA,&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_5;
- GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IPU;
- GPIO_Init(GPIOC,&GPIO_InitStruct);
- }
復制代碼
|