AKI-USB
CONTENTS
LINKS
/*--------------------------------------------------*/
/* ボタンが押された時にLCD,SCI,USBにメッセージを送る*/
for(j=0;j<4;j++)
{
i = GetSW(j);
if( ((sw[j]^1) & i) ) /* sw = off->onで条件成立 */
{
SetLED(j,1); /* LED押した瞬間点灯 */
sprintf(buff,"sw%u",j+1);
PrintSCI("%s\n",buff);
write_buff(buff,strlen(buff)+1); /* NULL(0x00)まで送信 */
PrintLCD(buff);
}
else SetLED(j,0);
sw[j] = i;
}if( get_inbufflen() ) /* 受信データあり? */
{
cnt = read_buff(buff,64); /* データ取得(buffサイズは64byteまで) */
PrintLCD("\f"); /* LCDクリア */
PrintLCD(buff); /* LCDへ表示 */
PrintSCI(buff); /* シリアル出力 */
write_buff(buff,cnt); /* USBへリダイレクト */
}int write_buff(char *p, int size); int read_buff(char *p, int size);
/*--------------------------------------------------------------*/
/*送信バッファへ書き込み */
/*char *p バッファポインタ */
/*int size 書き込みサイズ */
/*戻り値 書き込んだサイズ */
/*--------------------------------------------------------------*/
int write_buff(char *p,int size)
{
int i;
INTC.IER &= (-1^0x20); /* IRQ5 Disable */
for(i=0;i<size;i++)
{
if( outlen >= USBBUFFLEN ) break;
outbuff[outpos%USBBUFFLEN] = *p;
outpos = (outpos + 1)%USBBUFFLEN;
outlen++;
p++;
}
INTC.IER |= 0x20; /* IRQ5 Enable */
return(i);
}/*--------------------------------------------------------------*/
/*受信バッファから読み込み */
/*char *p バッファポインタ */
/*int size バッファ最大サイズ */
/*戻り値 読み込んだサイズ */
/*--------------------------------------------------------------*/
int read_buff(char *p,int size)
{
int i;
INTC.IER &= (-1^0x20); /* IRQ5 Disable */
for(i=0;inlen>0;i++)
{
if( i >= size ) break;
p[i] = inbuff[ (USBBUFFLEN+inpos-inlen)%USBBUFFLEN ];
inlen--;
}
INTC.IER |= 0x20; /* IRQ5 Enable */
return(i);
}