#include "common.h"
#include "primary.h"
#include "NXTMotor.h"
#include "LegoMotor.h"
#include "interruptClass.h"
#include "PICi2c.h"
extern int wkCount, wkCount2, wkThermo, wkcnt[];
extern BYTE intKind;
BYTE getSW(); //スイッチ読み込み
void startInit(char* str);
unsigned char read_data[10]; // read data
unsigned char read_data2[10]; // read data
void main(void)
{
// 200μs 3
// 300μs 4,5
// 400μs 6
// 500μs 8
int width;
PICi2c comm;
int bit;
Timer tm;
Port Busy=Port(CPU.port8, 7);
Busy.setInput();
startInit("\n************ PIC spanのテスト ****************\n");
printf("Init start\n");
comm.PIC_getData(0x80, 0);
while(1) {
for(bit=0; bit<8; bit++)
{
read_data[3] =read_data[2] =read_data[0] = 255;
comm.PIC_getData(0x81, bit,read_data,4);
while(Busy.readPin()) ;
do {
comm.PIC_getData(0x00, bit,read_data,4);
} while(read_data[3]!=bit);
switch(read_data[1])
{
case 0: width=-1; break;
case 3: width=200; break;
case 4:
case 5: width=300; break;
case 6: width=400; break;
case 7:
case 8: width=500; break;
default: width=9999;
}
if(width !=-1 && width !=9999)
printf("width %d bit=%d\n", width, bit );
}
}
}
void startInit(char* str)
{
init();
LED(1); // 緑
while(!getSW() );
LED(0);
printf(str);
}
|
1
2
3
4
5
6
7 PICとI2Cで通信する
8
9 LegoMotorのエンコーダーを用いる場合
10 宣言する
11
12
13
14
15 PICとの通信用
16 PICとの通信用
17
18
19
20
21
22
23
24
25
26 PICとの通信用オブジェクトを作る
27
28 Timerオブジェクトを作る
29 幅計測busyフラグのオブジェクトを作る
30 入力に設定する
31 システムの初期化
32
33 赤外線ボール距離計測初期化コマンド
34 永久ループ
35 センサー8個をスキャンする
36
37
38 指定のセンサーのデータを要求する
39 計測の終了を知る
40
41 計測結果を得る
42 正しい結果が得られるまで繰り返す
43 パルス幅を分類する
44
45
46
47
48
49
50
51
52
53
54
55 分類結果を表示する
56
57
58
59
60
61
62
63
64
65
66
67
|