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

📄 main.c

📁 对摄像头用MCU进行数据采集与分析
💻 C
📖 第 1 页 / 共 2 页
字号:
 }
 /*
*******************************************************************************
** 函数名称:void LR_UD_move(uint8 x,uint8 y)
** 函数功能:步进电机要动作的方向
** 入口参数:当前camera采集到的像素点位置
** 出口参数:给出动作标志
*******************************************************************************
*/
void UD_judge(uint8 y)
{   if(y>70)      UD_move_flag =1;
    else if(y>50) UD_move_flag =0;
    else if(y>1)  UD_move_flag =2;
    else          UD_move_flag =0;
}
/*
*******************************************************************************
** 函数名称:void LR_UD_move(uint8 x,uint8 y)
** 函数功能:步进电机要动作的方向
** 入口参数:当前camera采集到的像素点位置
** 出口参数:给出动作标志
*******************************************************************************
*///uint8 motorUD_end_flag=3;
void UDmotor_move(void)
{   switch(UD_move_flag)
    {   case 0:motorUD_end_flag = 1;break;
        case 1:IO0CLR = DIU;break;
        case 2:IO0SET = DIU;break;
    }
}

 /*
*********************************************************************************************************
** 函数名称 :IRQ_T0()
** 函数功能 :T1定时器中断服务程序
** 入口参数 :无
** 出口参数 :匹配输出脉冲
*********************************************************************************************************
*/
void __irq IRQ_T0 (void)
{  //static uint8 re_p;
   //samp_end_flag =0; 
    //      end_flag = 0;
     //     IO0CLR = RR;
          //VICIntEnable = 1<<0x0e;
   T0IR = 0x01;
   VICVectAddr = 0x00;			            // 中断处理结束
}
  /*
*********************************************************************************************************
** 函数名称 :T0_Init()
** 函数功能 :T0定时器初始化,设置工作模式。
** 入口参数 :
*********************************************************************************************************
*/
void T0_Init ()
 { 
    T0TC   = 0;							// 定时器初值设置为0
    T0PR   = 0;							// 时钟不分频,(1秒计数Fpclk个脉冲)
    T0MCR  = 0x03;						// 设置T0MR0匹配后复位T0TC,并产生中断标志
    T1EMR  = 0xc00;                      // T1MR0匹配否MAT0.3输出翻转
    T0MR0  = Fpclk;					// 0.5秒定时,匹配寄存器MR0等于1/2的计数频率
    T0TCR  = 0x01;						// 启动定时器
 }
 
/*
*********************************************************************************************************
** 函数名称 :SYS_Init()
** 函数功能 :系统初始化,设置接口和中断寄存器。
** 入口参数 :
** 出口参数 :
*********************************************************************************************************
*/ 
void SYS_Init()
{  
    LCD_IO_Init();   
    //LCD_Initialize();
    
    T1_Init ();
    //T0_Init ();
    camerINT_Init();
    
    VICIntSelect = 0x00000000;			// 设置所有的通道为IRQ中断
    
    VICVectCntl0 = 0x20 | 0x04;			// 定时器T1分配到IRQ slot5,即次高优先级
    VICVectAddr0 = (uint32)IRQ_T0; 		// 设置T1中断向量 
    VICIntEnable = 1 << 0x04;	  		// 使能T1中断		
    
    VICVectCntl0 = 0x20 | 0x05;			// 定时器T1分配到IRQ slot5,即次高优先级
    VICVectAddr0 = (uint32)IRQ_T1; 		// 设置T1中断向量 
    VICIntEnable = 1 << 0x05;	  		// 使能T1中断		
    
	//IRQEnable();						// 使能IRQ中断
	
    VICVectCntl1 = 0x20 | 0x0e;			// 外部中断0分配到IRQ slot14,即次高优先级
    VICVectAddr1 = (uint32)IRQ_Eint0;   // 设置外部中断0中断向量 
    EXTINT       |= 0x01;                // 清除EINT0中断标志
   // VICIntEnable = 1 << 0x0e;	  		// 使能外部中断0中断	
    
    VICVectCntl2 = 0x20 | 0x0f;			// 外部中断0分配到IRQ slot14,即次高优先级
    VICVectAddr2 = (uint32)IRQ_Eint1;   // 设置外部中断0中断向量 
    EXTINT       |= 0x02;                // 清除EINT0中断标志
   // VICIntEnable = 1 << 0x0f;	  		// 使能外部中断0中断	
   
    VICVectCntl3 = 0x20 | 0x10;			// 外部中断0分配到IRQ slot14,即次高优先级
    VICVectAddr3 = (uint32)IRQ_Eint2;   // 设置外部中断0中断向量 
    EXTINT       |= 0x04;                // 清除EINT0中断标志
   // VICIntEnable = 1 << 0x0f;	  		// 使能外部中断0中断	
    IRQEnable();						// 使能IRQ中断 
}
/*
*******************************************************************************
** 函数名称:void display_xoy(uint8 x,uint8 y)
** 函数功能:显示找到该点的坐标置
** 入口参数:x,y
** 出口参数:显示坐标
*******************************************************************************
*/
void display_xoy(uint8 x,uint8 y)
{   uint8 i,x0[3],y0[3];
    x0[0]=x/100; x0[1]=x%100/10; x0[2]=x%10;
    y0[0]=y/100; y0[1]=y%100/10; y0[2]=y%10;
    for(i=0;i<3;i++)
    {   LCD_hz816(200+8*i, 120,x0[i]);
        LCD_hz816(200+8*i, 136,y0[i]);
    }
}
/*
*******************************************************************************
** 函数名称:camer_data_handle(void)
** 函数功能:将摄像头的数据转换成在LCD上显示的数据
** 入口参数:camer0[19][200]的数据
** 出口参数:显示出该画面
*******************************************************************************
*/
void display_XOY(uint8 dx,uint8 dy)
{   uint8 i,j,m,n,ok,kc=0;
    for(i=0;i<120;i++)
    {    for(j=0;j<160;j++)
         {   if(camer0[i][j] >0xb0)
             {   ok = 0;
                 for(m=0;m<dx;m++)
                 {    for(n=0;n<dy;n++)
                      {   if(camer0[i+m][j+n] >0xb0)
                             ok++;
                      }
                 }
             }
             if(ok==dx*dy)
                 break; 
         }
         if(ok==dx*dy)
         {  kc =1;break; }
    }
    if(kc==1)
    {   display_xoy(j+(dy/2),i+(dx/2)); 
        X_line = j+(dy/2);
        Y_line = i+(dx/2);
        //LR_UD_judge(j+(dy/2),i+(dx/2));
        //motor_move();
    }
    else
    {   X_line = 0;
        Y_line = 0;
    }
    for(i=0;i<120;i++)
        for(j=0;j<160;j++)
            camer0[i][j]=0;
}
/*
*******************************************************************************
** 函数名称:camer_data_handle(void)
** 函数功能:将摄像头的数据转换成在LCD上显示的数据
** 入口参数:camer0[19][200]的数据
** 出口参数:显示出该画面
*******************************************************************************
*/
//uint16 light_unit;   // 计算出点亮点的个数
/*id camer_data_handle(void)
{   uint8 i;//,k;
    uint16 j;  
    //light_unit = 0;light_unit++;
    for(i=0;i<120;i++)
        for(j=0;j<160;j++)
        {   if(camer0[i][j]>=0xbf)
            {    pic_camer[i][j/8] |= 0x01<<(7-(j%8));   }
            else 
                 pic_camer[i][j/8] &= ~(0x01<<(7-(j%8)));
        }
}*/
/*******************************************************************************************
**函数名称:LCD_picture()
**函数功能:显示camer所拍到的图片
**入口参数:无
**返 回 值:无
**说    明:由于没有灰度级,这里假设一个值:大于这个的点亮,小于这个的熄灭。
*******************************************************************************************/
void LCD_Picture(uint8 x,uint8 y)
{   uint8 i,j;
    
    for(i=0; i<120; i++)
    {
        IO_CMD(0,i);
        IO0CLR = CS;
        IO0CLR = CS;
        
        IO0SET = RS;
        IO0SET = RS;     
        for(j=0; j<160; j++)
        {
            IO_Snd_Date(camer0[i][j]);
        }
    }
    IO0SET = CS;                                                      // 关闭LCD片选
}
/*******************************************************************************************
**函数名称:Camera_Init()
**函数功能:摄像头初始化
**入口参数:无
**返 回 值:无
**说    明:控制寄存器各项初始化
*******************************************************************************************/
void Camera_Init(void)
{    
    Write_One_Byte(0x00,0x1a);
    Write_One_Byte(0x01,0x6f);
    Write_One_Byte(0x02,0x7a);
    Write_One_Byte(0x03,0xb0);
    Write_One_Byte(0x06,0x4d);
    Write_One_Byte(0x07,0x00);
    Write_One_Byte(0x0c,0x24);
    Write_One_Byte(0x0d,0x24);
    Write_One_Byte(0x10,0x7f);
    Write_One_Byte(0x14,0xa4);
    Write_One_Byte(0x15,0x01);
    Write_One_Byte(0x16,0x03);
    Write_One_Byte(0x17,0x2f);
    Write_One_Byte(0x19,0x06);
    Write_One_Byte(0x1a,0xf5);
    Write_One_Byte(0x1b,0x00);
    Write_One_Byte(0x21,0x85);
    Write_One_Byte(0x22,0x03);
    Write_One_Byte(0x23,0x00);
    Write_One_Byte(0x24,0x20);
    Write_One_Byte(0x25,0x30);
    Write_One_Byte(0x26,0xa2);
    Write_One_Byte(0x27,0xea);
    Write_One_Byte(0x29,0x08);
    Write_One_Byte(0x2a,0x90);
    Write_One_Byte(0x2b,0xac);
    Write_One_Byte(0x2c,0x88);
    Write_One_Byte(0x2d,0xd5);
    Write_One_Byte(0x2e,0x01);
    Write_One_Byte(0x60,0x27);
    Write_One_Byte(0x61,0x02);
    Write_One_Byte(0x62,0x5f);
    Write_One_Byte(0x64,0x57);
    Write_One_Byte(0x65,0x83);
    Write_One_Byte(0x66,0x55);
    Write_One_Byte(0x67,0xb0);
    Write_One_Byte(0x68,0xef);
    Write_One_Byte(0x69,0x76);
    Write_One_Byte(0x6a,0x22);
    Write_One_Byte(0x6f,0x1d);
    Write_One_Byte(0x70,0x8b);
    Write_One_Byte(0x71,0x00);
    Write_One_Byte(0x72,0x14);
    Write_One_Byte(0x73,0x54);
    Write_One_Byte(0x74,0x20);
    Write_One_Byte(0x75,0x8e);
    Write_One_Byte(0x76,0x00);
}
/*
*********************************************************************************************************
** 函数名称 :void main( void )
** 函数功能 :主函数
** 入口参数 :无
** 出口参数 :无
** 函数说明 :所有操作的调配
*********************************************************************************************************
*/ uint8 read_dt[124]; 
int main (void)
{   //uint8 i;
        
    SYS_Init();
    IO0SET = CS;
    IO0SET = WR;                
    IO0SET = RS; 
    IO0SET = RR;
    IO0SET |= 0x00000080;                // 开使能
    T1EMR = 0x00;
    VICIntEnClr = 1 << 0x05;
    LCD_clear(0xbf);
    
    Camera_Init();

    Write_One_Byte(0x18,0x7f);

    Write_One_Byte(0x11,0x25);
    Write_One_Byte(0x12,0x1f);
    Write_One_Byte(0x13,0x21);
    Write_One_Byte(0x28,0x40);
    Write_One_Byte(0x20,0x42);
    read_dt[0]=Read_One_Byte(0x43,0x18);
    read_dt[1]=Read_One_Byte(0x43,0x11);
    read_dt[2]=Read_One_Byte(0x43,0x12);
    read_dt[3]=Read_One_Byte(0x43,0x13);
    read_dt[4]=Read_One_Byte(0x43,0x28);
    read_dt[5]=Read_One_Byte(0x43,0x20);
    DELAY(50000);
    VICIntEnable = 1 << 0x0e;
    while(1)
    {  if(samp_end_flag==1 && end_flag==1)
       {  IO0SET = RR;
          VICIntEnClr = 1<<0x0e;
          
          LCD_clear(0x00);
          LCD_Picture(0,0);
          
          display_XOY(2,2);
          if((X_line>90 || X_line<70) && motor_end_flag ==3)
              motor_end_flag =0;
          
          samp_end_flag =0; 
          end_flag = 0;
          IO0CLR = RR;
          VICIntEnable = 1<<0x0e;
       }
       if(motor_end_flag ==1)
       {   T1EMR = 0x00;
           VICIntEnClr = 1 << 0x05;
           motor_end_flag =3;
       }
       if(motor_end_flag ==0)
       {   T1EMR = 0x30;
           VICIntEnable = 1 << 0x05;
           IO0CLR |= 0x00000080;                // 开使能
           motor_end_flag =4;
       }
       
    }
    return 0;
}
/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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