|
單片機(jī)源程序如下:
- #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"
-
- int main(void)
- {
- int i;
- delay_init(); //延時函數(shù)初始化
- NVIC_Configuration(); //設(shè)置NVIC中斷優(yōu)先級
- uart_init(9600); //串口初始化為9600
- LED_Init(); //LE端口初始化
- LCD_Init();
- usmart_dev.init(72); /初始化USMART
- POINT_COLOR=BLUE; //字體設(shè)置為藍(lán)色
- LCD_ShowString(60,50,200,16,16,"ROBOT_Program");
- LCD_ShowString(60,70,200,16,16,"Testing.....");
- LCD_ShowString(60,230,200,16,16,"OV7670 Init......");
-
- while(OV7670_Init())//初始化OV7670
- {
- LCD_ShowString(60,230,200,16,16,"OV7670 Error!!");
- delay_ms(200);
- LCD_Fill(60,230,239,246,WHITE);
- delay_ms(200);
- }
-
- LCD_ShowString(60,230,200,16,16,"OV7670 Init OK");
- delay_ms(1500);
-
- EXTI8_Init();
-
- OV7670_CS=0;
- while(1)
- {
- refresh_BW();
- }
- }
- /*函數(shù)功能:黑白二值化(BLACK-WHITE)
- * 函數(shù)名稱:refresh_BW();
- */
- void refresh_BW(void)//
- {
- u32 j;
- u16 color;
-
- if(ov_sta==2)
- {
- LCD_Scan_Dir(U2D_L2R); //從上到下,從左到右 刷新
- LCD_SetCursor(0,0); //設(shè)置光標(biāo)
- LCD_WriteRAM_Prepare(); //開始寫入GRAM
- OV7670_CS=0;
- OV7670_RRST=0; //開復(fù)位度指針
- OV7670_RCK=0;
- OV7670_RCK=1;
- OV7670_RCK=0;
- OV7670_RRST=1; //讀指針結(jié)束
- OV7670_RCK=1;
-
- for(j=0;j<76800;j++)
- {
- OV7670_RCK=0;
- OV7670_RCK=1;
- color=GPIOC->IDR&0XFF; //讀數(shù)據(jù)
- OV7670_RCK=0;
- OV7670_RCK=1;
- color=GPIOC->IDR&0XFF; //讀數(shù)據(jù)
- color>>=5;
-
- if(color>0x03)
- color=0xffff;
- else
- color=0x0000;
- LCD->LCD_RAM=color;
-
- }
- OV7670_CS=1;
- OV7670_RCK=0;
- OV7670_RCK=1;
- EXTI_ClearITPendingBit(EXTI_Line8); //清除LINE8上的中斷標(biāo)志位
- ov_sta=0; //開始下一次采集
-
- LCD_Scan_Dir(DFT_SCAN_DIR); //回復(fù)默認(rèn)掃描方向
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
黑白二值化.rar
(357.12 KB, 下載次數(shù): 27)
2018-3-7 19:21 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評分
-
查看全部評分
|