C51 中斷接收 G代碼 并發(fā)送回去 by mingwen
//===========================================================
// step motor 串口通信G代碼
//
//86 step motor,3200cts/r,f=20kHz=20000/r,
//n=20000/3200=6.25r/s=375rpm, ratio=5
//n_out=75rpm, n_old=1500/75=20rpm
//
//f :
//times=1,delay0.05ms=20000Hz=20kHz
//times=2,delay0.1ms=10000Hz=10kHz
//times=3,delay0.15ms=6666Hz=6.66kHz
//times=4,delay0.2ms=5000Hz=5kHz
//===========================================================
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define Gcode_LEN 10 //數(shù)據(jù)長度G01X12345$ (10char)
sbit Xpul = P0^0; //axis X
sbit Xdir = P0^1; //axis X
sbit KEY4 = P3^2;
bit rece_flag = 0; //為1代表串口接收到了一幀數(shù)據(jù)
uchar receive[Gcode_LEN]={0}; //暫存數(shù)組,可以將10改為需要的數(shù)值
/**************************************************/
/* 向串口發(fā)送字符 */
/**************************************************/
void send_char_com(uchar c)
{
SBUF=c;
while(TI==0);
TI=0;
}
/**************************************************/
/* 向串口發(fā)送字符串 */
/**************************************************/
void send_string_com(uchar *s)
{
while(*s!=