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

Help with X10 home automation
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Sep 19, 2011 5:12 am     Reply with quote

There are 1,000s of 'hits' about X10...

from one...

X10 data stream..
"A complete code transmission encompasses eleven
cycles of the power line. The first two cycles represent a
Start Code. The next four cycles represent the House
Code and the last five cycles represent either a Number
Code (1 thru 16) or a Function Code (On, Off etc.). This
complete block, (Start Code, House Code, Key Code)
should always be transmitted in groups of 2 with 3 power
line cycles between each group of 2 codes".

Those 11 cycles MUST be sequential.....

sc,sc,hc,hc,hc,hc,fc,fc,fc,fc,fc

The only 'delay' is the loop waiting for zero cross to occur.

In your program you've got delay_ms(1000) between sc..hc..fc

So you're not doing it right.

I strongly suggest using Google and finding 'how X10 works'. There are several sites that ONLY deal with X10(both cdn and EU), even found PBasic code to run X-10E modules, so it is out there.

You might find help from wherever you bought the modules or on one of the X10 'forums' on the net.
miamomoualeu



Joined: 16 Sep 2011
Posts: 15

View user's profile Send private message

help
PostPosted: Tue Sep 20, 2011 4:36 am     Reply with quote

i have tried on the internet to find that timing problem but cant find any.i understand that the lenght of the pulse should be 1ms but this is standard everywhere cant change.so i dont know where to do those rectifiactions.please i need your insight.
if you look at this code, what is wrong with it?
Code:


#include <18F4520.h>
#fuses INTRC,NOWDT,NOPROTECT,
#use delay(clock=1000000)

void start_code();
void house_code();
void key_code();
void send_one();
void send_zero();

 void start_code() 
      {
   while ( !input(PIN_B0) ){  // wait for zero crossing to go high
   output_high( PIN_B2);
   delay_ms(1);
   output_low ( PIN_B2);
}

   while ( input(PIN_B0) ){  // wait for zero crossing to go low
   output_high( PIN_B2);
   delay_ms(1);
   output_low ( PIN_B2);
}

   while ( !input(PIN_B0) ){  // wait for zero crossing to go high
   output_high( PIN_B2);
   delay_ms(1);
   output_low ( PIN_B2);
}
   while ( input(PIN_B0) ){  // wait for zero crossing to go low
   output_low ( PIN_B2);
   delay_ms(1);
   output_low ( PIN_B2);
}
      }


/*========================send a one============================*/
 void send_one()
{
   while ( !input(PIN_B0) ){  // wait for zero crossing
   output_high( PIN_B2);
   delay_ms(1);
   output_low ( PIN_B2);
}

   while ( input(PIN_B0) ){
   output_low ( PIN_B2);
   delay_ms(1);
   output_low ( PIN_B2);
}

}

 /*=======================send a zero===========================*/
   void send_zero()
{
   while ( !input(PIN_B0) ){  // wait for zero crossing
   output_low ( PIN_B2);
   delay_ms(1);
   output_low ( PIN_B2);
}

   while ( input(PIN_B0) ){
   output_high( PIN_B2);
   delay_ms(1);
   output_low ( PIN_B2);
}

}
void house_code()
  {
  send_zero();
  send_one();
  send_one();
  send_zero();
  }
void key_code()
{
send_zero();
send_one();
send_one();
send_zero();
send_zero();
}

void main()
{
   
   while(1)
   {
      //output_high(PIN_B5);   
        start_code();
      //output_low(PIN_B5);
        house_code();
     // output_high(PIN_B5);
        key_code();
     // output_low(PIN_B5);

}
}
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 20, 2011 5:14 am     Reply with quote

You're not following the X-10 format or protocol.
Please look at how CCS does it in their example program ex_x10.c using their driver, x10.c

1st question, have you verified with a regular x10 controller that you can turn on/off an x10 module?

2nd, since I don't have any X10 product here, I cannot test the CCS code, though I have no reason to doubt it won't work. Perhaps someone else has tried it and will report back.
Onur



Joined: 11 Apr 2004
Posts: 11

View user's profile Send private message

PostPosted: Tue Sep 20, 2011 7:55 am     Reply with quote

long time ago I used <x10.c> code with TW523 module at 220V 50Hz. works like a charm
miamomoualeu



Joined: 16 Sep 2011
Posts: 15

View user's profile Send private message

help
PostPosted: Tue Sep 27, 2011 7:29 am     Reply with quote

please i need a code to receive the x10 data on a pic. i can send the information because the led on the modem goes off so now i want to receive on a pic through the XM10E.please need help with the code.
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 9:22 am     Reply with quote

Well CCS supplies code in their examples folder, just be sure you have the correct X10 controller module as they are NOT all the same.
miamomoualeu



Joined: 16 Sep 2011
Posts: 15

View user's profile Send private message

help plc
PostPosted: Fri Oct 07, 2011 10:01 am     Reply with quote

I want to light an LED after receive an x10 codes. Can you help me please? This is the code I'm using.
Code:

//sender

#include <18F4520.h>
#fuses INTRC,NOWDT,NOPROTECT
#use delay(clock=1000000)
#include <x10.c>
#USE Fast_IO(B)

void main() {

SET_TRIS_B( 0b00000011 );

while(1){
output_low(pin_b5);
delay_ms(500);

x10_write('A',5);

output_high(pin_b5);
delay_ms(500);
}
}


Code:

// Receiver

#include <18F4520.h>
#fuses INTRC,NOWDT,NOPROTECT
#use delay(clock=1000000)
#USE Fast_IO(B)
#include <x10.c>

char house_code;
BYTE key_code;

void main() {
SET_TRIS_B( 0b00000011 );

output_low(pin_b5);

while(x10_data_ready()){
output_low(pin_b5);

        x10_read(&house_code, &key_code);
         if (key_code==5){
         
         output_high(pin_b5);
         delay_ms(500);
      }
}
}
 


The signal is going through but now I want to light an LED on the receiver after the code has been received.
miamomoualeu



Joined: 16 Sep 2011
Posts: 15

View user's profile Send private message

help
PostPosted: Wed Oct 12, 2011 2:12 am     Reply with quote

Can someone please help me with the codes I sent. I want to light an led if the codes is received. plllllllllllllsssssssssssssssssssssssssssssss
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 3:07 am     Reply with quote

Buy an X10 module and try to communicate with that.

By writing both transmitter and receiver you don't know whether the error is either or even both ends of the system.
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Oct 12, 2011 5:33 am     Reply with quote

What is the make/model/product info of the X-10 controller and appliance modules you're using ?
Are they plugged into the same power socket or different rooms ?
miamomoualeu



Joined: 16 Sep 2011
Posts: 15

View user's profile Send private message

help
PostPosted: Wed Oct 12, 2011 5:42 am     Reply with quote

I'm simply using a pic microcontroller at the receiver and two XM10E models. So when it receives the signal i want to light up an LED but it doesn't work. Even the led from the modem is not blinking but the modem of transmitter blinks off normally meaning that the signal is going.
miamomoualeu



Joined: 16 Sep 2011
Posts: 15

View user's profile Send private message

help
PostPosted: Sun Oct 16, 2011 2:12 pm     Reply with quote

In the following code im trying to light led after receiving x10 data.
The led at pinb6 goes high, meaning that the codes are received. Now I want to light the led at pinb5 or b4 if the exact codes were received. Pls what can I do?
As well if I want to display the bits received on the lcd of the board.
How do i do that?

Code:

#include <18F4520.h>
#fuses INTRC,NOWDT,NOPROTECT
#use delay(clock=1000000)
//#include <input.c>
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
//#include <x10.c>

   char house_code;
   BYTE key_code;


#ifndef X10_ZERO_CROSS

#define X10_ZERO_CROSS  PIN_B0
#define X10_TO_PIC      PIN_B1
#define X10_FROM_PIC    PIN_B2

#endif

char const X10_HOUSE_CODES[16] = {'M','N','O','P','C','D','A','B','E',
                                  'F','G','H','K','L','I','J'};
BYTE const X10_KEY_CODES[16] = {13,14,15,16,3,4,1,2,5,6,7,8,11,12,9,10};


void wait_for_zero_cross() {

  if(input(X10_ZERO_CROSS))
     while(input(X10_ZERO_CROSS)) { output_d(0xAB);}       
  else
     while(!input(X10_ZERO_CROSS)) { output_d(0xBA);}

         
}


BYTE x10_data_ready() {
  port_b_pullups(TRUE);
  return(!input(X10_TO_PIC));
}

BYTE x10_read_bits(BYTE n) {
   BYTE data,i;

   for(i=1;i<=n;++i) {

         
     wait_for_zero_cross();
         
     delay_us(300);
     shift_right(&data,1,input(X10_TO_PIC));
     wait_for_zero_cross();
     delay_us(300);
   }
   data>>=8-n;
   return(data);
}

void x10_read(BYTE *house_code,BYTE *key_code) {

  port_b_pullups(TRUE);
         
  x10_read_bits(2);
         
  *house_code=x10_read_bits(4);
  *house_code=X10_HOUSE_CODES[*house_code % 16]; /*Make sure we don't overrun the array*/
  *key_code=x10_read_bits(5);
  output_d(*house_code);
 
  output_d(*key_code);
  if(*key_code<16)
    *key_code=X10_KEY_CODES[*key_code];
}

void main() {
SETUP_ADC_PORTS(NO_ANALOGS);
 
//SET_TRIS_B( 0b00000011 );

 //output_low(pin_b5);

   do
   {
      if (x10_data_ready()){
        output_high(pin_b6); //These may also be a problem, depending on how they are connected
         
        x10_read(&house_code, &key_code);
 output_high(pin_b6);
         
        if (house_code=='A' && key_code==5){
          output_high(pin_b5);
}

 if (house_code=='M' && key_code==16){
         output_high(pin_b4);
       }
       else
       {
          //delay_ms(1000);
          //output_low(pin_b6);
       }
      }
   }while (1);
}
 
 
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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