#pragma sfr
#pragma DI
#pragma EI
#include "trgbios.h" // トラ技BIOSのサービスルーチンを呼び出すのに必要
#define NULL ((void *)0)
unsigned short ledCount;
unsigned short ledCountmax;
unsigned char c;
unsigned char d;
unsigned char pdat[8];
unsigned short pdatcnt;
unsigned short pdat_kaku;
unsigned short pdat_kakuold;
void intsrv_tim(void)
{
ledCount++;
if(ledCount >= ledCountmax)
{
ledCount = 0x0; //リセット
if(pdat_kaku > pdat_kakuold) //位置指令>現在位置なら・・・
{
pdatcnt++; //針 1ステップ進める
pdatcnt = pdatcnt & 0x07;
P1 = pdat[pdatcnt]; //P1に励磁パターン出力
pdat_kakuold++; //現在位置更新
}
if(pdat_kaku < pdat_kakuold) //位置指令<現在位置なら・・・
{
pdatcnt--; //針 1ステップ戻す
pdatcnt = pdatcnt & 0x07;
P1 = pdat[pdatcnt]; //P1に励磁パターン出力
pdat_kakuold--; //現在位置更新
}
}
// タイマー割り込みフラグをクリア
IF0H.6 = 0;
}
void main() // メイン
{
unsigned short i;
unsigned char standAlone = 0;
unsigned char ramMode = 0;
unsigned char biosExists = 0;
unsigned char first = 1;
ledCountmax = 100; //10kHz/100=100pps
pdat_kakuold = 96; //現在位置 電源ON時の針ゼロ点出し用
pdat_kaku = 0; //位置指令
PM6 = 0xfd; /*PM61 = 0, PM60 = 1*/
PM1 = 0x00; /*PM1 = 0*/
P1 = 0x00;
//励磁パターン
pdat[0] = 0x66;
pdat[1] = 0x06;
pdat[2] = 0x96;
pdat[3] = 0x90;
pdat[4] = 0x99;
pdat[5] = 0x09;
pdat[6] = 0x69;
pdat[7] = 0x60;
trg_regintsrv(TRG_INTID_BSITM000,intsrv_tim); // 割り込みハンドラ登録
//
//タイマ割り込み設定
PRM00 = 1; // プリスケーラモードレジスタ 16M/4=4M
CR000 = 0x190; // 割り込み周期 4M/400=10KHz
TMC00 = 0x0C; // カウント開始
MK0H.6 = 0; // TM000割り込み許可
c = 0;
while(1) {
d = trg_getrecvcount();
if(d > 0)
{
trg_recvdata(&c,1);
trg_senddata(&pdat_kakuold,1);
if(c == 255)
{
P6.1 = 0;
P1 = 0x00;
TMC00 = 0x00;
MK0H.6 = 1;
break; //位置指令=255なら終了
}
pdat_kaku = c; //位置指令更新
}
}
}