CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Sending X10 commands - help!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
milkman41



Joined: 16 Jun 2008
Posts: 30

View user's profile Send private message

Sending X10 commands - help!
PostPosted: Thu Jun 19, 2008 10:43 pm     Reply with quote

I would like to preface this by saying Im pretty much a complete n00b when it comes to programming PICs (and in general, really) - having said that, on to my problem! I'm trying to use a PIC to control an X10 TW523, and send commands to a lamp module, but I can't seem to get it right. I've looked at the example code and the driver for X10, and the example code just sends the address code. I've also looked at the documentation for X10 code, and I know what format the code should be in (11 cycles - 2 for start bit, 4/5 for house code, 4/5 for key code/function (can't remember which is 4 and which is 5), then 6 cycles of silence), as per the example code. However, when I try to transmit the functions in this manner, using their binary representations, I can't get it to work. I've tried numerous methods, and this is where I am at right now:


Code:
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) //Get house, key codes from rs232 usually, here just using default A1

#include <x10.c>
#include <input.c>

void main() {
   while(TRUE)
   {  printf("ONLINE");
   
      x10_write('A', 1);
      //x10_write('A', 1); //the x10_write function already sends the data twice
   
      delay_ms(5000);
   }
}


I've rewritten the x10_write to also send the function codes, and the delay and print message are just to make sure the program is running properly (trying to turn the lamp off currently). Here is the rewritten x10_write function:


Code:
void x10_write(BYTE house_code, BYTE key_code) {
  BYTE i;

  i=0;
  while (X10_HOUSE_CODES[i]!=house_code)
    i++;
  house_code=i;
  if(key_code<16) {
     i=0;
     while (X10_KEY_CODES[i]!=key_code)
       i++;
     key_code=i;
  }
  x10_write_bits(7,4,1);
  x10_write_bits(house_code,4,0);
  x10_write_bits(key_code,5,0);
  x10_write_bits(0,6,1);
  x10_write_bits(7,4,1); //repeated
  x10_write_bits(house_code,4,0);
  x10_write_bits(key_code,5,0);
  x10_write_bits(0,6,1);
 
  x10_write_bits(7,4,1);
  x10_write_bits(house_code,4,0);
  x10_write_bits(16,5,1);
  x10_write_bits(0,6,1);
  x10_write_bits(7,4,1); //repeated
  x10_write_bits(house_code,4,0);
  x10_write_bits(16,5,1);
  x10_write_bits(0,6,1);
}


This is just the example code provided in EX_X10.c, with just an added little bit add the end to write the command. I can't remember off the top of my head what function 16 is (I think its all off), but I have tried all off, all on, off, on, all lights off, several functions, and they aren't working.

Any help would be greatly, greatly appreciated.

Thank you in advance,
-Nick
horkesley



Joined: 20 Feb 2007
Posts: 48
Location: Essex UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jun 20, 2008 12:01 am     Reply with quote

Hi,

Have you looked at these sites?

http://www.x10.com/support/technology1.htm

http://ww1.microchip.com/downloads/en/AppNotes/00236a.pdf

Regards
_________________
Horkesley Electronics Limited
horkesley



Joined: 20 Feb 2007
Posts: 48
Location: Essex UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jun 20, 2008 12:23 am     Reply with quote

Another thought, don't you have to sync with mains zero crossing.

Are you doing this somewhere?

Regards
_________________
Horkesley Electronics Limited
Guest








PostPosted: Fri Jun 20, 2008 7:15 am     Reply with quote

yes I have looked at those sites, and from my (albeit limited) knowledge of programming and X10, it appears as if I am doing the right thing, although I clearly am not, seeing as it doesn't work. I took the example code and replicated the signal being sent out, except instead of a key code, I sent out a function code, as specified in the sites. Also, the write_bits function included in the x10 driver waits for the zero crossing. The code seems to transmitting correctly, as the TW523 recieves valid commands (and hte LED winks), but the function code transmission is just not right, I suppose. Thank you though.

Any other suggestions?
milkman41



Joined: 16 Jun 2008
Posts: 30

View user's profile Send private message

PostPosted: Fri Jun 20, 2008 7:48 am     Reply with quote

that was me^, oops Laughing
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group