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

x10-communication

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



Joined: 28 Jul 2009
Posts: 10

View user's profile Send private message

x10-communication
PostPosted: Mon May 10, 2010 2:00 pm     Reply with quote

Hi Everyone,

I try to communicate with two pic using x10 protocol. There is a driver "x10.c" for tw523. The code which i wrote is below. I could send data but couldn't receive data with second pic. There is schema below. Where is the problem?
(U1 is transmitter, U2 is receiver. Pin B0 is using for zero-crossing)

transmitter:
Code:

#include <16f877.h>

#use delay (clock=7680000)
#use fast_io(b)

#include <X10.c>

#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD

void main()
{
   setup_psp(PSP_DISABLED);       
   setup_spi(SPI_SS_DISABLED);   
   setup_timer_1(T1_DISABLED);   
   setup_adc_ports(NO_ANALOGS);   
   setup_adc(ADC_OFF); 
   
   set_tris_b(0x03);
   
   while(1){
   
      if(input(pin_a0)){
      x10_write('M',15);
      }
   }
   
}


receiver:
Code:

#include <16f877.h>

#use delay (clock=7680000)

#include <X10.c>
#use fast_io(b)

#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD

char house_code;
BYTE key_code;
   
void main(){
   setup_psp(PSP_DISABLED);       
   setup_spi(SPI_SS_DISABLED);   
   setup_timer_1(T1_DISABLED);   
   setup_adc_ports(NO_ANALOGS);   
   setup_adc(ADC_OFF);
   
   set_tris_b(0x03);
   
   while(1){
     
      output_high(pin_b7);
      delay_ms(200);
      output_low(pin_b7);
      delay_ms(200);
     
      while(x10_data_ready()){
     
         x10_read(&house_code,&key_code);
         
         if(house_code=='M'){
            output_high(pin_b6);
            delay_ms(500);
         }
      }
      output_low(pin_b6);
   
   }
   
}




PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 10, 2010 3:03 pm     Reply with quote

Quote:
#include <16f877.h>

#use delay (clock=7680000)
#use fast_io(b)

#include <X10.c>

#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD

Does Proteus simulate X-10 ?

But anyway, the maximum frequency for 'XT' oscillator is 4 MHz.
You need to use HS for 7.68 MHz.
iruraz



Joined: 28 Jul 2009
Posts: 10

View user's profile Send private message

PostPosted: Tue May 11, 2010 12:55 am     Reply with quote

Thanks PCM Programmer. I changed xt as hs but simulation doesn't work correctly. You asked "Does Proteus simulate X-10 ? ".
Code:

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];
  *key_code=x10_read_bits(5);
  if(*key_code<16)
    *key_code=X10_KEY_CODES[*key_code];
}

There is no problem while sending "house code" and "key code". Only problem is reading received data. I thought that It reads input as "0" or "1" thus reading function constitute "house code" and "key code". Is it wrong idea?
Thanks for help...
kaplan



Joined: 13 Jan 2012
Posts: 3

View user's profile Send private message

X-10
PostPosted: Fri Jan 13, 2012 6:39 am     Reply with quote

Dear All

can anyone send me the simulation files and the code in C for the X10 protocol to my email address [email protected]. I need also the X10.c

thank you in advance

kind regards
kabalan CHACCOUR
Hardware design Engineer
temtronic



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

View user's profile Send private message

PostPosted: Fri Jan 13, 2012 6:50 am     Reply with quote

I really doubt anyone here has Proteus X-10 simulation files since Proteus is so full of bugs, errors and bad DRCs.

With respect to real CCS C X-10 code, they do supply example code located in the examples folder.

Your best action is get get some PICs and parts, wire up the correct schematic ,install CCS C code and experiment, don't waste valuable time on Proteus !
kaplan



Joined: 13 Jan 2012
Posts: 3

View user's profile Send private message

PostPosted: Fri Jan 13, 2012 7:08 am     Reply with quote

Thank you for your kind reply. Where could I find the correct schematic ?
temtronic



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

View user's profile Send private message

PostPosted: Fri Jan 13, 2012 3:40 pm     Reply with quote

You could start by looking at the X-10 example that CCS kindly supplies and see what pins they have assigend to the various X-10 pins.
As for 'correct', there really is none. that's the nice thing about PICs, YOU can choose which pin does what function! What is 'correct' for me won't be for you, since I design PCBs 'old school'. It also matters what else the PIC has to do(LCD,KPD,USB,etc) as to actual pin layout.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sat Jan 14, 2012 4:40 am     Reply with quote

Well the two PIC's are communicating asynchronously. To make things worse the receiver has a half second delay in which it doesn't accept new data. The receiver must catch every X10 value to be reliable. I'd write an ISR on the receiver side and buffer the data into a circular buffer.
Alternatively replace the delays with timers so as to make them non blocking. As to Proteus it is never a substitute for a real circuit. Maybe as a learning tool it has some value but it brings with it the danger of a false positive. It worked in Proteus so they blame everything else if it doesn't work elsewhere.
kaplan



Joined: 13 Jan 2012
Posts: 3

View user's profile Send private message

PostPosted: Sat Jan 14, 2012 12:39 pm     Reply with quote

Can anyone send me the x10.c file to include it in my program?



+++++++++++++++++++++++++++++
Do not ask this question. Forum rule #10:

10. Don't post the CCS example code or drivers, or ask for such code and drivers.

Forum Rules:
http://www.ccsinfo.com/forum/viewtopic.php?t=26245

- Forum Moderator
+++++++++++++++++++++++++++++
dyeatman



Joined: 06 Sep 2003
Posts: 1937
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Jan 14, 2012 1:24 pm     Reply with quote

Kaplan
If you have a legal CCS compiler you should already have the file
anyway. It has been distributed in the drivers directory with the
compiler since at least 2003 (before version 3.180). If you don't have
the file then are you likely using a very old, bootleg or incomplete
compiler. If you have a legal/registered CCS compiler then ask CCS
support for the file.
_________________
Google and Forum Search are some of your best tools!!!!
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