Browsing this Thread:
1 Anonymous Users
Topic options
View mode
舊的在前
Re: VB傳ASCII CODE 傳至 P30F4011
中級會員
Joined
: 2005/10/1 17:36最後登入時間
: 2021/2/12 23:02
From 中山醫學大學附設醫院-醫工室
Group:
註冊會員
Level : 5
HP : 0 / 106
MP : 14 / 5940
EXP : 27
利用COM Port來控制,首先自己要先定義控制的命令/訊息格式,在此先假設您對串列傳輸已經有基本的認知,只是不知道dsPIC如何撰寫 直接貼上我目前用的程式一小段,這是用來改變PID的控制參數及轉速命令,建議您看看dsPIC的周邊課程資料 // *********************************************************************** void __attribute__((__interrupt__)) _U1TXInterrupt(void) { IFS0bits.U1TXIF = 0; // clear interrupt flag return; } void __attribute__((__interrupt__)) _U1RXInterrupt(void) { IFS0bits.U1RXIF = 0; // clear interrupt flag Rec_temp = U1RXREG; // 4個字元進來中斷一次,第一字元放temp if (Rec_temp == 0x02) // 判斷命令為何 { RXPtr = &InData1[0]; // point to first char in string *RXPtr=Rec_temp; *RXPtr++; for (Rec_Count=1;Rec_Count<=3;Rec_Count++) { *RXPtr = U1RXREG; *RXPtr++; } SpeedSet=((unsigned int)InData1[1] << 8) + (unsigned int)InData1[2]; if (SpeedSet < 2000) //UART歸零時硬體電路設計還有初始值 SpeedSet = 2000; } else if (Rec_temp == 0x03) // 判斷Kp命令為何 { RXPtr = &InData2[0]; // point to first char in string *RXPtr=Rec_temp; *RXPtr++; for (Rec_Count=1;Rec_Count<=3;Rec_Count++) { *RXPtr = U1RXREG; *RXPtr++; } Kp=((unsigned int)InData2[1] << 8) + (unsigned int)InData2[2]; } else if (Rec_temp == 0x04) // 判斷Ki命令為何 { RXPtr = &InData3[0]; // point to first char in string *RXPtr=Rec_temp; *RXPtr++; for (Rec_Count=1;Rec_Count<=3;Rec_Count++) { *RXPtr = U1RXREG; *RXPtr++; } Ki=((unsigned int)InData3[1] << 8) + (unsigned int)InData3[2]; } else { //清除空間 U1RXREG; U1RXREG; U1RXREG; } return; }
發表於: 2007/3/17 13:07
VB傳ASCII CODE 傳至 P30F4011
新會員
Joined
: 2007/3/16 17:03最後登入時間
: 2007/3/16 17:04
Group:
註冊會員
Level : 1
HP : 0 / 0
MP : 0 / 0
EXP : 0
動作: VB輸入ASCII P30F4011 利用LED顯示 例如 我傳U字元 ASII=01010101 LED八顆就亮哪幾個 VB已成功輸出ASCII CODE 問題是PF4011 語法如何寫 最好為C語言
發表於: 2007/3/16 17:10
You can view topic.
你 不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.