|
ov7640摄像头处理源码
摄像头实验(彩色,灰度,任意窗口):
- #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"
- //ALIENTEK战舰STM32开发板实验36
- //摄像头 实验
- extern u8 ov_sta; //在exit.c里面定义
- extern u8 ov_frame; //在timer.c里面定义
- extern u8 data_ready;
- u16 color_r;
- u16 color_g;
- u16 color_b;
- //设置CPU的频率
- void ov7670_clock_set(u8 PLL)
- {
- u8 temp=0;
- RCC->CFGR&=0XFFFFFFFC;
- RCC->CR&=~0x01000000;
- RCC->CFGR&=~(0XF<<18);
- PLL-=2;//抵消2个单位
- RCC->CFGR|=PLL<<18;
- RCC->CFGR|=1<<16; //PLLSRC ON
- FLASH->ACR|=0x12;
- RCC->CR|=0x01000000; //PLLON
- while(!(RCC->CR>>25));
- RCC->CFGR|=0x02;
- while(temp!=0x02)
- {
- temp=RCC->CFGR>>2;
- temp&=0x03;
- }
- }
- //更新LCD显示
- void camera_refresh()
- {
- u32 i,j;
- u16 color;
- if(ov_sta==2)
- {
- LCD_Scan_Dir(U2D_L2R); //从上到下,从左到右
- LCD_SetCursor(0x00,0x0000); //设置光标位置
- LCD_WriteRAM_Prepare(); //开始写入GRAM
- OV7670_RRST=0; //开始复位读指针
- OV7670_RCK_L;
- OV7670_RCK_H;
- OV7670_RCK_L;
- OV7670_RRST=1; //复位读指针结束
- OV7670_RCK_H;
- if(ov7670_config.mode){
- for(i=0; i<ov7670_config.height; i++)
- {
- // LCD_SetCursor(i+ov7670_config.xsta,ov7670_config.ysta); //设置光标位置
- // LCD_WriteRAM_Prepare(); //开始写入GRAM
- for(j=0; j<ov7670_config.width; j++)
- {
- OV7670_RCK_L;
- color = GPIOC->IDR&0XFF; //读数据
- OV7670_RCK_H;
-
- color<<=8;
- OV7670_RCK_L;//因为设置的是 YUYV输出,第二个字节没用,不需要读
- // color |= GPIOC->IDR&0XFF; //
- OV7670_RCK_H;
-
-
- color_r = color&0xf800;
- color_b = color>>11;
- color >>=5;
- color_g =color&0x07e0;
-
- LCD->LCD_RAM= color_r + color_g + color_b;
- }
-
- }
- }else{
- for(i=0; i<ov7670_config.height; i++)
- {
- // LCD_SetCursor(i+ov7670_config.xsta,ov7670_config.ysta); //设置光标位置
- // LCD_WriteRAM_Prepare(); //开始写入GRAM
- for(j=0; j<ov7670_config.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;
- }
-
- }
- }
- EXTI_ClearITPendingBit(EXTI_Line8); //清除LINE8上的中断标志位
- ov_sta=0; //开始下一次采集
- ov_frame++;
- LCD_Scan_Dir(DFT_SCAN_DIR); //恢复默认扫描方向
- }
- }
- int main(void)
- {
- delay_init(); //延时函数初始化
- NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- uart_init(9600); //串口初始化为9600
- LED_Init(); //LED端口初始化
- LCD_Init();
- KEY_Init();
- TPAD_Init(72); //触摸按键初始化
- usmart_dev.init(72); //初始化USMART
- POINT_COLOR=RED;//设置字体为红色
- LCD_ShowString(60,50,200,16,16,"WarShip STM32");
- LCD_ShowString(60,70,200,16,16,"OV7670 TEST");
- LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
- LCD_ShowString(60,110,200,16,16,"2012/9/14");
- LCD_ShowString(60,130,200,16,16,"OV7670 Init...");
- while(OV7670_Init())//初始化OV7670
- {
- LCD_ShowString(60,130,200,16,16,"OV7670 Error!!");
- delay_ms(200);
- LCD_Fill(60,130,239,246,WHITE);
- delay_ms(200);
- }
- LCD_ShowString(60,130,200,16,16,"OV7670 Init OK");
-
-
- TIM6_Int_Init(10000,7199); //10Khz计数频率,1秒钟中断
- EXTI8_Init(); //使能定时器捕获
- OV7670_CS=0;
-
- config_ov7670_OutPut(20,60,320,240,1);
- while(1)
- {
- camera_refresh();//更新显示
- }
- }
复制代码
|
|