void TempHygroTX868::sendNibble(byte value) {
  for (byte i = 0; i < 4; ++i) {
    sendBit(value & 1);
    value >>= 1;
  }
  sendBit(1); // end of nibble
}
/**
* \brief Send a byte
* \param b The byte to send
* \param startstop Whether to send mark bits as start/stop markers
*
* If startstop is true, send a mark at the beginning and end of data, but
* between the two, send the byte, LSB first.
*
*/
void EngduinoIRClass::send(uint8_t b, bool startstop)
{
    bool sending_temp = sending;
    uint8_t mask = 0x01;

    while (rcvstate == STATE_READING)		// Wait until we're not receiving
        ;
    sending = true;

    if (startstop)
        sendBit(MARK);

    for (int i = 0; i < 8; i++) {
        Serial.print((b & mask) != 0);
        sendBit((b & mask) != 0);
        mask = mask << 1;
    }
    Serial.println("");

    if (startstop) {
        sendBit(MARK);
        delayMicroseconds(2*GAP);
    }

    sending = sending_temp;
}
void TempHygroTX868::sendData(byte* data, byte length) {
  int sum = 0;
  byte check = 0;
  byte* nibble = &data[0];
  
  // sync
  for (byte i = 0; i < 10; ++i) {
    sendBit(0);
  }
  // start bit
  sendBit(1);
  // data  
  for (byte i = 0; i < length; ++i) {
    check ^= *nibble;
    sum += *nibble;
    sendNibble(*nibble);
    ++nibble;
  }
  
  // check sum
  sendNibble(check);
  sendNibble(sum + check + 5);
  
  // ensure that tx is off
  digitalWrite(pin, LOW);
}
Beispiel #4
0
void senddata1(char display_num) {
	unsigned i;
	TP_ON;

	CS_ON(display_num);
    DEBUG_DELAY
	delayms(1);
	CS_OFF(display_num);
    DEBUG_DELAY
	delayms(1);

	WR_OFF;
    DEBUG_DELAY
	sendBit(1);
    DEBUG_DELAY
	WR_ON;
    DEBUG_DELAY

	WR_OFF;
    DEBUG_DELAY
	sendBit(0);
    DEBUG_DELAY
	WR_ON;
    DEBUG_DELAY

	WR_OFF;
    DEBUG_DELAY
	sendBit(1);
    DEBUG_DELAY
	WR_ON;
    DEBUG_DELAY

	temp1 = 0x80;
	MCU_Address_2416(0x00);
	for (row = 0; row < 3; row++) {
		for (i = 0; i < 8; i++) {
			MCU_Data_2416(Array1, display_num);
			if (temp1 == 0x00)
				temp1 = 0x80;
		}
	}
	delayms(1);
    DEBUG_DELAY
    CS_ON(display_num);
    DEBUG_DELAY

	TP_OFF;
    DEBUG_DELAY
    tmpBit = tmpBit ^ 1;
}
Beispiel #5
0
bool PBBP::sendByte(uint8_t b) {
  bool parity_val = 0;
  bool ok = true;
  uint8_t next_bit = 0x80;
  while (next_bit && ok) {
    if (b & next_bit)
      parity_val ^= 1;
    if (!sendBit(b & next_bit))
      return false;
    next_bit >>= 1;
  }

  return sendBit(!parity_val) && receiveReady() && receiveAck();
}
Beispiel #6
0
void sendByte(BYTE out) {
    BYTE i;
    for (i=0; i<8; i++) {
        sendBit(out & 0x01);
        out = out >> 1;
    }
}
void TIMER0_IRQHandler() {
    LPC_TIM0->IR = 1;
    if (sending == 2) {
    	if (bitsSent < BITS_IN_MESSAGE)
    		sendBit(OUTPUT_STRING,bitsSent);
    	else
    		setBitToPin(0);
    }
    else if (sending == 1) {
   	 setBitToPin(bitsSent%8 >= 4);
   	 if (bitsSent >= 7) {
   		 sending = 2;
   		 bitsSent = -1;
   	 }
    }
    else if (sending == 0) {
   	 setBitToPin(!(bitsSent%2));
   	 if (bitsSent >= 7) {
   		 sending = 1;
   		 bitsSent = -1;
   	 }
    }

    bitsSent++;
    return;
}
Beispiel #8
0
void init_command(unsigned int command_data, char display_num) {
	unsigned int i, j;
	command_data = command_data & 0xfff;
	command_data = command_data << 4;

	// Toggle CS1

	CS_ON(display_num);
    DEBUG_DELAY
	CS_OFF(display_num);
    DEBUG_DELAY

	for (i = 0; i < 12; i++) {
	    DEBUG_DELAY
		WR_OFF;
		j = command_data & 0x8000;
		command_data = command_data << 1;
		j = j >> 15;
		sendBit(j);
	    DEBUG_DELAY
		WR_ON;
	}
    DEBUG_DELAY
		CS_ON(display_num);
}
Beispiel #9
0
bool OneWireSlave::search() {
    uint8_t bitmask;
    uint8_t bit_send, bit_recv;

    for (int i=0; i<8; i++) {
        for (bitmask = 0x01; bitmask; bitmask <<= 1) {
            bit_send = (bitmask & rom[i])?1:0;
            sendBit(bit_send);
            sendBit(!bit_send);
            bit_recv = recvBit();
            if (errno != ONEWIRE_NO_ERROR)
                return FALSE;
            if (bit_recv != bit_send)
                return FALSE;
        }
    }
    return TRUE;
}
Beispiel #10
0
void sendByte(int data)
{
	// Loop all bits and send one by one
	int i;
	for(i = 0; i < 8; i++)
    	{
        	int b = data&1;
        	data = data >> 1;
		sendBit(b);
    	}
}
/**
* \brief Send a buffer of bytes
* \param buf The buffer of bytes to send as a (uint8_t *)
* \param len Length of the buffer
* \param startstop Whether to send mark bits as start/stop markers
*
* If startstop is true, send a mark at the beginning and end of data, but
* between the two, send the individual bytes, LSB first.
*
*/
void EngduinoIRClass::send(uint8_t *buf, unsigned int len, bool startstop)
{
    bool sending_temp = sending;

    while (rcvstate == STATE_READING)		// Wait until we're not receiving
        ;
    sending = true;

    if (startstop)
        sendBit(MARK);

    for (int i = 0; i < len; i++)
        send(buf[i], false);

    if (startstop) {
        sendBit(MARK);
        delayMicroseconds(2*GAP);
    }

    sending = sending_temp;
}
Beispiel #12
0
void send(int protocol, int id, int data)
{
	int i;
	for(i = 0; i < 6; i++)
	{
		// Send start
		sendBit(0);
		sendBit(1);
		// Send protocol
		sendByte(protocol);
		// Send id
		sendByte(id);
		// Send data
		sendByte(data);
		// Send parities
		sendBit(protocol&1);
		sendBit(id&1);
		sendBit(data&1);
		// Send stop bit
		sendBit(1);
		// Set normal
		bcm2835_gpio_write(PIN, 1);
		// Wait and repeat
		delay(500);
	}
};
Beispiel #13
0
bool Cuart::run(void)
{

    if (outputBuffer.size()) {
        Set_RS(true);
    }

    if (RS && CS)	{ Set_SD( (sendBit()==Bit_1) ? true:false);	}

    if (CD) { Set_RR(1); Set_CD(1); }
    bitToByte();

    return true;
}
Beispiel #14
0
void MCU_Data_2416(unsigned char *p, char display_num) {
	unsigned char i, k;

	p = p + display_num*3;

	for (i = 0; i < 8; i++) {
		WR_OFF; //clk = 0 for data ready
	    DEBUG_DELAY

		k = *(p + i * 8 + row) & temp1;
		if (k == 0) {
			sendBit(0);
			DEBUG_DELAY
		} else {
Beispiel #15
0
// Sends one individual code to the main tank controller
void sendCode(int code) {
  // Send header "bit" (not a valid Manchester code)
  GPIO_SET = 1<<PIN;
  usleep(500);
  
  // Send the code itself, bit by bit using Manchester coding
  int i;
  for (i=0; i<32; i++) {
    int bit = (code>>(31-i)) & 0x1;
    sendBit(bit);
  }
  
  // Force a 4ms gap between messages
  GPIO_CLR = 1<<PIN;
  usleep(3333);
} // sendCode
Beispiel #16
0
void OneWireSlave::send(uint8_t v) {
    errno = ONEWIRE_NO_ERROR;
    for (uint8_t bitmask = 0x01; bitmask && (errno == ONEWIRE_NO_ERROR); bitmask <<= 1)
        sendBit((bitmask & v)?1:0);
}