transmitting problem

Thread Starter

ddonn

Joined Feb 10, 2010
13
I am using a pic18f4520 to send data through a KNX bus to KNX software. The data i am trying to send was taken from a demonstration KNX system. Basically, when a motion sensor detects movement it sends this hex code to the KNX software.
I am trying to program my pic to send this message to the software and "pretend" to be the motion sensor. I have the knx components i need for this to work and i have checked with the demo if it is sending message to software and it is. I have connected the bus to the tx pin on the pic and was wondering if the code below should send the message out the tx pin.
Thanks in advance for any help.

#include <p18f4620.h>
#include <usart.h>
#include <stdio.h>
#include <delays.h>



#pragma config OSC = HS // Sets the oscillator mode to HS
#pragma config WDT = OFF // Turns the watchdog timer off
#pragma config MCLRE = OFF
#pragma config LVP = OFF // Turns low voltage programming off

#define baudrate 64


//Declare varialbles

unsigned char msg[13] = {0x2B,0x04,0xC3,0x4F,0xBC,0x11,0x02,0x00,0x01,0xE1,0x00,0x81,0x31};

void configure_pins()
{
// Configure port D digital i/o
// Inputs: 27, 28, 29 and 30 (RD4, RD5, RD6 and RD7)
// Outputs: 19, 20, 21 and 22 (RD0, RD1, RD2 and RD3)
LATD = 0; // Set port D data latch to 0V initially.
TRISD = 0b11110000; // This binary value sets pins RD4-7 as inputs and RD0-3 as outputs.

}


void main(void)
{

// Configure which pins are inputs and which are outputs
configure_pins();

//Initialise USART
//TRISC = 0b11111111;
OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH,baudrate);

while(1)
{
putsUSART(msg[0]);
Delay100TCYx(25); //one character
putsUSART(msg[1]);
Delay100TCYx(25);
putsUSART(msg[2]);
Delay100TCYx(25);
putsUSART(msg[3]);
Delay100TCYx(25);
putsUSART(msg[4]);
Delay100TCYx(25);
putsUSART(msg[5]);
Delay100TCYx(25);
putsUSART(msg[6]);
Delay100TCYx(25);
putsUSART(msg[7]);
Delay100TCYx(25);
putsUSART(msg[8]);
Delay100TCYx(25);
putsUSART(msg[9]);
Delay100TCYx(25);
putsUSART(msg[10]);
Delay100TCYx(25);
putsUSART(msg[11]);
Delay100TCYx(25);
putsUSART(msg[12]);
Delay100TCYx(25);

}

}
 
Top