here's my code
Code: Select all
#define BIT_RATE 115200
#define BIT_TIME 100000000 / BIT_RATE
out port TX1 = XS1_PORT_1A;
in port RX1 = XS1_PORT_1B;
unsigned char M[]="!M ";
void txByte(out port TXD, unsigned char c)
{
unsigned time, data;
data = c;
// get current time from port with force out.
TXD <: 1 @ time;
// Start bit.
TXD <: 0;
// Data bits.
for (int i = 0; i < 8; i += 1)
{
time += BIT_TIME;
TXD @ time <: >> data;
}
// one stop bit
time += BIT_TIME;
TXD @ time <: 1;
}
void Mcmd(out port TXD, char Mcmd1[], char Mcmd2[])
{
for(int i=0;M[i]!=0;i++)
txByte(TXD,M[i]);
for(int i=0;Mcmd1[i]!=0;i++)
txByte(TXD,Mcmd1[i]);
for(int i=0;Mcmd2[i]!=0;i++)
txByte(TXD,Mcmd2[i]);
}
int main(void)
{
int out1=400;
int out2=-950;
char outS1[33];
char outS2[33];
IntToSt(out1,outS1);
IntToSt(out2,outS2);
Mcmd(TX1,outS1,outS2);
return 0;
}