C言語
12 /*インクルード***********************************************************/3 #include "lpc13xx.h"4 #include "gpio.h"5 #include "vs-wrc103.h"6 #include "ixbus.h"7 #include <time.h>8 time_t time(time_t *t);9 10 /*マクロ***********************************************************/11 12 /*グローバル変数***********************************************************/13 14 /*メイン関数***********************************************************/15 int main (void)16 {17 //制御周期の設定[単位:Hz 範囲:30.0~]18 const unsigned short MainCycle = 60;19 Init(MainCycle); //CPUの初期設定20 21 while(getSW() != 1);22 while(getSW() ==1);23 Mtr_Run_lv(0,0,0,0,0,0);24 LED(3);25 26 unsigned short L_Sensor;27 unsigned short R_Sensor;28 29 int R_count=0;30 int L_count=0;31 int R_second=0;32 int L_second=0;33 Mtr_Run_lv(8000,-8000,0,0,0,0);34 35 time_t start,end;36 time(&start);37 LED(0);38 Wait(1999900);39 40 41 //ループ42 while(end-start>10){43 L_Sensor=ADRead(0);44 R_Sensor=ADRead(1);45 46 time(&end);47 48 if(L_Sensor>512&&R_Sensor>512){49 50 if(R_second==1){51 Mtr_Run_lv(10000,0,0,0,0,0);52 Wait(1000);53 R_count=0;54 L_count=0;55 R_second=0;56 LED(0);57 58 }else if(L_second==1){59 Mtr_Run_lv(0,-10000,0,0,0,0);60 Wait(1000);61 R_count=0;62 L_count=0;63 L_second=0;64 LED(0);65 66 67 }else if(R_count>L_count){68 69 Mtr_Run_lv(0,-10000,0,0,0,0);70 Wait(1000);71 LED(1);72 R_second++;73 74 75 }else if(R_count<L_count){76 77 Mtr_Run_lv(10000,0,0,0,0,0);78 Wait(1000);79 LED(0);80 L_second++;81 82 }83 84 }else if(L_Sensor>512){85 L_count++;86 Mtr_Run_lv(8000,0,0,0,0,0);87 R_count=0;88 LED(0);89 }else if(R_Sensor>512){90 R_count++;91 Mtr_Run_lv(0,-8000,0,0,0,0);92 L_count=0;93 LED(0);94 }else if(R_Sensor<512&&L_Sensor<512){95 Mtr_Run_lv(8000,-8000,0,0,0,0);96 LED(0);97 98 }99 100 101 }102 103 }104 105

0 コメント