|
|
View previous topic :: View next topic |
Author |
Message |
iruraz
Joined: 28 Jul 2009 Posts: 10
|
X10-TEMPERATURE CONTROL |
Posted: Wed Apr 07, 2010 4:51 am |
|
|
Hi Everyone,
I try to implement temperature control with using X10 protocol. I benefit from microchip's AN-236 application. There are asm codes but i work with CCS. CCS has X10 driver for TW523. Can i use this driver or should i write new functions for main-slave module communication? There X10 driver codes below.
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)) ;
else
while(!input(X10_ZERO_CROSS)) ;
}
void x10_write_bits(BYTE data, BYTE n, BYTE start) {
BYTE i;
BOOLEAN the_bit;
for(i=1;i<=n;++i) {
wait_for_zero_cross();
the_bit=shift_right(&data,1,0);
output_bit(X10_FROM_PIC, the_bit);
delay_ms(1);
output_low(X10_FROM_PIC);
if(start==0) {
wait_for_zero_cross();
output_bit(X10_FROM_PIC, !the_bit);
delay_ms(1);
output_low(X10_FROM_PIC);
}
}
}
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);
}
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];
*key_code=x10_read_bits(5);
if(*key_code<16)
*key_code=X10_KEY_CODES[*key_code];
}
|
|
|
|
jbmiller
Joined: 07 Oct 2006 Posts: 73 Location: Greensville,Ontario
|
|
Posted: Wed Apr 07, 2010 5:33 am |
|
|
It's always best to start with something that does work! If you can use this code to control X10 modules(lights on, of, dim,etc.) then you've got a good 'base' to start from.
Add your own LCD, KPD routines, then implement the temperature controller functions.
That way you'll always have program to refer to that was working until you do 'something' wrong !
Better to tak several small steps than one giant leap.... |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Wed Apr 07, 2010 6:39 am |
|
|
Two different approaches
An236 interfaces to the power line itself.
The tw523 is a separate device
but you probably already know that. |
|
|
|
|
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
|