You are on page 1of 26


X-10® Home Automation Using the PIC16F877A

Author: Jon Burroughs HARDWARE OVERVIEW
Microchip Technology Inc. The home controller application described in this appli-
cation note allows the user to program on and off times
INTRODUCTION for up to sixteen devices, using a 2 x 16 liquid crystal
display and five push buttons. A built-in light sensor can
X-10 is a communication protocol designed for sending be used to turn on lights at dusk, and turn them off at
signals over 120 VAC wiring. X-10 uses 120 kHz bursts dawn.
timed with the power line zero-crossings to represent The home controller is designed to facilitate experi-
digital information. Plug-in modules available from var- mentation with home automation using the
ious vendors enable users to create home automation PIC16F877A. In addition to the PIC16F877A, the board
systems by using the AC wiring already installed within will accept any other PIC MCU that shares the same
a home. Readers who would like an overview of the pinout, such as the PIC18F452. Therefore, experi-
X-10 signal format may refer to Appendix A. menters may expand on the application using the
PIC® microcontrollers can easily be used in conjunction higher performance of the PIC18 family of parts without
with X-10 technology to create home automation changing the hardware.
applications. The specific PIC microcontroller (MCU) With care, engineers and home control enthusiasts can
used should be selected based on RAM, ROM, experiment with home automation using the
operating frequency, peripheral, and cost requirements MPLAB ICD 3 development tool. However, proper cir-
of the particular application. The PIC16F877A was cuit isolation precautions must be taken to avoid
selected for this application because of its versatility as damage to your computer or development tools. See
a general purpose microcontroller, its Flash program Figure 1 and the warning note!
memory (for ease of development), data EEPROM and
ample I/O. WARNING: VSS or ground on the application circuit is
tied to neutral of the 120 VAC. To safely connect your
This application note discusses the implementation of
development tools or computer to the home control-
X-10 on a PIC MCU to create a home controller that
ler, you must power it through an isolation transformer
can both send and receive X-10 signals. The reader
and leave wall ground (the green wire in most cases)
may implement the home controller as is, or adapt the
disconnected. Any test instruments (such as an oscil-
circuits and firmware to other applications. A library of
loscope) that you hook up to the application circuit,
X-10 functions is provided to facilitate development of
should be powered through the isolation transformer
other X-10 applications using PIC MCUs (see
as well, with wall ground disconnected. In addition,
Appendix E).
the entire circuit should be enclosed within a suitable
Operating instructions for the home controller are case to prevent unintentional contact with the mains
included in Appendix B. voltage!


X-10 modules and
X-10 X-10
X-10 Oscillo- any test
Lamp Lamp
Isolation Board scope instruments should
Module Module
Transformer be plugged into
the isolation
development tools,
and the isolation To maintain
transformer should
isolation, leave
be plugged into
the wall outlet.

 2010 Microchip Technology Inc. DS00236B-page 1

HARDWARE DESCRIPTION There are several application functions that are not
directly associated with the X-10 interface. User
An overview of the home controller application interface functions are accomplished with an LCD
hardware is shown in Figure 2. display and five push buttons. A real-time clock is
The hardware functionality of X-10 circuitry can be created using Timer1 and an external 32 kHz oscillator.
divided into four functional blocks: User modified control data, such as unit on and off
times, are stored in the PIC MCU’s built-in EEPROM. A
• Zero-crossing detector
light sensor and load switch are also used in this
• 120 kHz carrier detector application.
• 120 kHz signal generator
• Transformerless power supply



Zero-crossing Detector Light Load
Sensor Switch

120 kHz Carrier Detector
Real-time Clock Control Data

120 kHz Carrier Generator

LCD Key Switches


DS00236B-page 2  2010 Microchip Technology Inc.

it will go low about Ipeak = 165V/5 M = 33 A. the RB0 pin will be clamped to VSS . and the input buffer is a Schmitt trigger. PIC16F87XA In this application. Vrms = 117 VAC. More information on interfacing PIC MCUs to AC power Input protection diodes (designed into the PIC MCU I/O lines can be found in the application note AN521. the logical value will become a ‘1’. This 120 VAC RB0/INT makes the input threshold 0. V = Vpk*sin(2**f*t). PORTB<1:5> Key Press Inputs Five push buttons are used for menu navigation. RB0 is configured for external inter- rupts. Timer0 interrupt 120 kHz Envelope Timing Times duration of 1 ms bursts and onset of second and third phase bursts. See warning note! PORTD<0:7> LCD Data pins 8 data lines for LCD. AN236 A summary of resource use can be seen in Table 1.680 MHz. CCP1/Timer2 in PWM 120 kHz Modulation TRISC is used to enable/disable 120 kHz output. information is timed with the zero-crossings of rupt occurs on every zero-crossing. PORTE<0:2> LCD Control pins 3 control lines for LCD. it is possible to calculate when the pin state ated by using the external interrupt on the RB0 pin and will change relative to the zero-crossing: just one external component.0. to limit the current into the PIC MCU (see Figure 3). DATA EEPROM Non-volatile Control Data Storage Stores on and off times and other user programmable information.6V. when the AC voltage is in the negative download from the Microchip web site.  2010 Microchip Technology Inc. If we select a resistor of 5 M. Zero-Crossing Detector Upon each interrupt. Using the following the AC power. ADC Light Sensor Used to detect dawn and dusk. half of its cycle. Details of the functional sections are discussed below.8 VDD = 4V on a rising R = 5 M edge and 0. FIGURE 3: ZERO-CROSSING DETECTOR When the AC voltage rises above the input threshold. mode Main oscillator is 7. Timer1 interrupt Real-time Clock Used as time keeping clock and key scan clock. which is well within the 16 Μs before the zero-crossing. the Interrupt Edge Select bit within the OPTION_REG register is toggled so that an inter- In X-10. where Vpk = 165V and f = 60 Hz In the United States. Timer2 interrupt through Triac Dimmer Timing Generates dimmer timing increments for controlling postscaler Triac. 40 interrupts/1 sec. A zero-crossing detector is easily cre. PORTB<6:7> Reserved for ICD Isolation precautions required. One interrupt/25 ms. DS00236B-page 3 . and on a falling edge. This will be interpreted as a logic zero. Therefore. a resistor. current capacity of a PIC MCU I/O pin. pins) clamp any voltage higher than VDD or lower than “Interfacing to AC Power Lines”. which is available for VSS. equation. TABLE 1: SUMMARY OF MICROCONTROLLER RESOURCE USE Resource Function Description External interrupt on RB0 Zero-crossing Detect Generates one interrupt every zero-crossing. and the peak On a rising edge.2 VDD = 1V on a falling edge. zero-crossing. RB0 will go high about 64 s after the line voltage is 165V.

a 0. shown on sheet 5 of the schematics in Appendix C. The amplified impedance (13) to the 120 kHz carrier frequency. and resistor. To receive X-10 signals. capacitor. RC3 is simply Since the 120 kHz carrier frequency is much higher checked within the 1 ms transmission envelope to see than the 60 Hz power line frequency.1 F 10K 10 nF X2 Rated High-Pass Filter & Tuned Amplifier(1) RC3 1 M Envelope Detector Note 1: See schematic in Appendix C. The next two Zc = 1/(2**f*C). Filter and Tuned Amplifier Block. This is accomplished with a decoupling capacitor. DS00236B-page 4  2010 Microchip Technology Inc. FIGURE 4: 120 kHz CARRIER DETECTOR Decoupling +5 VDC Capacitor PIC16F87XA 0. This high-pass filter allows the 120 kHz signal envelope detector output is buffered through an to be safely coupled to the 60 Hz power line. inverter and presented to an input pin (RC3) of the bles as the coupling stage of the 120 kHz carrier PIC16F877A. For C = 150 pF and R = 33 k. Next. nal is amplified using a series of inverters configured as high gain amplifiers. while the 120 kHz signal is passed detector. tor. it is whether or not the carrier is present. and an envelope pletely attenuated. the -3 db breakpoint is: ƒ3 db = 1/(2**R*C). and it dou. presence of the 120 kHz signal on the AC power line.AN236 120 kHz Carrier Detector For a simple high-pass filter.1 F capacitor presents a low stages provide additional amplification.5 k) to the 60 Hz power line fre. it is necessary to detect the ƒ3 db = 1/(2**150 pF *33 k) = 32 kHz. The quency. a This ƒ3 db point assures that the 60 Hz signal is com- high-pass filter. Upon each zero-crossing interrupt. A ‘0’s that form the X-10 messages described in high-pass filter forms the first stage of the High-Pass Appendix A. formed with a diode. but 120 kHz signal is passed through an envelope detec- a high impedance (26. generator described in the next section. The first two stages are tuned Because the impedance of a capacitor is: amplifiers with peak response at 120 kHz. . the 120 kHz sig- illustrated in Figure 4. The components of the carrier detector are through to the amplifier stages. The presence or straightforward to design an RC filter that will pass the absence of the carrier represents the stream of ‘1’s and 120 kHz signal and completely attenuate the 60 Hz. a tuned amplifier.

AC mains (see the warning note)! Because X-10 specifies the carrier frequency at WARNING: This circuit is not isolated from 120 VAC.2 kHz). and ensure that it is contained within a suitable cisely 120 kHz. AN236 120 kHz Carrier Generator Transformerless Power Supply X-10 uses 120 kHz modulation to transmit information The PIC16F877A and other board circuits require a 5V over 60 Hz power lines. When spikes on the AC power line. Two diodes rectify the voltage Since the impedance of a capacitor is Zc = 1/(2**f*C). A sin. Calculations for setting the PWM insulated enclosure. Since gle I/O pin would be used to enable or disable the oscil. X-10 components are intended to be plugged into a lator circuit output. in order for the CCP to generate pre. 120 kHz (+/. When the TRISC bit is set. Figure 6 illustrates the transformerless power supply put. the pin becomes an output and dependent resistor) is connected between Line and the 120 kHz signal is coupled to the AC power line Neutral. as and the 1 M resistor provides a discharge path for the depicted in Figure 5. the system oscillator is chosen to Act with caution when constructing or using such a be 7.680 MHz.680 MHz RC3/CCP 1 M OSC1  2010 Microchip Technology Inc. Since the zero-crossing detector has a maximum delay of approximately 64 Μs. available for download 120 kHz carrier detector. However. This high-pass filter allows The reader may wish to refer to the application note the 120 kHz signal to be safely coupled to the 60 Hz AN954. and it doubles as the first stage of the and Capacitive” (DS00954). To protect the circuit from the 120 kHz signal is not presented to the pin. on transformerless power supply design.1 ΜF capacitor presents a low impedance to the produce a 5V supply. formerless supplies that should be kept in mind are The CCP1 module is used in PWM mode to produce a limited current capacity. for additional information section. the firmware must take less than 236 Μs after detection of the zero-crossing to begin transmission of the 120 kHz envelope. To be compatible with other X-10 receivers. a transformer- circuit can be avoided by using one of the PIC MCU’s less power supply is used. After initialization. CCP1 is continuously enabled. the X-10 controller must also 120 kHz carrier with an external oscillator circuit. Follow isolation precautions to period and duty cycle are shown in the code listing avoid personal injury or damage to test equipment comments for the function InitPWM. the maxi- mum delay from the zero-crossing to the beginning of the X-10 envelope should be about 300 Μs. a 130V VDR (voltage the TRISC bit is clear. an external oscillator wall outlet and have a small form factor. but a high impedance to the 60 Hz power line frequency. through a transistor amplifier and capacitor. The 47 resistor limits current into the circuit.1V Zener diode to a 0. and lack of isolation from the 120 kHz square-wave with a duty cycle of 50%. the pin is an input and used in this application. circuit. described in the previous from the Microchip web site.1 ΜF X2 Rated 50 120 VAC PIC16F87XA OSC2 200 7. DS00236B-page 5 . and the TRISC bit for the pin is used to gate the PWM out. It is possible to generate the supply. 120 kHz carrier frequency. “Transformerless Power Supplies: Resistive power line. voltage left on the capacitor when the circuit is unplugged from the wall. transmit and receive its data over the AC line. Two characteristics of trans- CCP modules. and development tools. FIGURE 5: 120 kHz CARRIER GENERATOR +5 VDC High-Pass Filter 0. across the 1000 ΜF capacitor and 5. In this application.

basically acts as a high-speed.1M 1N4005 Load Switch ing value. The design and control of a lamp dimmer using a PIC MCU is discussed in detail in PICREF-4 Reference Design. the Triac will automatically switch off near each zero-crossing as the AC voltage A load switch is included on the home controller so that falls below the latching voltage. gate Triac can control AC current in both directions through the device. are wired in series with A variable dimmer is created by including a delay the load. “PICDIM Lamp Dimmer for the PIC12C508”. even though the PIC MCU can A Triac is an inexpensive. bidirectional AC switch. FIGURE 7: LOAD SWITCH/DIMMER (TRIAC) Return Hot PIC16F87XA L4008L6 MT1 120 VAC In 470 1N4148 Gate MT2 RA5 VSS 120 VAC Out DS00236B-page 6  2010 Microchip Technology Inc. as long as the load current exceeds the latch. . A Teccor® L4008L6 Triac was selected because it has because its medium power switching capacity and a sensitive gate that can be directly controlled from the rapid switching capability make it well-suited for lamp logic level output of the PIC MCU I/O pin. Because of this. A Triac was selected as the load switch. Two terminals. A small trigger current between the gate and between the time of each zero-crossing and the time MT1 allow conduction to occur between MT1 and MT2. that the trigger current is provided to the Triac from the Current continues to flow after the gate current is PIC MCU. three-terminal device that provide only positive voltages to the gate.AN236 FIGURE 6: TRANSFORMERLESS POWER SUPPLY VDR 1N4005 2.25 ΜF +5 VDC N L PTC 2.1V Zener 1. with its own house and unit address. MT1 and MT2. removed. The sensitive control and dimming. it may act as a lamp module.25 ΜF 1000 ΜF G 5.

minutes. To use EEPROM memory space most efficiently (by avoiding wasted bits). TMR1H:TMR1L are pre-loaded with 0xFCE0h. AN236 LCD Module development tool. However. 0x022 Unit 3 A B OnMin Push Buttons 0x030 Unit 1 A B OffMin Five push buttons. control flags for 16 units. a CdS photoresistor is Each time that minutes are incremented within the used in conjunction with an 820 resistor to create a UpdateClock routine. on/off times and light sensor Real-Time Clock control flags are stored using the format shown in A real-time clock is implemented using Timer1. and hours. Light Sensor To detect the ambient light level. 1 1 6 bits B = Control bit for On at Dusk ScanKeys. In Address Unit Data order for Timer1 to generate an interrupt once every 25 ms. Since ScanKeys performs debouncing of the 1 1 6 bits button presses. (ICD). tions for controlling this type of LCD. a suitable rate to check the buttons is EEOffMinutes C D Off Min once every 25 ms. time with the unit on and off times stored in EEPROM memory. By adding a specific offset to Timer1 each 4 bits 4 bits time it overflows. built-in EEPROM is well-suited to this task. by sending it the appropriate X-10 RB6 and RB7 have been reserved for In-Circuit Serial command when the routine ControlX10Units is ProgrammingTM (ICSPTM) and the In-Circuit Debugger called. the time before the next overflow can A = AM/PM bit for On Hour EEHours On Hour Off Hour be precisely controlled. It also determines the this data organization. If there is a match. The Figure 8. are used for 0x031 Unit 2 A B OffMin user interaction with the application. is called each time a Timer1 interrupt C = AM/PM bit for Off Hour EEOnMinutes A B OnMin D = Control bit for Off at Dawn occurs. with some additional Certain control data that is programmable by the user software overhead. DS00236B-page 7 . Minutes and hours are 0x021 Unit 2 A B OnMin incremented in a similar fashion. can be seen in the following equation: 0x010 Unit 1 OnHour OffHour (FFFFh – FCE0h)*1/32 kHz = . UpdateClock keeps track of the time unit variables: ticks. The voltage on the divider varies with tine called CheckOnOffTimes to be called from the the intensity of ambient light and is connected to an main loop. Eight data lines and three control lines are used to interface to the PIC MCU. CheckOnOffTimes compares the present analog channel (AN0) of the microcontroller. 0x001 System House Address 0x002 System Unit Address The Timer1 interrupt interval. 0x020 Unit 1 A B OnMin mented every 40 ticks. With a 32 kHz crystal. connected to RB1-RB5. The PIC MCU’s this application.25 Μs when the prescaler is set to 1:1. seconds. the LCD can be operated in Nibble mode using only four data lines. Using routine called UpdateClock. Figure 9 shows the location of on/off times real-time clock keeps track of the present time using a and other information within the data EEPROM. Each normally open 0x032 Unit 3 A B OffMin push button will pull a port pin low when it is pressed. The button reading routine. Timer1 is set to cause an interrupt each time it FIGURE 8: ON/OFF TIME STORAGE overflows. If fewer I/O Control Data Storage pins are available.025 s = 1 tick 0x011 Unit 2 OnHour OffHour Each time ScanKeys is called (every 25 ms). A basic LCD library is included in must be stored in non-volatile memory. or tick. it calls 0x012 Unit 3 OnHour OffHour UpdateClock. the counter increments once FIGURE 9: EEPROM DATA every 31. then a flag is set to either In-Circuit Debugger turn the unit on or off. which provides the necessary func. a flag is set that enables a rou- voltage divider. only 48 bytes of EEPROM are rate that the buttons are read by a routine called required to store the on/off times and light sensor ScanKeys. seconds are incre. Since every 25 ms equals one tick. without taking first isolating the entire application from wall power (see the previous The 2-line x 16-character display uses the HD44780U warning notes)! Display Controller. do not connect the ICD or any other  2010 Microchip Technology Inc.

The X-10 library Before sending an X-10 message. which is signified by the X10TxFlag being set. To send an address contained in the user variables MyHouse and MyUnit. home controller. PIC16F877A parts. Examples of how the macros • x10hc. This macro simply checks that flag and skips the next instruction if it is okay to begin a new transmission. It must be called in the applica- • p16f877A. vide X-10 functionality.asm Example code that shows how to use the X-10 library macros. application note: To use the library. modification in a user’s application.AN236 APPLICATION FIRMWARE X-10 LIBRARY OVERVIEW A simple library of commands was developed and used The firmware is divided into several different files to for the home controller. defined by variables rather than constants. one simply types: SendX10Address HouseP.asm Defines X-10 there is a chance that a new transmission will interrupt an ongoing transmission.asm and x10lib.transmit next message SendX10Address (House.contains a value Standard include file for InitX10 PIC16F877A Defines X-10 constants and nating the need for the user to understand every X-10 macros. SkipIfTxReady Detailed descriptions of operation can be found in the comments within the code listing.contains a value .asm. Otherwise. It requires two arguments. Unit16 SendX10AddressVar This macro is used to send an X-10 address. .from 0-16 MOVWF TxUnit SendX10AddressVar DS00236B-page 8  2010 Microchip Technology Inc.from 0-16 MOVWF TxHouse MOVF MyUnit.loop until ready to . it is necessary to functions and macros are described in the next section. a house address and unit address. the following sequence would be applied: MOVF MyHouse. It is used as follows: SkipIfTxDone GOTO $-1 . The macros greatly simplify the use of the library by elimi- • W . The definitions for all house and unit addresses are defined in x10lib. Unit) This macro is used to send an X-10 address for a par- ticular unit. function of the macros defined in x10lib. a user need only understand the • x10lib.asm Defines the routines necessary This macro is used to initialize the peripherals that pro- for driving the LCD. InitX10 • lcd. The macros are explained below: • x10demo. It can be used with little or no facilitate adaptation of the code to other applications. It is used as follows: • p16f877A. W .lkr Standard linker file for tion program before any of the below macros will work. The library consists Following is a summary of the files associated with this of two files: x10lib.asm Main application code for the are used are included in the file x10demo. make sure that another message is not already being function in x10lib. To use this macro to send the address for unit 16 at house P.

W . If the message was a command.defined in .inc.loop until address . It It may be necessary to make sure that an address was requires two arguments. The definitions for all house addresses and RxCommandFlag is clear.from 0-16 SkipIfCommandRcvd MOVWF TxHouse GOTO $-1 . SkipIfRxDone then the received house address and function code will Before reading an X-10 message. SkipIfRxDone GOTO $-1 . which checks to see MyCommand to all units at MyHouse. function codes are defined in x10lib. which may be either an address or a command.function ReadX10Message . respectively. it is necessary to be stored in the variables RxHouse and RxFunction. AllLightsOn GOTO $-1 . MOVF MyHouse.received  2010 Microchip Technology Inc.received SendX10CommandVar SkipIfCommandRcvd This macro is used to send an X-10 command.loop until command MOVF MyCommand.loop until message . the house address and func. Please refer to the example code in x10demo. W . make sure that a complete message has been It is simply called as follows: received.contains a value It is used as follows: .asm to see how each of these macros is used in a simple It is used as follows: application. then the received house and SendX10CommandVar unit codes will be stored in the variables RxHouse and RxUnit. which checks to see if the tion code. To use this macro This macro is called to read a received X-10 message. AN236 SendX10Command (House. defined by a variable rather than a constant. ReadX10Message This macro simply checks that flag and skips the next instruction if a new X-10 message has been received. one types: SkipIfAddressRcvd SendX10Command HouseA. one types: if the RxCommandFlag is set. To use this It is used as follows: macro to send the command ‘All Lights On’ to all units at house A.received . DS00236B-page 9 . If the MOVWF TxFunction message was an address. This is signified by the X10RxFlag being set.any X-10 .x10lib. Function) SkipIfAddressRcvd This macro is used to send an X-10 command. received by using this macro. it may be necessary to make sure that a command to send the command stored in the user variable was received by using this macro.

. TABLE 3: SUMMARY OF MEMORY USAGE FOR THE HOME CONTROLLER Memory Type Used Available on PIC16F877A Percent Used Flash Program Memory 3762 words 8453 words 44.5% Data Memory (RAM) 168 bytes 368 bytes 45.6% EEPROM Data Memory 51 bytes 256 bytes 20% DS00236B-page 10  2010 Microchip Technology Inc.AN236 Memory Usage Memory usage for the X-10 portion of the application is summarized in Table 2. TABLE 2: SUMMARY OF MEMORY USAGE FOR X-10 FUNCTIONALITY Memory Type Used Available on PIC16F877A Percent Used Flash Program Memory 437 words 8453 words 5% Data Memory (RAM) 62 bytes 368 bytes 17% EEPROM Data Memory 0 bytes 256 bytes 0% Memory usage for the entire home controller application is summarized in Table 3.

have plenty of additional resources for • http://www.x10. were adapted to the home controller the X-10 library leaves ample space for the user to cre.  2010 Microchip Technology Inc. while smaller The Microchip web site features data sheets. X-10 system that can transmit and receive messages Parts of this project’s receiver circuit.abacuselectrics. ate application specific code. PIC MCUs. documentation available here include: AN521 “Interfacing to AC Power Lines” AN954. DS00236B-page 11 . a PIC MCU can be used to implement an module that utilizes the PIC16C52 or PIC16F84.microchip. Helpful technical simpler X-10 creating more complex X-10 applications. AN236 CONCLUSION USEFUL WEB REFERENCES The PIC MCU is well-suited to X-10 applications. “Transformerless Power Supplies: Resistive and Capacitive” PICREF-4 “PICDIM Lamp Dimmer for the PIC12C508” • http://www. such as the The X10 Wireless Technology. web site features technical information and FAQs pertaining to the X-10 communication protocol. The small code size of Phil Plunkett. With • http://www. designed by over the AC power line wiring. product PIC MCUs can be selected for economical use in information. and more.htm its plethora of on-chip peripherals and a few external This web site describes how to build an appliance components. Inc.

333 ms (1) (1) Note 1: These 120 kHz carrier bursts are timed to coincide with the zero-crossing of the other phases.AN236 APPENDIX A: HOW DOES THE X-10 PROTOCOL WORK? X-10 transmissions are synchronized with the zero-crossings on the AC power line. . A complete X-10 message is composed of a start code (1110). when implemented. followed by a house code. X-10 devices know when to trans- mit or receive X-10 information.778 ms 5. DS00236B-page 12  2010 Microchip Technology Inc. Table A-1 and Table A-2 show the possible values of the house and key codes. near the zero-crossing point of the AC. A binary ‘1’ is repre- sented by a 1 ms long burst of 120 kHz. By monitoring for the zero-crossings. A binary zero is represented by the lack of the 120 kHz burst. depending on whether the message is an address or a command. followed by a key code. FIGURE A-1: X-10 TRANSMISSION TIMING (1) (1) 120 kHz 60 Hz 1 ms 2.556 ms 8. The key code may be either a unit address or a function code.

one bit per zero-crossing. the E 0 0 0 1 start code is the only place where the pattern 1110 will F 1 0 0 1 appear in an X-10 data stream. key code and suffix. For example. DS00236B-page 13 . and the code transmitted as C 0 0 1 0 complimentary bit pairs is 01101001.. or six zero-crossings. G 0 1 0 1 The key code. unit 2. please refer to the X10 Wireless (Analog) Technology. For A 0 1 1 0 example. the four-bit B 1 1 1 0 code in Table A-1 is 0110. the last bit K 0 0 1 1 of the key code can be treated as a suffix that denotes L 1 0 1 1 whether the key code is a unit address or function M 0 0 0 0 code. which is 5-bits long in Table A-2. the Hail Request 1 0 0 0 1 bright and dim codes do not require the 3-cycle wait Hail Acknowledge 1 0 0 1 1 between consecutive dim commands or consecutive Pre-set Dim 1 0 1 X 1 bright commands. between each pair of data blocks. Status = Off 1 1 1 0 1 Status Request 1 1 1 1 1  2010 Microchip Technology Inc. with 3 power line cycles. to turn on an X-10 module assigned to Key Codes house code A. wait for three cycles (six zero-crossings) before Dim 0 1 0 0 1 sending the next block: Function Codes Bright 0 1 0 1 1 000000 All Lights Off 0 1 1 0 1 Extended Code 0 1 1 1 1 There are exceptions to this format. N 1 0 0 0 A complete block of data consists of the start code.e. the following data stream would Unit Addresses be sent on the power line. For a complete discussion of all Extended Code 1 1 0 0 1 X-10 messages. Each data block is P 1 1 0 0 sent twice. wait for three cycles (six zero-crossings): 10 1 1 1 1 0 000000 11 0 0 1 1 0 12 1 0 1 1 0 Then. two zero-crossings are used to transmit House House Codes each bit as complementary bit pairs (i. AN236 TABLE A-1: HOUSE CODES When transmitting the codes in Table A-1 and Table A-2. in order to send the house code A. O 0 1 0 0 house code. D1 D2 D4 D8 D16 1 0 1 1 0 0 First. I 0 1 1 1 Because the last bit of the key code is always zero for J 1 1 1 1 a unit address and one for a function code. Inc. a zero is rep- Addresses H1 H2 H4 H8 resented by 0-1. send the command twice: 13 0 0 0 0 0 1110 01101001 01011001 10 14 1 0 0 0 0 15 0 1 0 0 0 START HOUSE A ON Suffix 16 1 1 0 0 0 All Units Off 0 0 0 0 1 1110 01101001 01011001 10 All Units On 0 0 0 1 1 START HOUSE A ON Suffix On 0 0 1 0 1 Off 0 0 1 1 1 Lastly. and a one is represented by 1-0). send the address twice: 2 1 1 1 0 0 1110 01101001 10101001 01 3 0 0 1 0 0 START HOUSE A UNIT 2 Suffix 4 1 0 1 0 0 5 0 0 0 1 0 6 1 0 0 1 0 1110 01101001 10101001 01 7 0 1 0 1 0 START HOUSE A UNIT 2 Suffix 8 1 1 0 1 0 9 0 1 1 1 0 Next. web site (see the "USEFUL WEB Status = On 1 1 0 1 1 REFERENCES" section). TABLE A-2: KEY CODES For example. Since house and D 1 0 1 0 key codes are sent using the complimentary format. takes H 1 1 0 1 10 bits to represent in the complimentary format.

Select Function Screen 7. Immediately. . each of the five buttons performs a menu up down enter exit menu up down enter exit different function. 3. enables access to the Select Function screen. as illustrated in Figure B-2. including AM or PM. the home controller.AN236 APPENDIX B: HOME CONTROLLER FIGURE B-2: SELECT FUNCTION OPERATING SCREENS INSTRUCTIONS Select Function Select Function Welcome Screen Set System Time Set System Addr The home controller user interface consists of five but- tons and a 2 x 16 LCD. Welcome Home 4. Depending on the screen viewed. SETTING SYSTEM TIME • Press enter to turn the lamp on. 4 3 When the Welcome screen is displayed. Select Function Select Function Program Unit Set Light Sensor Figure B-1 shows the Welcome screen and the location and functionality of each button. 12:00:00 AM 5. Press enter when the correct hour. menu up down enter exit 1 Set System Time 12:00 AM Set min menu up down enter exit 2 Set System Time 12:00 AM Okay? Y menu up down enter exit 3 DS00236B-page 14  2010 Microchip Technology Inc. setting the 12:00 AM Set hrs light sensor. If the time is not correct. menu up down enter exit 6. 1. press menu • Press exit to turn the lamp off. Starting from the Welcome screen. This will return the user to step 2 so the correct time can be entered. Press up/down to set the hours. Press exit at any time to return the user to the When viewing the Welcome screen. This screen displays a welcome 1 2 message and the time. the buttons enable access to the following functions: • Press menu to enter the Select Function screen. Set System Time Screen • Press up to brighten the lamp that is plugged into Use the Set System Time screen to set the time. • Press down to dim the lamp. until the Set System Time screen is displayed and press enter. the Welcome menu up down enter exit menu up down enter exit screen is displayed. or programming the unit on and off times. setting the system address. select N and press enter. Repeat this process to set the minutes. FIGURE B-1: WELCOME SCREEN 2. If the time is correct. the seconds begin incrementing and the PIC MCU begins keeping track of the time. Upon power-up. This returns to the Welcome screen with the new time displayed. has been selected. select Y (the default) using the up/down buttons and press enter. Each successive press of the menu button cycles through FIGURE B-3: SET SYSTEM TIME SCREENS the four main functions of the user interface: setting the Set System Time system time. the menu button Welcome screen without saving the new time.

enter. Press enter when the house address has been house address. Press up or down to select the desired unit. If the address is not correct. select N and press Dawn” prompt is displayed will return the user to enter. Press exit at any time to return the user to the parameter. Repeat this process to set other units as and press enter. 2. This will return the user to step 2. Press enter when the desired unit address has 4. SETTING HOUSE/UNIT ADDRESS SETTING THE LIGHT SENSOR 1.P). This returns to the Welcome desired. DS00236B-page 15 . and press enter. the Welcome screen without modifying that 7. Pressing exit while the “On at Dusk” or “Off at 6. 3. The letter from A . Welcome screen without saving the new address. If the house and unit addresses are correct. house address will already be set to the system 3. non-volatile memory. units turn on at dusk. number from 1 . or off at dawn. Press up or down to select whether or not the 5. select Y (the default) using the up/down buttons 5. FIGURE B-5: SET LIGHT SENSOR SCREENS FIGURE B-4: SET SYSTEM ADDRESS SCREENS Set Light Sensor A-01 Set Unit Set System Addr A-01 Set House menu up down enter exit 1 menu up down enter exit Set Light Sensor 1 On at Dusk? Y Set System Addr A-01 Set Unit menu up down enter exit 2 menu up down enter exit Set Light Sensor 2 Off at Dawn? Y Set System Addr A-01 Okay? Y menu up down enter exit 3 menu up down enter exit 3  2010 Microchip Technology Inc. Repeat steps 2 and 3 to set the unit address (a been selected. unit should turn on at dusk. screen with the new address stored in 6. 4. press menu until the Set System Addr screen is displayed and press Set Light Sensor screen is displayed and press enter. Press exit to return to the Welcome screen. AN236 Select System Address Screen Set Light Sensor Screen Use the Set System Address screen to set the house Use the Set Light Sensor screen to select whether address and unit address of the home controller. From the Welcome screen. From the Welcome screen. selected.16). Press up or down to set the house address (a 2. press menu until the 1.

then the minutes will be set to ‘00’ automatically. Press enter when the unit address has been selected. press menu repeat. This allows the user to re-enter the hour and minutes by returning to step 2. If the time is not correct. 5. If the time is correct. menu up down enter exit If the hour has been set to ‘00’. select Y (the default) using the up/down buttons and press enter. 6. The user Program On-Time will be prompted to program the ‘off’ time in a 00:00AM Okay? Y N similar fashion. Repeat this process to set the ‘on’ time minutes. Hours set to ‘00’ means that the unit will not be turned on at any time. 7.AN236 Program Unit Screen FIGURE B-6: PROGRAM UNIT ‘ON’ TIME SCREENS Use the Program Unit screen to program on and off times for different units. has been selected. Repeat this process to set the ‘on’ and ‘off’ time for other units as desired. 00:00AM Set hrs 3. From the Welcome screen. Press up or down to select the desired unit. Y 9. 8. Press up or down to set the ‘on’ time hours. menu up down enter exit edly until the Program Unit screen is displayed and press enter. 2. 00:00AM Set hrs Pressing exit while the “Set Hours” or “Set Min” prompt is displayed will return the user to the menu up down enter exit Welcome screen without modifying any parameters. menu up down enter exit 4. Program Off-Time 00:00AM Set min menu up down enter exit Program Off-Time N 00:00AM Okay? Y menu up down enter exit Y DS00236B-page 16  2010 Microchip Technology Inc. select N and press menu up down enter exit enter. Press enter when the correct hour. Program Off-Time 10. . Press exit to return to the Welcome screen. including AM Program On-Time 00:00AM Set min or PM. Program Unit A-01 Set Unit PROGRAMMING UNIT ON AND OFF TIMES 1. The house address will already be set to the system Program On-Time house address.


AN236 FIGURE C-2: SHEET 2 OF 5 EXIT RD0 RD1 RD2 RD3 RD4 RD5 RD6 RD7 ENTER DOWN LCD1 CDS RE2 RE1 RE0 UP MENU DS00236B-page 18  2010 Microchip Technology Inc. .

AN236 FIGURE C-3: SHEET 3 OF 5 TRIAC +5V XIOCIRCUITS  2010 Microchip Technology Inc. DS00236B-page 19 .

.AN236 FIGURE C-4: SHEET 4 OF 5 ZEROX CARRIERDATA XIOCIRCUITS XOUT DS00236B-page 20  2010 Microchip Technology Inc.

DS00236B-page 21 . AN236 FIGURE C-5: SHEET 5 OF 5 XIN CARRIERDATA  2010 Microchip Technology Inc.

C24 10 pF Capacitor 1 C27 100 pF Capacitor 2 C18. C6. C11.8V Zener Diode 2 D4. R5.7 nF Capacitor 1 C20 10 nF Capacitor 2 C23. . S2. 250V x2 Capacitor 2 C21. D5 1N4005 Diode 2 D3.3 nF Capacitor 2 C25. D2 LTL-94PEKTA LEDs 1 U1 PIC16F877A Microcontroller 1 R6 20 k Potentiometer 1 PTC1 CdS Cell 1 R18 1 M Resistor 1 R14 1.1V Zener Diode 1 Q2 2N2222 NPN Transistor 1 J2 Power In Connector 2 J1 Power Out Connector 1 U2 CD4069 HEX Inverters 8 C1. S4. R8. C26 4. S3. C5.AN236 APPENDIX D: PARTS LIST Count Reference Value Description 2 D7. C7 15 pF Capacitor 1 C13 0.1 ΜF. C12 0. R3 680 Resistor 1 R10 820 Resistor 1 R11 470 Resistor 1 R12 470 k Resistor 1 R26 10 M Resistor 6 S1. P6. P7 Test Points 1 Q1 TIC206D Sensitive Gate Triac 1 VDR1 130V Varistor (Voltage Dependent Resistor) DS00236B-page 22  2010 Microchip Technology Inc. S5. R21 10 k Resistor 1 R22 33 k Resistor 1 R25 47 k Resistor 1 R19 50 k Resistor 1 R16 100 k Resistor 2 R15. 275 VAC x2 Capacitor 1 Y2 7. C10.1 ΜF Capacitor 2 C14. R7. C15 2. C9.25 ΜF. C2. C22 3. R4. D9 1N4148 Diode 1 D6 5. S6 Push Button Switches 7 P1. C19 150 pF Capacitor 1 C16 1000 ΜF. L2 220 ΜH Axial Lead Inductor 1 LCD1 CG161 HD44780-based 2x16 Liquid Crystal Display 2 D1.680 MHz Crystal 1 Y1 32 kHz Crystal 2 L1. D8 6. P5. 25V Capacitor 1 C17 0. P3. P4.1 M Resistor 1 R13 2 M Resistor 1 R17 5 M Resistor 7 R1. C3. R23 100 k Resistor 1 R20 200 Resistor 1 R24 220 k Resistor 2 R2. R9. C8. P2.1 ΜF Capacitor 4 C4.

AN236 APPENDIX E: SOURCE CODE Due to size considerations.microchip. DS00236B-page 23 . A complete version of the source code. the complete source code for this application note is not included in the text. at: www. with all required support files. is available for download as a Zip archive from the Microchip web  2010 Microchip Technology Inc.

.AN236 NOTES: DS00236B-page 24  2010 Microchip Technology Inc.

FanSense. ICSP. to our knowledge.. In addition. MPLINK. All other trademarks mentioned herein are property of their respective companies.A. We at Microchip are committed to continuously improving the code protection features of our products. SEEVAL and The Embedded Control QUALITY. • There are dishonest and possibly illegal methods used to breach the code protection feature. WiperLock and ZENA are trademarks of Microchip Technology Incorporated in the U. and other WARRANTIES OF ANY KIND WHETHER EXPRESS OR countries. indemnify and ECONOMONITOR. the person doing so is engaged in theft of intellectual property. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Octopus. claims. MXDEV. PIC32 logo. the Microchip logo. you may have a right to sue for relief under that Act. MiWi. Programming. Use of Microchip Analog-for-the-Digital Age. Information contained in this publication regarding device Trademarks applications and the like is provided only for your convenience The Microchip name and logo. nonvolatile memory and analog products. when used in the intended manner and under normal conditions.A. ECAN. Linear Active Thermistor. Application Maestro. Total Endurance. PICC.A.S. dsPIC.S. MXLAB. Serial EEPROMs.S. • Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. CodeGuard.Note the following details of the code protection feature on Microchip devices: • Microchip products meet the specification contained in their particular Microchip Data Sheet. UniWinDriver. MERCHANTABILITY OR Solutions Company are registered trademarks of Microchip FITNESS FOR PURPOSE. Microchip Technology Incorporated. intellectual property rights. In-Circuit Serial hold harmless Microchip from any and all damages. PERFORMANCE. and may be superseded by updates. and other countries. INCLUDING BUT NOT LIMITED TO ITS CONDITION. the buyer’s risk.A. Arizona. The Company’s quality system processes and procedures are for its PIC® MCUs and dsPIC® DSCs. mTouch. PICtail. devices in life support and/or safety applications is entirely at dsPICDEM. Oregon and design centers in California and India. If such acts allow unauthorized access to your software or other copyrighted work. PICkit. MPLAB Certified suits. PICSTART. Mindi. dsPICDEM. dsSPEAK. Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified. PICDEM. PIC. No licenses are logo. PICmicro. design and wafer fabrication facilities in Chandler and Tempe.  2010 Microchip Technology Inc. Microchip disclaims all liability Technology Incorporated in the U. require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data Sheets. RELATED TO THE INFORMATION. It is your responsibility to KEELOQ. Most likely. All of these methods. All Rights Reserved. PICC-18. • Microchip believes that its family of products is one of the most secure families of its kind on the market today. MPLIB. rfLAB. Select Mode. IMPLIED. ensure that your application meets with your specifications. under any Microchip Generation. REAL ICE. MPLAB.S. DS00236B-page 25 . FilterLab. MPASM.A. ISBN: 978-1-60932-125-3 Microchip received ISO/TS-16949:2002 certification for its worldwide headquarters. Code protection does not mean that we are guaranteeing the product as “unbreakable. © 2010. STATUTORY OR OTHERWISE. SQTP is a service mark of Microchip Technology Incorporated in the U. • Microchip is willing to work with the customer who is concerned about the integrity of their code. KEELOQ logo. KEELOQ® code hopping devices. Gresham. Hampshire. Printed in the U. HI-TECH C. PICDEM. microperipherals. rfPIC and UNI/O are registered trademarks of MICROCHIP MAKES NO REPRESENTATIONS OR Microchip Technology Incorporated in the U. implicitly or otherwise. Printed on recycled paper. WRITTEN OR ORAL. and the buyer agrees to defend.” Code protection is constantly evolving. arising from this information and its use. dsPICworks. HI-TIDE. Omniscient Code conveyed.S. or expenses resulting from such use.

Qingdao Philippines .Taipei Fax: 949-462-9608 Tel: 86-27-5980-5300 Tel: 886-2-2500-6610 Fax: 86-27-5980-5118 Fax: 886-2-2508-0102 Santa Clara Santa Clara.6166 Tel: 86-10-8528-2100 Fax: 49-89-627-144-44 Fax: 678-957-1455 Fax: 81-45-471-6122 Fax: 86-10-8528-2104 Italy . OH Fax: 852-2401-3431 Fax: 60-3-6201-9859 UK .Nanjing Tel: 44-118-921-5869 Malaysia . AZ 85224-6199 Tower 6.Xiamen Mississauga.Drunen Fax: 774-760-0088 Korea .Munich Duluth.Zhuhai Fax: 905-673-6509 Tel: 86-756-3210040 Fax: 86-756-3210049 01/05/10 DS00236B-page 26  2010 Microchip Technology Inc. IN Fax: 86-24-2334-2393 Fax: 886-3-6578-370 Tel: 765-864-8360 Fax: 765-864-8387 China . Ontario.Xian Thailand .Sydney Tel: 91-20-2566-1512 Tel: 33-1-69-53-63-20 www. WORLDWIDE SALES AND SERVICE AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPE Corporate Office Asia Pacific Office India .Pune France .Hong Kong SAR Tel: 34-91-708-08-90 Malaysia .Shanghai Singapore Farmington Hills.Milan Boston Korea .Yokohama China . .Kaohsiung Tel: 86-755-8203-2660 Tel: 886-7-536-4818 Los Angeles Fax: 86-755-8203-1760 Fax: 886-7-536-4803 Mission Viejo.Chongqing Tel: 82-2-554-7200 Tel: 31-416-690399 Chicago Tel: 86-23-8980-9588 Fax: 82-2-558-5932 or Fax: 31-416-690340 Itasca.Bangkok Tel: 408-961-6444 Tel: 86-29-8833-7252 Tel: 66-2-694-1351 Fax: 408-961-6445 Fax: 86-29-8833-7256 Fax: 66-2-694-1350 Toronto China .microchip. Kowloon Denmark .Daegu China .Paris Web Address: Australia .Shenzhen Taiwan .Manila Tel: 972-818-7423 Tel: 86-532-8502-7355 Tel: 63-2-634-9065 Fax: 972-818-2924 Fax: 86-532-8502-7205 Fax: 63-2-634-9069 Detroit China . Suites 3707-14.Wokingham Tel: 216-447-0464 China .com Tel: 61-2-9868-6733 Fax: 91-20-2566-1513 Fax: 33-1-69-30-90-79 Atlanta Fax: 61-2-9868-6755 Germany .Shenyang Taiwan .Copenhagen India .microchip.Bangalore Austria .Wels 2355 West Chandler Blvd. CA China .Hsin Chu Kokomo Tel: 86-24-2334-2829 Tel: 886-3-6578-300 Fax: 852-2401-3431 India . TX China .Penang Fax: 216-447-0643 Tel: 86-25-8473-2460 Fax: 44-118-921-5820 Tel: 60-4-227-8870 Dallas Fax: 86-25-8473-2470 Fax: 60-4-227-4068 Addison. IL Tel: 630-285-0071 Fax: 86-23-8980-9500 82-2-558-5934 Spain . GA Japan . MA Tel: 82-53-744-4301 Tel: 86-28-8665-5511 Fax: 39-0331-466781 Tel: 774-760-0087 Fax: 82-53-744-4302 Fax: 86-28-8665-7889 Netherlands .Beijing Tel: 49-89-627-144-0 Tel: 678-957-9614 Tel: 81-45-471. 37th Floor Tel: 91-80-3090-4444 Tel: 43-7242-2244-39 Chandler. CA Tel: 949-462-9523 China .Wuhan Taiwan . MI Tel: 86-21-5407-5533 Tel: 65-6334-8870 Tel: 248-538-2250 Fax: 86-21-5407-5066 Fax: 65-6334-8850 Fax: 248-538-2260 China .Madrid Fax: 630-285-0075 China .Seoul China . The Gateway Fax: 91-80-3090-4123 Fax: 43-7242-2244-393 Tel: 480-792-7200 Harbour City.New Delhi Fax: 480-792-7277 Hong Kong Tel: 45-4450-2828 Tel: 91-11-4160-8631 Technical Support: Tel: 852-2401-1200 Fax: 45-4485-2829 Fax: 91-11-4160-8632 http://support.Kuala Lumpur Tel: 852-2401-1200 Tel: 60-3-6201-9857 Fax: 34-91-708-08-91 Cleveland Independence.Chengdu Tel: 39-0331-742611 Westborough. Tel: 86-592-2388138 Canada Fax: 86-592-2388130 Tel: 905-673-0699 China .