Created
January 26, 2012 08:34
-
-
Save pobo380/1681771 to your computer and use it in GitHub Desktop.
xxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define WAIT4(n) do{volatile long t=(n)-1;while(t--);}while(0) | |
int main() { | |
unsigned char recv_cmd = -1, ctrl_cmd = 0x0D; | |
short recv_cmd_buff = -1; | |
for (;;) { | |
// シリアル通信から一文字取得 | |
recv_cmd_buff = sci_getc(); | |
// 送信コマンドへ型を変換 | |
recv_cmd = (unsigned char)recv_cmd_buff; | |
switch (recv_cmd) { | |
case '4': | |
ctrl_cmd = 0x02; | |
break; | |
case '1': | |
ctrl_cmd = 0x07; | |
break; | |
case '3': | |
ctrl_cmd = 0x04; | |
break; | |
case '6': | |
ctrl_cmd = 0x09; | |
break; | |
case '0': | |
ctrl_cmd = 0x0D; | |
break; | |
} | |
/* コマンドを送信 */ | |
if (PE.DR.BIT.B8 == 0) { // PICが受信可能だったら | |
// PE12, PE13, PE14, PE15 に出力 | |
PE.DR.BYTE.LH = ctrl_cmd << 4; | |
// STBをハイにする | |
PE.DR.BIT.B9 = 1; | |
// PICが信号を読むのを待つ 0.8us * 2 * 100 wait | |
WAIT4(12800); | |
// STBをローに戻す | |
PE.DR.BIT.B9 = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment