|
如题
- #include <stdio.h>
- #include <math.h>
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "string.h"
- #include "ov7725.h"
- #include "tpad.h"
- #include "timer.h"
- #include "exti.h"
- #include "usmart.h"
- #include "color.h"
- #include "xd.h"
- #include "ov7670.h"
- //传感器名字宏定义
- #define OV7725 1
- #define OV7670 2
- #define uchar unsigned char
- uchar xx,yy,m2;
- int yc,xc,ENA,ENB;
- //由于OV7725传感器安装方式原因,OV7725_WINDOW_WIDTH相当于LCD的高度,OV7725_WINDOW_HEIGHT相当于LCD的宽度
- //注意:此宏定义只对OV7725有效
- #define OV7725_WINDOW_WIDTH 320 // <=320
- #define OV7725_WINDOW_HEIGHT 240 // <=240
- //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,i;
- // 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
- //// OV7725_RRST=0; //开始复位读指针
- //// OV7725_RCK_L;
- //// OV7725_RCK_H;
- //// OV7725_RCK_L;
- //// OV7725_RRST=1; //复位读指针结束
- //// OV7725_RCK_H;
- // OV7670_RRST=0; //开始复位读指针
- // OV7670_RCK_L;
- // OV7670_RCK_H;
- // OV7670_RCK_L;
- // OV7670_RRST=1; //复位读指针结束
- // OV7670_RCK_H;
- // for(i=0;i<OV7725_WINDOW_HEIGHT;i++)
- // {
- // for(j=0;j<OV7725_WINDOW_WIDTH;j++)
- // {
- // OV7725_RCK_L;
- // color=GPIOC->IDR&0XFF; //读数据
- // OV7725_RCK_H;
- // color<<=8;
- // OV7725_RCK_L;
- // color|=GPIOC->IDR&0XFF; //读数据
- // OV7725_RCK_H;
- // 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);
- //
- //
- // xx=result.x;yy=result.y;
- // LCD_ShowNum(1,280.,xx,3,16);
- // LCD_ShowNum(1,300.,yy,3,16);
- // }
- // else {xx=0;yy=0; LCD_ShowNum(1,280.,xx,3,16);LCD_ShowNum(1,300.,yy,3,16);}
- // }
- //}
- void camera_refresh(void)
- {
- u32 j,i;
- 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
- // OV7725_RRST=0; //开始复位读指针
- // OV7725_RCK_L;
- // OV7725_RCK_H;
- // OV7725_RCK_L;
- // OV7725_RRST=1; //复位读指针结束
- // OV7725_RCK_H;
- OV7670_RRST=0; //开始复位读指针
- OV7670_RCK_L;
- OV7670_RCK_H;
- OV7670_RCK_L;
- OV7670_RRST=1; //复位读指针结束
- OV7670_RCK_H;
- for(i=0;i<OV7725_WINDOW_HEIGHT;i++)
- {
- for(j=0;j<OV7725_WINDOW_WIDTH;j++)
- {
- OV7670_RCK_L;
- color=GPIOC->IDR&0XFF; //读数据
- OV7670_RCK_H;
- color<<=8;
- OV7670_RCK_L;
- color|=GPIOC->IDR&0XFF; //读数据
- OV7670_RCK_H;
- 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);
-
-
- xx=result.x;yy=result.y;
- LCD_ShowNum(1,280.,xx,3,16);
- LCD_ShowNum(1,300.,yy,3,16);
- }
- else {xx=0;yy=0; LCD_ShowNum(1,280.,xx,3,16);LCD_ShowNum(1,300.,yy,3,16);}
- }
- }
- u16 a,b,c;
- u16 t=0;
- u8 key;
- u8 lightmode=4,saturation=2,contrast=2;
- u8 effect=0;
- int main(void)
- {
-
- 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
- XD_Init();
- LED_Init(); //初始化与LED连接的硬件接口
- KEY_Init(); //初始化按键
- LCD_Init(); //初始化LCD
- TPAD_Init(6); //触摸按键初始化
-
- TIM3_PWM_Init(899,0);
- TIM3_PWM2_Init(899,0);
-
- POINT_COLOR=RED; //设置字体为红色
- LCD_ShowString(30,10,200,16,16,"WJS STM32");
- LCD_ShowString(30,70,200,16,16,"ATOM@ALIENTEK");
- LCD_ShowString(30,90,200,16,16,"2018/8/5");
- LCD_ShowString(30,110,200,16,16,"OV7725 Init...");
- while(OV7670_Init())//初始化OV7670
- {
- LCD_ShowString(30,210,200,16,16,"OV7725 Error!!");
- delay_ms(200);
- LCD_Fill(30,210,239,246,WHITE);
- delay_ms(200);
- }
- LCD_ShowString(30,210,200,16,16,"OV7725 Init OK");
- delay_ms(1500);
- OV7670_Brightness(-2);
- OV7670_Contrast(-2);
- TIM6_Int_Init(9999,7199); //10Khz计数频率,1秒钟中断
- EXTI8_Init(); //使能定时器捕获
- // OV7670_Window_Set(320,240,1); //设置窗口
- // OV7725_CS=0;
-
- OV7670_Window_Set(12,176,240,320); //设置窗口
- OV7670_CS=0;
- LCD_Clear(BLACK);
- while(1)
- {
-
- POINT_COLOR=BLACK;
- camera_refresh();//更新显示
- printf("x = %d \r\n",xx);
- printf("y = %d \r\n",yy);
-
- yc=yy-220;
- xc=xx-220;
- yc=abs(yc);
- xc=abs(xc);
- ENA=yc*2+xc*1.7;
- ENB=yc*2-xc*1.7;
- if((xx<150)&&(xx>70)&&(yy<150)&&(yy>70)) {tz();ENA=0;ENB=0;}
- else if((xx<150)&&(xx>70)&&(yy<220)&&(yy>140)) {qj();}
- else if((xx<150)&&(xx>70)&&(yy<70)&&(yy>0)) {ht();}
- else if((xx<220)&&(xx>140)&&(yy<220)&&(yy>0)) {zz();}
- else if((xx<70)&&(xx>0)&&(yy<220)&&(yy>0)) {yz();}
- TIM_SetCompare2(TIM3,ENA);//ENA
- TIM_SetCompare3(TIM3,ENB); //ENB
-
-
- }
-
- }
复制代码
|
|