Пример #1
0
void start_i2c_slave_reply(/*unsigned char length, unsigned char *msg*/) {

    unsigned char msgType;
    signed char len;
//    const unsigned char buffer[MSGLEN];
    len = FromMainLow_recvmsg(MSGLEN, &msgType, ic_ptr->outbuffer);

    if (len == MSGQUEUE_EMPTY) {
        ic_ptr->outbuflen = 8;
        ic_ptr->outbuffer[0] = IR_EMPTY_MESSAGE;
        
        unsigned char i;
        for (i = 1; i < 8; ++i)
          ic_ptr->outbuffer[i] = 0;
    }
    else {
        ic_ptr->outbuflen = len;
    }
//    for (ic_ptr->outbuflen = 0; ic_ptr->outbuflen < length; ic_ptr->outbuflen++) {
//        ic_ptr->outbuffer[ic_ptr->outbuflen] = buffer[ic_ptr->outbuflen];
//    }
//    ic_ptr->outbuflen = length;
    ic_ptr->outbufind = 1; // point to the second byte to be sent

    // put the first byte into the I2C peripheral
    SSPBUF = ic_ptr->outbuffer[0];
    // we must be ready to go at this point, because we'll be releasing the I2C
    // peripheral which will soon trigger an interrupt
    SSPCON1bits.CKP = 1;

}
Пример #2
0
void uart_trans_int_handler() {
    FromMainLow_recvmsg(uc_ptr->outbuflen, (void *) MSGT_I2C_DATA, (void *) uc_ptr->outbuffer);
    if (TXSTAbits.TRMT == 1) {
        uc_ptr->outbufind++;
        if (uc_ptr->outbufind < uc_ptr->outbuflen) {
            TXREG = uc_ptr->outbuffer[uc_ptr->outbufind - 1];
        } else {
            uc_ptr->outbuflen = 0;
            uc_ptr->outbufind = 0;
            PIE1bits.TXIE = 0;
        }
    }
}
void uart_int_handler()
{
	unsigned char uart_msg_buf[9];
	unsigned char type;
	int error;
			
	FromMainLow_recvmsg(9, &type, (void *) uart_msg_buf);

	// InsteON msg
	/*if(uart_msg_buf[0] == 0x13)	{
		TXSTA2bits.TXEN = 0;
		TXREG1 = uart_msg_buf[1];
		while(!TXSTA1bits.TRMT)	{};
		TXREG1 = uart_msg_buf[2];
		while(!TXSTA1bits.TRMT)	{};
		TXREG1 = uart_msg_buf[3];
		while(!TXSTA1bits.TRMT)	{};
		TXREG1 = uart_msg_buf[4];
		while(!TXSTA1bits.TRMT)	{};
		TXREG1 = uart_msg_buf[5];
		while(!TXSTA1bits.TRMT)	{};
		TXREG1 = uart_msg_buf[6];
		while(!TXSTA1bits.TRMT)	{};
		TXREG1 = uart_msg_buf[7];
		while(!TXSTA1bits.TRMT)	{};
		TXREG1 = uart_msg_buf[8];
		while(!TXSTA1bits.TRMT)	{};

		//TXSTA1bits.TXEN = 0;
	}*/

	if(uart_msg_buf[0] == 0xaf)	{
		if (uart_msg_buf[5] == 0)
		{
			//LATB = !LATB;
			//TXSTA1bits.TXEN = 0;
			TXREG2 = uart_msg_buf[1];
			while(!TXSTA2bits.TRMT)	{};
			TXREG2 = uart_msg_buf[2];
			while(!TXSTA2bits.TRMT)	{};
			TXREG2 = uart_msg_buf[3];
			while(!TXSTA2bits.TRMT)	{};
		}
		
		//TXSTA2bits.TXEN = 0;
	}
	//TXSTA1bits.TXEN = 0;
	TXSTA2bits.TXEN = 0;

}