⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 模拟ccd摄像头的图像采集程序。采集方式为隔行实时采集
💻 C
字号:
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
///////////////////////////////////////////////////////////////////////////////////////
//全数字视频采集1.0
//Designed by Zhaoliang/2007/6/20
//CPU总线时钟48MHz
//采集分辨率35*25
//采集范围中间280行,每8行一采
//T值计算公式:T=t(s)*3000000
//////////////////////////////////////////////////////////////////////////////////////////////
#define  DELAY_US     {__asm nop;__asm nop;__asm nop;__asm nop;__asm nop;__asm nop;__asm nop;__asm nop;}
#define  ILL       280   //Image Line Limit
#define  IDL			 25		//Image Dot Limit
#define  IILLT		 4320 //Image Initial Line Locate Time   1.44ms*3000000=4320
#define  IIDLT		 31		//Image Initial Dot Locate Time    10.4us*3000000=31.2
#define  START_SAMPLE    0xa
#define  WAIT_TO_SAMPLE  0xb
#define  FINISH_SAMPLE   0xc

uchar Image[36][25]={0} ;
uchar VideoFinFlag,VideoLineCount,VideoDotCount;
uchar VSS;  //Video Sample Status
int i,T;

void InputInit(){
  TIOS=0X00;     //channel 0 input capture
  TCTL4=0X55;    //capture rising edge
  TSCR2=0X07;    //64KHZ
  TIE=0Xff;      //channel 0 interrupt enable
  TSCR1=0X90;    //Timer enable
}




void PLL_Init(void) {
  REFDV=0x01; 
  SYNR=0x02;						    //Set the system clock 48MHz
}

void Start_PLL(void) {
  asm{
    BRCLR CRGFLG,#$08,*
    BSET CLKSEL,#$80
    }													  
}



void MDCInit(void){
  MCCTL = MCCTL&0Xfb; //模数计数器禁止运行
  MCCTL = 0Xe2;       //允许中断,模数计数方式  返回时重新加载所用的常数,分频常数为8   
  MCCTL_MCEN=1; //模数计数器使能                   
  MCCNT = T;    
  MCCTL = MCCTL|0X08  ; //把模数常数寄存器的值加载到模数计数器
  
                  
}


void interrupt 26 MDC_ISR(void){
  MCCTL_MCEN=0; //模数计数器关闭
  MCFLG = 0x80; 	 //清标志位
  switch (T){
    
  case IILLT:
    
    INTCR=0x40;//IRQ地点平触发,使能
    VSS=WAIT_TO_SAMPLE;
    break;
  case IIDLT:
    INTCR_IRQEN=1;
    VSS=START_SAMPLE;
    break; 
  
  
  }
}

void Video_Init(void){
  
  INTCR_IRQEN=0;
 

}




void main(void){
  DisableInterrupts;

  DDRA = 0xFF;
  PORTA = 0x00;
  PORTA = 0xFF;
  PLL_Init();
  Start_PLL();
  
  Video_Init();
  
  
  for(;;){
    EnableInterrupts;  
  }
  
}

void VideoSample(){
  uchar i,j,line;
  while(PTJ_PTJ1);
  T=IILLT;		 //4320 = 1.44ms
  MDCInit();
  for(;;){
    
    
    if(VSS==FINISH_SAMPLE){
      VideoFinFlag=1;
      break;
    } else if(VSS==WAIT_TO_SAMPLE);
    else if(VSS=START_SAMPLE){
      line=VideoLineCount/8;
      for(;VideoDotCount<25;VideoDotCount++) {
        DELAY_US;
        DELAY_US;
        Image[line][VideoDotCount]=PORTA_BIT7;
      }
    
    
    
    }
  
  }
  
}

void interrupt 6 IRQ_ISR(){
  
  INTCR_IRQEN=0;//关闭IRQ中断
  VideoLineCount++;
  if(VideoLineCount>=ILL){ //ILL:采集行数
    
    VSS=FINISH_SAMPLE;
    VideoLineCount=0;
    VideoDotCount=0;
  } else{
    if((VideoLineCount%8)==0) {				 //采集0,8,16...280共36行
      VideoDotCount=0;
      T=IIDLT;				 //31 =	 10.4us
      MDCInit();
      
    } else {
      VideoLineCount++;
      INTCR_IRQEN=1;
    }
      
  
}
  
  
  
  
  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -