"Remotely Programmable RTC-Interfaced Microcontroller for Multiple"
CONSTRUCTION Remotely Programmable RTC-Interfaced Microcontroller for Multiple Device Control RAJA GOPAL AKELLA pressed at the remote control. This bit ally to the same type of coding with- is used to identify whether the button out any disturbance, i.e., one among T his project based on Atmel is really pressed or whether an obstacle the 64 devices can be identified AT89C52 and Dallas real-time- came in between the IR path of the uniquely. Addresses of some of the clock (RTC) chip DS12887 can remote and the IR receiver. remotes are shown in Table III. be used to control and remotely pro- The five bits (A4 through A0) im- The six bits (C5 through C0) im- gram the switching operation of 24 mediately following the toggle bit are mediately following the five address electrically operated devices. The de- used to identify the device (see Table bits are the control/command bits. vices can be switched on/off at pre- III). So, a maximum of 32 devices can Therefore a maximum of 64 commands cise times repeatedly every day, every be identified to and respond individu- can be equipped in an RC5-type re- month. The microcontroller can be mote. Some of the command codes programmed for device control using (decimal equivalents), as used in this PARTS LIST a normal Philips TV remote control. project, are shown in Table IV. Semiconductors: IC1 - AT89C52 microcontroller When any of the command/con- RC5 coding IC2 - 74LS573 octal D-type trol buttons on the remote is pressed, Since the circuit makes use of Philips latch the coded signal is received by the IC3 - DS12887 real-time clock TV remote for device-switching time IC4 - 74LS138 decoder IR receiver-demodulator TSOP1738. parameters, you need to know the fun- IC5 - 7400 NAND gate The output of the IR demodulator damentals of the coding format used IC6 - 82C55 programmable circuit is normally high, but when in these IR remotes. peripheral interface any of the buttons in the remote is IC7- IC9 - ULN2803 high current The Philips IR format makes use octal Darlington array pressed, a stream of low-going de- of RC5 code, which is also known as IC10 - 7805 5V regulator modulated pulses will appear at its ‘bi-phase coding.’ In RC5-coded sig- IRX1 - TSOP1738 IR receiver output. These pulses are fed to the module nals (Fig. 2), each bit has a uniform external active-low interrupt input BR1 - 1A bridge rectifier duration. A transition in the middle of T1 - BC547 npn transistor pin (INT/0) of 89C52. On receipt of the time interval assigned to each bit Resistors (all ¼-watt, ±5% carbon): the first low-going pulse, the moni- encodes its logical value (‘0’ or ‘1’). A R1, R6-R29 - 4.7-kilo-ohm tor program of 89C52 will get inter- high-to-low transition assigns the bit R2, R3 - 10-kilo-ohm rupted and jump to the location R4 - 100-ohm a logic value of ‘0,’ and a low-to-high R5 - 1-kilo-ohm ‘0003H,’ where the execution is redi- transition assigns the bit a logic value VR1 - 10-kilo-ohm preset rected to ‘receive’ sub-routine of the of ‘1.’ We need additional transitions VR2 - 1-kilo-ohm preset program. The outputs from the sub- at the beginning of each bit if a stream Capacitors: routine are: C1, C2 - 33pF ceramic disk of equal bits is sent. However, there is C3 - 10μF, 16V electrolytic 1. Toggle bit, which toggles (either no need of additional transitions if the C4-C8, C11 - 100nF ceramic disk ‘0’ or ‘1’) each time the button in a next bit has a different logic value. C9 - 1μF, 16V electrolytic remote is pressed. Table II shows how all the com- capacitor 2. Address byte, whose value is C10 - 1000μF, 35V electrolytic mands of an RC5 remote control are capacitor zero for a normal Philips-type TV re- encoded. Miscellaneous: mote control (see Table III). The first two bits are ‘start’ bits, X1 - 230V AC primary to 15V, 3. Control byte, which has a unique which are used to adjust and 500mA secondary value for each button in the remote transformer synchronise the receiver. These bits are RL1-RL24 - 12V, 200-ohm, 1C/O control (see Table IV). used to calculate and analyse the bit relay length of the other bits. S1 - Push-to-on switch The hardware - 16×2 LCD module The third bit is a ‘toggle’ bit, which Microcontroller AT89C52 is interfaced XTAL - 11.09 MHz crystal is toggled every time a button is to DS12887 (RTC), a 16x2 LCD mod- SEPTEMBER 2006 WWW.EFYMAG.COM CMYK CONSTRUCTION ule and an 8255 programmable periph- as shown in Fig. 1. The interfacing cir- various peripheral devices is shown in eral interface (PPI). The address-decod- cuitry for the external electrical appli- Table I. ing circuitry comprises NAND gates ances comprises Darlington array IC In 89C52 (IC1), port P0 is used for 74LS00 and 3-to-8 line decoder 74LS138 ULN2803. The addressing range of outputing multiplexed address (lower SEPTEMBER 2006 WWW.EFYMAG.COM CMYK CONSTRUCTION TABLE II RC5 Coding Format S S T A4 A3 A2 A1 A0 C5 C4 C3 C2 C1 C0 8-bit) and data. The address is latched ranges 000H-0FFH, 100H-1FF and 200- into 74LS573 (IC2) octal latch and RTC 2FF for RTC, LCD module and PPI DS12887 (IC3) chip, respectively. with the help of Quad NAND gate 7400 (IC5) in ALE (address conjunction with read and write sig- latch-enable) out- nals from IC1 and chip-select signal put from pin 30 of from pin 14 of IC4 is used for select- IC1. ing the LCD module both during read Only two ad- and write cycles of IC1. dress lines from PPI chip 8255 is configured with IC2 (A0 and A1) port A, port B and port C as output have been used ports for controlling up to 24 electrical for addressing the appliances via relays RL1 through four registers of RL24. Relays are energised through 8255 PPI (IC6) in high-current octal Darlington arrays conjunction with the chip- inside ULN2803 (IC7 through IC9) in TABLE I select signal at pin 6 (from accordance with programmed data I/O Address Range of IC4) and read/write signals stored in the non-volatile RAM (NV Peripheral Devices from IC1. Higher-address RAM) of RTC chip DS12887. There is bits from port P2 of IC1 (A8, no need of connecting external free- Address range Used address range Device name A9 and A10 from output wheeling diodes across relays as 0000 00FF 0000 to 007F DS12887 (RTC chip) pins P2.0, P2.1 and P2.2) are inbuilt diodes are provided in 0100 01FF 0100 LCD Module (16×2) used for generating the chip- ULN2803 ICs. 0200 02FF 0200 to 0203 8255 (PPI) select signals from 74LS138 All the 24 devices/electrical appli- Note. Please refer device datasheets for more details. (IC4) covering address ances are considered as 24 bits (three SEPTEMBER 2006 WWW.EFYMAG.COM CMYK CONSTRUCTION The relay-switching TABLE III TABLE V data that is output Remote Address Codes Memory Map of DS12887 from ports A, B and C Address Device/Equipment of the PPI is stored as Decimal Memory Location Data description Pointer 0 TV1 consecutive bits at 0 0000 Seconds Memory used 1 TV2 00EH, 00FH and 010H by Clock 2 Videotext locations of the RAM. 1 0001 Seconds Alarm 3 Expansion for TV1 and TV2 2 0002 Minutes The relay/device pro- 4 Laser video player 3 0003 Minutes Alarm gramming timing data 5 VCR1 4 0004 Hours is stored at five con- 6 VCR2 5 0005 Hours Alarm secutive locations for 7 Reserved 6 0006 Day of the Week each device. This data (Sun=1) includes month, date, 8 Sat1 7 0007 Date of the month hour and minute in 27-31 Reserved 8 0008 Month first four bytes, while 9 0009 Year the fifth byte contains 10 000A Register A TABLE IV 5-bit address of the de- 11 000B Register B Remote Command Codes 12 000C Register C vice with MSB indicat- 13 000D Register D ing ‘on’/‘off’ status of Button Command Function (as used) 14 000E Data on Port A 24 bits treated the device. Bits 6 and 7 0–9 0–9 Number keys as 24 devices of this byte are ‘don’t ‘--’ 10 10+ 15 000F Data on Port B care’ bits. Address lo- ‘sfx’ 36 20+ 16 0010 Data on Port C cations 123 through 126 Mute 13 Delete task 17 0011 Month Prog 1 data are used for storing the AC 34 Clear prog memory 18 0012 Date 4-byte long password. PWR 12 Change password 19 0013 Hour Thus only 106 locations Timer 38 Change time 20 0014 Minute are available for stor- 21 0015 Device # (MSB Search 30 Chk existing tasks ing the 5-byte long de- indicates ON/OFF) CH+ 32 See next task 22 0016 Month Prog 2 data vice data and as such CH- 33 See before task 23 0017 Date the program for a RCL 15 Turn on/off LCD 24 0018 Hour maximum of only 21 back light 25 0019 Minute devices out of 24 de- PP 14 Enter new task 26 001A Device # (MSB vices can be stored. Store 41 Enable/disable indicates ON/OFF) The remaining three child lock ….. ….. ….. ….. devices can be ….. ….. ….. ….. switched on/off ….. ….. ….. ….. bytes at locations 200H, 201H and through remote key ….. ….. ….. ….. 202H) of the three ports (ports A, B operation as explained ….. ….. ….. ….. and C) of 8255. The LCD is used for below. 112 0070 Month Prog 20 data displaying real time (year, month, date, 113 0071 Date Bit P1.1 output of day and time in 24-hour mode) ob- 114 0072 Hour IC1 is fed to transistor tained from RTC DS12887 as also some 115 0073 Minute BC547 (T1) through R5. other information during time setting, 116 0074 Device # (MSB Transistor T1 acts like device programming, searching (de- indicates ON/OFF) a switch for LCD back- vice-switching programmed data), 117 0075 Month Prog 21 data light. So you can password entry, etc, as described later. 118 0076 Date switch the backlight of RTC DS12887 is clock-cum-calen- 119 0077 Hour LCD ‘on’/‘off’ just by 120 0078 Minute dar chip with 128 NV RAM (14 bytes setting/resetting the 121 0079 Device # (MSB used for its control registers and 114 P1.1 bit of 89C52. indicates ON/OFF) bytes as general-purpose RAM). It has 122 007A Mem. Location Power supply (Fig. an inbuilt lithium battery and can re- not used Nil 3). While most of the tain stored data for over ten years in 123 007B * Used to store circuit requires regu- the absence of external power. the Password lated 5V for its opera- Memory map of DS12887 is shown 124 007C * tion, the relays and in Table V. Data stored in location 125 007D * Darlington drivers IC7 07FH (decimal 127) indicates the ad- 126 007E * through IC9 127 007F Pointer value dress of the last RAM location used. (ULN2803) are oper- SEPTEMBER 2006 WWW.EFYMAG.COM CMYK CONSTRUCTION (Figs 1 and 3) is shown in Fig. 4 and its component layout in Fig. 5. The con- nections for relays are to be extended from the 16-pin FRC connectors on the PCB. Each connector is meant for ex- tending connections to eight relays. The author’s prototype is shown in Fig. 6. Remote key operations Refer Table IV for details of remote buttons/keys. The functions of these keys follow: Keys ‘0’ through ‘9’, ‘--’ and ‘sfx’. Used to switch on/off the 24 devices manually. Each time you press any of these buttons, the status of the corre- sponding device will toggle, i.e., its output will be the complement of the previous state. Button ‘--’ is used as ‘10+’ button. When it is pressed, the system waits ated with unregulated 12V DC sup- directly fed to all the relays and for around three seconds before the ply. A step-down transformer rated at ULN2803 ICs. The same output is used next button (which should be between 15V AC secondary voltage at 500 mA for regulation by 7805 (IC10). The ‘0’ and ‘9’ to determine the device be- is used to supply 12V unregulated and ripple in the regulator output is fil- tween ‘10’ and ‘19’) is pressed. Simi- 5V regulated power to the circuit. The tered by capacitor C11. larly, ‘sfx’ is used as ‘20+’ key. The secondary output is rectified by 1A An actual-size, single-side PCB for button following the ‘sfx’ button rated bridge rectifier BR1 and the remotely-programmable RTC-inter- should be between ‘0’ and ‘3’ (as the smoothed by 1000μF, 35V capacitor faced microcontroller for multiple de- project supports only 24 electrical ap- C10. The output from the capacitor is vice control and power supply circuits pliances numbering ‘0’ through ‘23’). SEPTEMBER 2006 WWW.EFYMAG.COM CMYK CONSTRUCTION ing the program memory empty: Example $MOD52 Program memory in DS12887 ORG 00H JMP MAIN Task 1 Task 2 Task 3 … … Task ‘n–1’ Task ‘n’ ORG 20H When Task 2 is deleted, the whole memory is refreshed as: MAIN: MOV DPTR, #000AH MOVX A, @DPTR Task 1 Task 3 … … Task ‘n–1’ replaces Task ‘n’ replaces Empty ANL A, #0A0H task ‘n–2’ task ‘n–1’ MOVX @DPTR, A MOV DPTR, #007FH MOV A, #0011H RCL. Turns the LCD backlight flash on the LCD. MOVX @DPTR, A ‘on’/‘off.’ If the memory is not full, a new MOV MOV A, DPTR, #00H #007BH PWR. Used to change the 4-digit device program is accepted by display- MOVX @DPTR, A password (initial value ‘0000’). When ing a message in the first line of the INC DPTR MOVX @DPTR, A you press this button, the system will LCD as ‘Mn Dt Hr:Mn Dv S’ and a INC DPTR ask for the existing password. If the blinking cursor will appear on the sec- MOVX @DPTR, A correct password is entered, it will ask ond line to take the data. ‘Mn’ indi- INC MOVX DPTR @DPTR, A for the new password. If a wrong pass- cates ‘month’ (‘01’ to ‘12’), ‘Dt’ indi- JMP $ word is entered, ‘invalid’ message will cates ‘date’ (‘01’ to ‘31’), ‘Hr’ indicates END flash on the LCD. ‘hours’ (‘00’ to ‘23’), ‘Mn’ indicates Before getting started, you need to Note that the password can be any ‘minutes’ (‘00’ to ‘59’), ‘Dv’ indicates make this program run for the first 4-digit value, which need not be the ‘device number’ (‘00’ to ‘23’) and ‘S’ time after all the components and ICs numbers from ‘0000’ to ‘9999.’ Other stands for ‘programmed status’ (‘1’ for are inserted into the circuit. That is, to buttons representing various codes are ‘on’ or ‘0’ for ‘off’). Enter the desired make DS12887 work, burn the pro- also accepted. data in this format, which will get gram shown above in microcontroller Timer. Used to change the real stored in the NV RAM of the RTC. If 89C52, put the programmed time. As the circuit operations depend month (Mn) is entered as ‘00,’ the same microcontroller in the circuit, switch on the real (set) time, changing the task will repeat every month on the on the circuit for five seconds and then same is password-protected. A valid same date and time. If date (Dt) is en- turn it off. By doing so, the internal 4-digit password will let you tered as ‘00,’ the same task will repeat oscillator of DS12887 starts oscillating change/set the time. When you every day on the same time. and IC DS12887 is now ready for use. press ‘timer’ button, the top row Search. Shows the existing device Now, remove 89C52 from the circuit on the LCD defines the format programs that are stored in the memory and load into it the main program to ‘Hr:Mn:ScWkDyMnYr.’ You need to starting from location 011H onwards make the circuit work with all the fea- enter the valid data as follows: one by one. Each time, you need to tures. (For more details on DS12887 Hr: 00 to 23 (24-hour mode) press CH+/CH- button to move for- RTC, refer to the datasheets.) Mn: 00 to 59 minutes ward/backward. In this mode, you may The monitor program in 89C52 gets Sc: 00 to 59 seconds delete the displayed device program the relevant time data (time, date, day, Wk: 01 to 07 (01 is Sunday) data entry simply by pressing ‘Mute’ year, etc) from DS12887 RTC and dis- Dy: 01 to 31 dates button. Then the program that is resid- plays it on the LCD. The data is also Mn: 01 to 12 (01 is January) ing next to this task moves to the loca- compared against the user-entered Yr: 00 to 99 (year) tion of the deleted task and the whole data (programmed timing data for Any value out of the range will not memory is refreshed. multiple devices), which had been be accepted and message ‘invalid See the example shown above for stored in the NV RAM of DS12887. value’ will be displayed on the LCD. clarity. The pointer value in memory When the timing data that was stored Store. Enables/disables the child location 007FH of DS12887 changes in the NV RAM equals the real-time lock function. You can lock the remote accordingly. data fetched from the DS12887, it sets/ keypad by enabling the child lock. AC. Deletes the entire programmed resets the MSB of the fifth byte of the When you press this button, the sys- data in one stroke. So use this key very stored program for that device. tem will prompt the message ‘Lock?’ cautiously. The main software program or ‘UnLock?’ depending on the present ‘proj.asm’ for the project is given in status of the child lock. If ‘1’ is pressed, RTC initialisation the EFY-CD of this month. Before the child lock feature is enabled/dis- When DS12887 is shipped from the fac- burning the code for main program abled. Any button other than ‘1’ will tory, the oscillator is in disabled state. ‘proj.asm’ into AT89C52, erase the be treated as zero. The following program will make initialisation program ‘rtcint.asm’ that PP. Takes you to programming of DS12887 work and also reset the pass- is programmed initially into it. a task. word to ‘0000’ and make the program EFY note. The software and data If the NV RAM is full in DS12887, pointer to point to the location 0011H, files required for the project are in- the message ‘prog memory full’ will i.e., it clears the existing tasks by mak- cluded in this month’s EFY-CD. SEPTEMBER 2006 WWW.EFYMAG.COM CMYK