飞思卡尔 摄像头 程序
#include
#include "derivative.h"
#include
#define ROW 40 //Êý×ÖÉãÏñÍ?Ëù?É??µÄ?þÎ?Êý×éÐÐÊý #define COLUMN 120 //Êý×ÖÉãÏñÍ?Ëù?É??µÄ?þÎ?Êý×éÁÐÊý #define ROW_START 10 //Êý×ÖÉãÏñÍ??þÎ?Êý×éÐÐ?ªÊ?ÐÐÖµ #define ROW_MAX 200
//Êý×ÖÉãÏñÍ?Ëù?É??µÄ?þÎ?Êý×éÐÐ×î?óÖµ
#define THRESHOLD 0x68
//Í?ÏñãÐÖµ???ù?ÝËù?É??Í?ÏñÁÁ?ÈÖµ?óÐ?µÄʵ?ÊÇé?öµ?Õû??OV7620Ëù?É??µÄÁÁ?ÈÖµ?óÐ?Ϊ0--255??
unsigned char Buffer[ROW][COLUMN]={0}; //Ëù?É??µÄÍ?Ïñ?þÎ?Êý×é unsigned char Image_Center[ROW]={0}; //Ëù?É??µÄÍ?ÏñÖÐÐÄÏß
unsigned char SampleFlag=0; //ÆæÅ????ê?Ç
unsigned int m=0; //??ÐÐ?äÁ?
unsigned int Line; //ÐÐÖÐ?Ï?ÆÊý?äÁ?
unsigned int hang;
unsigned int Get_Image[]={
17,19,21,23,25,28,31,34,37,40,43,46,49,53,57,
61,65,69,73,77,81,85,89,94,99,105,111,117,123,
129,135,141,147,153,159,166,173,180,187
}; //??Ã????ÉÄÄ??ÐÐ??
/*************************************************************/ /* ?õÊ???PLLº?Êý */ /*************************************************************/ void PLL_Init(void) {
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR =0xc0 | 0x09;
REFDV=0x80 | 0x01;
POSTDIV=0x00;
//pllclock=2*osc*(1+SYNR)/(1+REFDV)=160MHz;
_asm(nop); //BUS CLOCK=80M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
/*************************************************************/ /* ÐÐ??ÖÐ?Ï?õÊ???º?Êý */ /*************************************************************/ void TIM_Init(void)
{
TIOS=0x00; //Íâ??ÊäÈë??×?0,1Í?µÀ
TCTL4=0x09; //Í?µÀ0 ÉÏÉýÑØ????,Í?µÀ1ÏÂ?µÑØ????
TSCR1=0x80; //Ê?ÄÜ
TIE=0x03; //Í?µÀ 0??1 ÖÐ?ÏÊ?ÄÜ
TFLG1=0xFF; //ÇåÖÐ?Ï?êÖ?Î?
}
/*************************************************************/ /* IO?Ú?õÊ???º?Êý */ /*************************************************************/
void IO_Init(void)
{
DDRA=0X00; //?Ë?ÚAÅäÖÃ?ÉÊäÈë
}
/*************************************************************/ /* ÑÓÊ?º?Êý */ /*************************************************************/
void delays(long m){
while(m--);
}
/*************************************************************/ /* ???Ú0?õÊ???º?Êý */
/*************************************************************/ void SCI_Init()
{
SCI0BD=261; //19200bps Baud Rate=BusClock/(16*SCIBD)
//SCI0BD=521;
SCI0CR1=0; //Õý??8 Î?Ä?Ê???ÎÞÆæÅ?Ð?Ñé
SCI0CR2=0X2C; //??ËÍÔÊÐí ?ÓÊÜÖÐ?ÏÔÊÐí }
/*************************************************************/ /* ???Ú0??Ëͺ?Êý */ /*************************************************************/ void SCI_Write(unsigned char SendChar)
{
while (!(SCI0SR1&0x80));
SCI0DRH=0;
SCI0DRL=SendChar;
}
/*************************************************************/ /* ÏòµçÄÔ???Ú??ËÍËù?É??µÄÍ?Ïñ */ /*************************************************************/
void Process()
{
unsigned char i,j;
for(i=0;i=THRESHOLD)
SCI_Write('1') ;
else SCI_Write('0') ;
}
SCI_Write(0x0D);
SCI_Write(0X0A);
}
}
/*************************************************************/ /* Ö?º?Êý */ /*************************************************************/ void main(void)
{
/* put your own code here */
PLL_Init();
TIM_Init();
IO_Init();
SCI_Init();
EnableInterrupts;
for(;;)
{
Process(); //ÏòµçÄÔ???Ú??ËÍËù?É??µÄÍ?Ïñ
}
// _FEED_COP(); /* feeds the dog */
/* loop forever */
/* please make sure that you never leave main */ }
/*************************************************************/ /* ÐÐÖÐ?Ï??Àíº?Êý */ /*************************************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 8 PT0_Interrupt()
{
TFLG1_C0F=1; //ÐÐÖÐ?Ï?êÖ?Î?Çå?ý??ÒÔ?ãÓÚÏÂ?ÎÐÐÖÐ?Ï?øÐÐ
Line++; //ÐÐÖÐ?Ï?ÆÊý?äÁ?
if ( SampleFlag == 0 || LineROW_MAX )
{
return; //??ÊÇÒª?É??Í?ÏñµÄÓÐÐ?ÐÐ???µ?Ø
}
if( Line==Get_Image[hang])
{
delays(8);
Buffer[m][0]=PORTA;_asm();Buffer[m][1]=PORTA;_asm();Buffer[m][2]=PORTA;_asm();Buffer[m][3]=PORTA;_asm();Buffer[m][4]=PORTA;_asm();
Buffer[m][5]=PORTA;_asm();Buffer[m][6]=PORTA;_asm();Buffer[m][7]=PORTA;_asm();Buffer[m][8]=PORTA;_asm();Buffer[m][9]=PORTA;_asm();
Buffer[m][10]=PORTA;_asm();Buffer[m][11]=PORTA;_asm();Buffer[m][12]=PORTA;_asm();Buffer[m][13]=PORTA;_asm();Buffer[m][14]=PORTA;_asm();
Buffer[m][15]=PORTA;_asm();Buffer[m][16]=PORTA;_asm();Buffer[m][17]=PORTA;_asm();Buffer[m][18]=PORTA;_asm();Buffer[m][19]=PORTA;_asm();
Buffer[m][20]=PORTA;_asm();Buffer[m][21]=PORTA;_asm();Buffer[m][22]=PORTA;_asm();Buffer[m][23]=PORTA;_asm();Buffer[m][24]=PORTA;_asm();
Buffer[m][25]=PORTA;_asm();Buffer[m][26]=PORTA;_asm();Buffer[m][27]=PORTA;_asm();Buffer[m][28]=PORTA;_asm();Buffer[m][29]=PORTA;_asm();
Buffer[m][30]=PORTA;_asm();Buffer[m][31]=PORTA;_asm();Buffer[m][32]=PORTA;_asm();Buffer[m][33]=PORTA;_asm();Buffer[m][34]=PORTA;_asm();
Buffer[m][35]=PORTA;_asm();Buffer[m][36]=PORTA;_asm();Buffer[m][37]=PORTA;_asm();Buffer[m][38]=PORTA;_asm();Buffer[m][39]=PORTA;_asm();
Buffer[m][40]=PORTA;_asm();Buffer[m][41]=PORTA;_asm();Buffer[m][42
]=PORTA;_asm();Buffer[m][43]=PORTA;_asm();Buffer[m][44]=PORTA;_asm();
Buffer[m][45]=PORTA;_asm();Buffer[m][46]=PORTA;_asm();Buffer[m][47]=PORTA;_asm();Buffer[m][48]=PORTA;_asm();Buffer[m][49]=PORTA;_asm();
Buffer[m][50]=PORTA;_asm();Buffer[m][51]=PORTA;_asm();Buffer[m][52]=PORTA;_asm();Buffer[m][53]=PORTA;_asm();Buffer[m][54]=PORTA;_asm();
Buffer[m][55]=PORTA;_asm();Buffer[m][56]=PORTA;_asm();Buffer[m][57]=PORTA;_asm();Buffer[m][58]=PORTA;_asm();Buffer[m][59]=PORTA;_asm();
Buffer[m][60]=PORTA;_asm();Buffer[m][61]=PORTA;_asm();Buffer[m][62]=PORTA;_asm();Buffer[m][63]=PORTA;_asm();Buffer[m][64]=PORTA;_asm();
Buffer[m][65]=PORTA;_asm();Buffer[m][66]=PORTA;_asm();Buffer[m][67]=PORTA;_asm();Buffer[m][68]=PORTA;_asm();Buffer[m][69]=PORTA;_asm();
Buffer[m][70]=PORTA;_asm();Buffer[m][71]=PORTA;_asm();Buffer[m][72]=PORTA;_asm();Buffer[m][73]=PORTA;_asm();Buffer[m][74]=PORTA;_asm();
Buffer[m][75]=PORTA;_asm();Buffer[m][76]=PORTA;_asm();Buffer[m][77]=PORTA;_asm();Buffer[m][78]=PORTA;_asm();Buffer[m][79]=PORTA;_asm();
Buffer[m][80]=PORTA;_asm();Buffer[m][81]=PORTA;_asm();Buffer[m][82]=PORTA;_asm();Buffer[m][83]=PORTA;_asm();Buffer[m][84]=PORTA;_asm();
Buffer[m][85]=PORTA;_asm();Buffer[m][86]=PORTA;_asm();Buffer[m][87]=PORTA;_asm();Buffer[m][88]=PORTA;_asm();Buffer[m][89]=PORTA;_asm();
Buffer[m][90]=PORTA;_asm();Buffer[m][91]=PORTA;_asm();Buffer[m][92]=PORTA;_asm();Buffer[m][93]=PORTA;_asm();Buffer[m][94]=PORTA;_asm();
Buffer[m][95]=PORTA;_asm();Buffer[m][96]=PORTA;_asm();Buffer[m][97
]=PORTA;_asm();Buffer[m][98]=PORTA;_asm();Buffer[m][99]=PORTA;_asm();
Buffer[m][100]=PORTA;_asm();Buffer[m][101]=PORTA;_asm();Buffer[m][102]=PORTA;_asm();Buffer[m][103]=PORTA;_asm();Buffer[m][104]=PORTA;_asm();
Buffer[m][105]=PORTA;_asm();Buffer[m][106]=PORTA;_asm();Buffer[m][107]=PORTA;_asm();Buffer[m][108]=PORTA;_asm();Buffer[m][109]=PORTA;_asm();
Buffer[m][110]=PORTA;_asm();Buffer[m][111]=PORTA;_asm();Buffer[m][112]=PORTA;_asm();Buffer[m][113]=PORTA;_asm();Buffer[m][114]=PORTA;_asm();
Buffer[m][115]=PORTA;_asm();Buffer[m][116]=PORTA;_asm();Buffer[m][117]=PORTA;_asm();Buffer[m][118]=PORTA;_asm();Buffer[m][119]=PORTA;_asm();
Buffer[m][120]=PORTA;
hang++;
m++;
}
}
/*************************************************************/ /* ??ÖÐ?Ï??Àíº?Êý */ /*************************************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 9 PT1_Interrupt()
{
TFLG1_C1F=1;
//??ÖÐ?ÏÇå?þ??ÒÔ?ãÓÚÏÂ?εÄ??ÖÐ?ϵÄÕý???øÐÐ
TFLG1_C0F=1;
//ÐÐÖÐ?ÏÇå?ý??ÒÔ?ãÓÚ?ªÊ??É??Í?ÏñÊý?Ý
m=0;
//ÐÐÖÐ?ä?äÁ?ÇåÁã??ÒÔ?ãÓÚ?ªÊ??Ó?Ñ?É??µÄÍ?Ïñ?ŵ?Êý×éµÄµÚÒ?ÐÐ
Line=0; //ÐÐÖÐ?ÏÁÙÊ??äÁ?ÇåÁã
hang=0; //ÐÐÁÙÊ??äÁ?Çå?ý
SampleFlag=~SampleFlag;
//??ÖÐ?Ï?ê?ÇÈ?????ÕâÑùÖ??É??ÆæÊý??µÄÍ?Ïñ
}