This project based on Atmel AT89C52 and Dallas real-time-clock (RTC) chip DS12887 can be used to control and remotely program the switching operation of 24 electrically operated devices. The devices can be switched on/off at precise times repeatedly every day, every month. The microcontroller can be programmed for device control using a normal Philips TV remote control.
Since the circuit makes use of Philips TV remote for device-switching time parameters, you need to know the fundamentals of the coding format used in these IR remotes.
The Philips IR format makes use of RC5 code, which is also known as ‘bi-phase coding.’ In RC5-coded signals (Fig. 2), each bit has a uniform duration. A transition in the middle of the time interval assigned to each bit encodes its logical value (‘0’ or ‘1’). A high-to-low transition assigns the bit a logic value of ‘0,’ and a low-to-high transition assigns the bit a logic value of ‘1.’ We need additional transitions at the beginning of each bit if a stream of equal bits is sent. However, there is no need of additional transitions if the next bit has a different logic value.
Table II shows how all the commands of an RC5 remote control are encoded.
The first two bits are ‘start’ bits, which are used to adjust and synchronise the receiver. These bits are used to calculate and analyse the bit length of the other bits.
The third bit is a ‘toggle’ bit, which is toggled every time a button is pressed at the remote control. This bit is used to identify whether the button is really pressed or whether an obstacle came in between the IR path of the remote and the IR receiver.
The five bits (A4 through A0) immediately following the toggle bit are used to identify the device (see Table III). So, a maximum of 32 devices can be identified to and respond individually to the same type of coding without any disturbance, i.e., one among the 64 devices can be identified uniquely. Addresses of some of the remotes are shown in Table III.
The six bits (C5 through C0) immediately following the five address bits are the control/command bits. Therefore a maximum of 64 commands can be equipped in an RC5-type remote. Some of the command codes (decimal equivalents), as used in this project, are shown in Table IV.
When any of the command/control buttons on the remote is pressed, the coded signal is received by the IR receiver-demodulator TSOP1738. The output of the IR demodulator circuit is normally high, but when any of the buttons in the remote is pressed, a stream of low going demodulated pulses will appear at its output. These pulses are fed to the external active-low interrupt input pin () of 89C52. On receipt of the first low-going pulse, the monitor program of 89C52 will get interrupted and jump to the location ‘0003H,’ where the execution is redirected to ‘receive’ sub-routine of the program.
The outputs from the sub-routine are:
- Toggle bit, which toggles (either ‘0’ or ‘1’) each time the button in a remote is pressed.
- Address byte, whose value is zero for a normal Philips-type TV remote control (see Table III).
- Control byte, which has a unique value for each button in the remote control (see Table IV).
Click to rotate Fig. 1
Microcontroller AT89C52 is interfaced to DS12887 (RTC), a 16×2 LCD module and an 8255 programmable peripheral interface (PPI). The address-decoding circuitry comprises NAND gates 74LS00 and 3-to-8 line decoder 74LS138 as shown in Fig. 1. The interfacing circuitry for the external electrical appliances comprises Darlington array IC ULN2803. The addressing range of various peripheral devices is shown in Table I.
In 89C52 (IC1), port P0 is used for outputing multiplexed address (lower 8-bit) and data. The address is latched into 74LS573 (IC2) octal latch and RTC DS12887 (IC3) with the help of ALE (address latch-enable) output from pin 30 of IC1.
Only two address lines from IC2 (A0 and A1) have been used for addressing the four registers of 8255 PPI (IC6) in conjunction with the chip select signal at pin 6 (from IC4) and read/write signals from IC1. Higher address bits from port P2 of IC1 (A8, A9 and A10 from output pins P2.0, P2.1 and P2.2) are used for generating the chip-select signals from 74LS138 (IC4) covering address ranges 000H- 0FFH, 100H-1FF and 200-2FF for RTC, LCD module and PPI chip, respectively.
Quad NAND gate 7400 (IC5) in conjunction with read and write signals from IC1 and chip-select signal from pin 14 of IC4 is used for selecting the LCD module both during read and write cycles of IC1.
PPI chip 8255 is configured with port A, port B and port C as output ports for controlling up to 24 electrical appliances via relays RL1 through RL24. Relays are energised through high-current octal Darlington arrays inside ULN2803 (IC7 through IC9) in accordance with programmed data stored in the non-volatile RAM (NV RAM) of RTC chip DS12887. There is no need of connecting external freewheeling diodes across relays as inbuilt diodes are provided in ULN2803 ICs.
All the 24 devices/electrical appliances are considered as 24 bits (three bytes at locations 200H, 201H and 202H) of the three ports (ports A, B and C) of 8255. The LCD is used for displaying real time (year, month, date, day and time in 24-hour mode) obtained from RTC DS12887 as also some other information during time setting, device programming, searching (device-switching programmed data), password entry, etc, as described later.
RTC DS12887 is clock-cum-calendar chip with 128 NV RAM (14 bytes used for its control registers and 114 bytes as general-purpose RAM). It has an inbuilt lithium battery and can retain stored data for over ten years in the absence of external power.
Memory map of DS12887 is shown in Table V. Data stored in location 07FH (decimal 127) indicates the address of the last RAM location used. The relay-switching data that is output from ports A, B and C of the PPI is stored as consecutive bits at 00EH, 00FH and 010H locations of the RAM. The relay/device programming timing data is stored at five consecutive locations for each device. This data includes month, date, hour and minute in first four bytes, while the fifth byte contains 5-bit address of the device with MSB indicating ‘on’/‘off ’ status of the device. Bits 6 and 7 of this byte are ‘don’t care’ bits. Address locations 123 through 126 are used for storing the 4-byte long password. Thus only 106 locations are available for storing the 5-byte long device data and as such the program for a maximum of only 21 devices out of 24 devices can be stored. The remaining three devices can be switched on/off through remote key operation as explained below.
Bit P1.1 output of IC1 is fed to transistor BC547 (T1) through R5. Transistor T1 acts like a switch for LCD backlight. So you can switch the backlight of LCD ‘on’/‘off ’ just by setting/resetting the P1.1 bit of 89C52.
Power supply (Fig. 3). While most of the circuit requires regulated 5V for its operation, the relays and Darlington drivers IC7 through IC9 (ULN2803) are operated with unregulated 12V DC supply. A step-down transformer rated at 15V AC secondary voltage at 500 mA is used to supply 12V unregulated and 5V regulated power to the circuit. The secondary output is rectified by 1A rated bridge rectifier BR1 and smoothed by 1000μF, 35V capacitor C10. The output from the capacitor is directly fed to all the relays and ULN2803 ICs. The same output is used for regulation by 7805 (IC10). The ripple in the regulator output is filtered by capacitor C11.
An actual-size, single-side PCB for the remotely-programmable RTC interfaced microcontroller for multiple device control and power supply circuits (Figs 1 and 3) is shown in Fig. 4 (View as PDF) and its component layout in Fig. 5 (View as PDF). The connections for relays are to be extended from the 16-pin FRC connectors on the PCB. Each connector is meant for extending connections to eight relays.
Download PCB layout PDF: click here
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 corresponding 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 for around three seconds before the next button (which should be between ‘0’ and ‘9’ to determine the device between ‘10’ and ‘19’) is pressed. Similarly, ‘sfx’ is used as ‘20+’ key. The button following the ‘sfx’ button should be between ‘0’ and ‘3’ (as the project supports only 24 electrical appliances numbering ‘0’ through ‘23’).
RCL. Turns the LCD backlight ‘on’/‘off.’
PWR. Used to change the 4-digit password (initial value ‘0000’). When you press this button, the system will ask for the existing password. If the correct password is entered, it will ask for the new password. If a wrong password is entered, ‘invalid’ message will flash on the LCD.
Note that the password can be any 4-digit value, which need not be the numbers from ‘0000’ to ‘9999.’ Other buttons representing various codes are also accepted.
Timer. Used to change the real time. As the circuit operations depend on the real (set) time, changing the same is password-protected. A valid 4-digit password will let you change/ set the time. When you press ‘timer’ button, the top row on the LCD defines the format ‘Hr:Mn:ScWkDyMnYr.’ You need to enter the valid data as follows:
Hr: 00 to 23 (24-hour mode)
Mn: 00 to 59 minutes
Sc: 00 to 59 seconds
Wk: 01 to 07 (01 is Sunday)
Dy: 01 to 31 dates
Mn: 01 to 12 (01 is January)
Yr: 00 to 99 (year)
Any value out of the range will not be accepted and message ‘invalid value’ will be displayed on the LCD.
Store. Enables/disables the child lock function. You can lock the remote keypad by enabling the child lock. When you press this button, the system will prompt the message ‘Lock?’ or ‘UnLock?’ depending on the present status of the child lock. If ‘1’ is pressed, the child lock feature is enabled/disabled. Any button other than ‘1’ will be treated as zero.
PP. Takes you to programming of a task. If the NV RAM is full in DS12887, the message ‘prog memory full’ will flash on the LCD. If the memory is not full, a new device program is accepted by displaying a message in the first line of the LCD as ‘Mn Dt Hr:Mn Dv S’ and a blinking cursor will appear on the second line to take the data. ‘Mn’ indicates ‘month’ (‘01’ to ‘12’), ‘Dt’ indicates ‘date’ (‘01’ to ‘31’), ‘Hr’ indicates ‘hours’ (‘00’ to ‘23’), ‘Mn’ indicates ‘minutes’ (‘00’ to ‘59’), ‘Dv’ indicates ‘device number’ (‘00’ to ‘23’) and ‘S’ stands for ‘programmed status’ (‘1’ for ‘on’ or ‘0’ for ‘off ’). Enter the desired data in this format, which will get stored in the NV RAM of the RTC. If month (Mn) is entered
as ‘00,’ the same task will repeat every month on the same date and time. If date (Dt) is entered as ‘00,’ the same task will repeat every day on the same time.
Search. Shows the existing device programs that are stored in the memory starting from location 011H onwards one by one. Each time, you need to press CH+/CH- button to move forward/backward. In this mode, you may delete the displayed device program data entry simply by pressing ‘Mute’ button. Then the program that is residing next to this task moves to the location of the deleted task and the whole memory is refreshed.
See the example shown above for clarity. The pointer value in memory location 007FH of DS12887 changes accordingly.
AC. Deletes the entire programmed data in one stroke. So use this key very cautiously.
When DS12887 is shipped from the factory, the oscillator is in disabled state. The following program will make DS12887 work and also reset the password to ‘0000’ and make the program pointer to point to the location 0011H, i.e., it clears the existing tasks by making the program memory empty:
Before getting started, you need to make this program run for the first time after all the components and ICs are inserted into the circuit. That is, to make DS12887 work, burn the program shown above in microcontroller 89C52, put the programmed microcontroller in the circuit, switch on the circuit for five seconds and then turn it off. By doing so, the internal oscillator of DS12887 starts oscillating and IC DS12887 is now ready for use. Now, remove 89C52 from the circuit and load into it the main program to make the circuit work with all the features. (For more details on DS12887 RTC, refer to the datasheets.)
The monitor program in 89C52 gets the relevant time data (time, date, day, year, etc) from DS12887 RTC and displays it on the LCD. The data is also compared against the user-entered data (programmed timing data for multiple devices), which had been stored in the NV RAM of DS12887. When the timing data that was stored in the NV RAM equals the real-time data fetched from the DS12887, it sets/resets the MSB of the fifth byte of the stored program for that device. stored program for that device.
The main software program is named ‘proj.asm’. Before burning the code for main program ‘proj.asm’ into AT89C52, erase the initialisation program ‘rtcint.asm’ that is programmed initially into it.
Download source code: click here