/* this function sends the byte in data over motorport A using Lepomux v2.0 protocol */ /* 28.2.2003 */ void senddata(char data) { int stream; int bit=0, lastbit=0; int bitcnt; do { stream = data << 1; for (bitcnt=8; bitcnt>=0; bitcnt--) { bit = (stream & (0x0001 << bitcnt)) >> bitcnt; if (bitcnt==8) stream |= bit; else stream ^= bit; if ((bit == lastbit) && (bitcnt<8)) { motor_a_dir(rev); lastbit = 2; } else { if (bit) motor_a_dir(fwd); else motor_a_dir(off); lastbit = bit; } msleep(1); /* this important for the timing! */ } motor_a_dir(rev); msleep(5); /* wait 5ms between databytes (just for debugging on the scope) */ } while ((SENSOR_1>>6) < 0x1d0); /* wait for ack on sensor 1 */ }