void Moto_Control(void) { //unsigned char Left = SPEED; //unsigned char Right = SPEED; if(dir == 0xF1) //下楼 { PITINTE = 0x00; // 关闭0路中断 SCI0CR2_RE = 0; //串口接收停止 stage = 0xF1; //moto_run(15,15); Delay_ms(1000); //延时5s dir = 255; SCI0CR2_RE = 1; //串口接收使能 PITINTE = 0x01; //打开0路中断 } else if(dir == 0xF2) { stage = 0xF2; dir = 255; } else if(dir == 0xF3) { stage = 0xF3; dir = 255; } else if(dir == 0xF4) { stage = 0xF4; dir = 255; } if(!dir) //路标不在视野内 { flag = 0; if((!flag)&&flag_old) //丢帧处理 { moto_run(0,0); //while(!dir); PITINTE = 0x00; // 关闭0路中断 Delay_ms(100); PITINTE = 0x01; // 关闭0路中断 } else { if(stage == 0xF1) //第一阶段 { moto_run(40,-20); //右转,直到第一个路标出现 } else if(stage == 0xF2) //第二阶段 { moto_run(-20,40); //左转,直到第二个路标出现 } else if(stage == 0xF3) //第三阶段 { moto_run(-20,40); //左转,直到第三个路标出现 } else if(stage == 0xF4) //第四阶段 { /* temp++; if(temp == 1) stage_4_flag = 1; if(stage_4_flag) { PITINTE = 0x00; // 关闭0路中断 moto_run(30,30); //直行一段 Delay_ms(3000); stage_4_flag = 0; //清标志 PITINTE = 0x01; // 打开0路中断 } */ moto_run(40,-20); //右转,直到第四个路标出现 } } flag_old = flag; } if((dir >= 26)&&(dir <= 34)) //途中...... { flag = 1; flag_old = flag; Left = (dir - 30) * P; Right = (30 - dir) * P; Left_old = Left; Right_old = Right; moto_run(Left + SPEED,Right + SPEED); } else if(dir == 255) { moto_run(45,45); } }
void main(void) { sys_init(); //初始化电机控制信号 //subdiv = 16; moto_set(int_speed,subdiv); //Shutter = 0; //Focus = 0; //moto_run(100); // Global enable interrupts #asm("sei") Lcd_Init(); delay_ms(5); Init_BH1750(); //初始化BH1750 Clear_Scr(); MenuInitialation(); ShowMenu(); UserChooseR = 1; while(1) { if(time_10ms) //10ms定时扫描键盘 { time_10ms = 0; *pRockValue=No_rock; rocker_type = Read_Rocker(pRockValue); if(rocker_type == keyPressed) { switch(*pRockValue) { case Down: UserChooseR ++; if(UserChooseR == 3) { UserChooseR = 1; } break; case Enter: TempMenu = MenuPoint; Clear_Scr(); if(MenuPoint[UserChooseR].ChildrenMenus != NULL) { MenuPoint = MenuPoint[UserChooseR].ChildrenMenus; //UserChooseR = 0; //DisplayStart = 0; } ShowMenu(); if(TempMenu[UserChooseR].Subs != NULLSubs) { (*TempMenu[UserChooseR].Subs)(); } //Clear_Scr(); break; } Set_Cursor(UserChooseR,1); //ShowMenu(); } key_value= Read_keyboard(); if(key_value != No_key) { switch(key_value) { case Esc: work_mode = 0; work_state = idle_state; //TIMSK &= ~(1<<OCIE2); break; case OK: work_mode = 1; //TIMSK |= (1<<OCIE2); break; case 0: moto_zero('A'); break; case 1: moto_zero('B'); break; default: break; } } } switch(work_state) { case idle_state: if(work_mode) { work_state = step_run; } break; case step_run: moto_run(Int_step); work_state = start_expos; break; case start_expos: if(run_finish) { if( expos_mode == camera ) { expos_value = def_tv; } else if( expos_mode == sensor ) { expos_value = Get_TV();} else { expos_value = (long)1000*Str2Int(TV);} flag_1ms = 0; Shutter = 1; Focus = 1; work_state = stop_expos; } break; case stop_expos: if(expos_finish) { expos_finish = 0; photo_taken++; photo_left = exp_photos - photo_taken; work_state = delay_state; cnt_10ms = 0; } break; case delay_state: if(photo_taken == exp_photos) { work_mode = 0; } if(delay_finish) { delay_finish = 0; work_state = idle_state; } break; default: break; } } }