Вы находитесь на странице: 1из 6

CONSTRUCTION

REMOTE-CONTROLLED
REAL-TIME CLOCK WITH SUNIL K
UMAR

DEVICE CONTROLLER
D.S. OBEROI AND HARINDER 32 devices can be interro-
DHINGRA gated to respond individu-
ally to the same type of cod-

T
his project makes use of a TV ing without any disturbance.
remote control. Using RC5 cod- Bits C5 down to C0 are
ing, a real-time clock chip is set control/command bits.
to control five different alarm settings. Therefore a maximum of 64
These settings can also be used to switch commands can be equipped
on an external device. Up to eight de- in an RC5 type remote. Deci-
vices can be controlled with this project. mal equivalent of a few com-
The circuit is based on ATMEL mand codes used in this
ATmega16 microcontroller and project are listed at Table II.
Maxim’s DS1307 real-time clock chip. Fig. 1: Block diagram of remote-controlled real-time clock Pressing any command/
An LCD module allows for user inter- with device controller control button on the remote
face. generates code signal,
TABLE I which is received by
Circuit description IR receiver-demodu-
Fig. 1 shows the block diagram of the
RC5 Coding Format lator (TSOP1738). The
remote-controlled real-time clock with S S T A4 A3 A2 A1 A0 C5 C4 C3 C2 C1 C0 output of the IR de-
device controller. It comprises six sec-
tions, namely, IR detector remote con-
trol sensing and decoding unit, real- TABLE II
time clock, LCD interface, device Remote Command Codes
switching unit, microcontroller and Remote key Numeric value Function
power supply unit (C5-C0)
The microcontroller unit integrates 0 0 Press this key to start the setting of the RTC.
all the sub-systems and system soft- Volume + 16 Increases the value (of a given field). Used in ‘Alarm Delete Mode’
ware operates the system. Fig. 2 shows to change the selection to Yes or No
the circuit of the device controller. Volume – 17 Decreases the value (of a given field). Used in ‘Alarm Delete Mode’
Remote control section. This circuit to change the selection to Yes or No
makes use of a Philips TV remote for Mute 13 Shifts to next field (in RTC setting mode)
device switching and RTC parameter TV/AV 56 Starts the RTC functioning. This remote control key acts as ‘Enter’ key
setting. It uses RC5 coding format, (confirmation key). Used in alarm mode, to confirm the setting
which is also known as ‘biphase cod- Power 12 Returns to Display Mode (from alarm mode).This key lets the user to
ing.’ In RC5-coded signal, each bit has return to the previous menu; when used in any of the Alarm Menu,
acts as ‘Escape’ key and cancels the action in Alarm mode
a uniform duration.
Table I shows how all the com- Timer/sleep 38 Enters Alarm menu for setting/deletion/viewing alarm data.
mands of RC5 remote control are en- Channel + 32 Scrolls forward alarm setting ‘See’ of Alarm menu
coded. The first two bits designated Channel – 33 Scrolls backward alarm setting ‘See’ of Alarm menu
‘S’ are ‘start’ bits, which are used to
adjust and synchronise the receiver. is used to identify whether the button modulator is normally high, which
These bits are used to calculate and is really pressed or whether an obstacle changes to low when any of the but-
analyse the bit length of other bits. came in between the path of the IR tons on the remote is pressed. It is fed
The third bit is a ‘toggle’ bit (T), remote and IR receiver. to PD3 through the I/O interface line
which toggles every time a button is Bits A4 down to A0 are used to of the microcontroller. The
pressed at the remote control. This bit identify the device. So a maximum of microcontroller decodes the incoming

60 • APRIL 2007 • ELECTRONICS FOR YOU WWW.EFYMAG.COM


CONSTRUCTION
RC5 data stream and subsequent ac- microcontroller. Register-select (RS) microcontroller with the help of tran-
tions are taken based on the this infor- pin 4 and enable pin (pin 6) of the LCD sistor T1. All the information is dis-
mation. are interfaced with PC1 and PC2 of played on the LCD, which forms the
LCD unit. The LCD module (16- the microcontroller, respectively. R/W basic user interface unit.
character×2-line) is interfaced with the pin of the LCD (pin 5) is pulled low Real-time clock. IC DS1307 (IC2)
microcontroller. Data pins 7 through permanently and thus is always in from Maxim (Dallas Semiconductor) is
14 of the LCD module are connected writing mode. Back light of the LCD a serial RTC chip with calendar func-
to port A (PA0 through PA7) of the is controlled by PD0 line of the tion. This chip also incorporates 56
bytes of NV RAM. Data
and address are trans-
ferred serially through
I 2 C bidirectional bus,
which obviates the need
for a large number of in-
terface lines. The bidirec-
tional data is read and
written with the help of
just two I/O interface
lines.
In this chip, the clock
operates in either 24- or
12-hour format with
AM/PM indicator. In cal-
endar mode, end of the
month is automatically
adjusted for the months
with less than 31 days
and leap year compensa-
tion is valid up to year
2100.
The memory map of
DS1307 (also referred to
as ‘time keeper register
map’) is shown in Table
III. For setting the clock
and calendar at power-
’on,’ the data is first writ-
Fig. 2: Circuit of remote-controlled real-time clock with device controller

ten to the designated


memory location of the
RTC chip and, during the
normal operation. It is
read back from each spe-
cific memory location
during the clock and cal-
endar display functions.
The alarm settings are
stored in NV RAM; these
can be deleted and al-
tered at any given point
of the operation. All this
is achieved with the help
of the system software. In
the project, only five
alarms have been al-
lowed but the same can
be changed as per re-
quirement; only the

62 • APRIL 2007 • ELECTRONICS FOR YOU WWW.EFYMAG.COM


CONSTRUCTION
alarm limits have to be changed.
TABLE III
Clock pulse to the RTC is provided
by a 32.768kHz crystal. As per the con-
Memory Map of DS1307
vention of I2C interface communica- Address Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Function Range
tion, the device address while writing 00H CH 10 seconds Seconds Seconds 00-59
into DS1307 chip is 0xD0 (in binary 01H 0 10 minutes Minutes Minutes 00-59
format 11010000) and while reading 02H 0 12 10 hour 10 hour Hours Hours 1-12
the data from DS1307 the device ad- 24 PM/AM +AM/PM
dress is 0xD1 (in binary format 00-23
11010001). Due to this unique device 03H 0 0 0 0 0 Day Day 01 07
addressing technique, a number of I2C- 04H 0 0 10 date Date Date 01 31
interfaced chips can be attached on 05H 0 0 0 10 month Month Month 01-12
SCL and SDA interface lines of RTC. 06H 10 year Year Year 00-99
Thus, at a given time, only one I2C de- 07H Out 0 0 SQWE 0 0 RS1 RS0 Control –
vice will respond to the data on the I/
08H RAM 00H-FFH
O interface lines. 56×8
Device control. Devices are con- 0 – Always reads back as 0
nected to contacts of the relay and re-
lays are controlled through the outputs
of IC4. Port B of IC1 (PB0 through PB7)
is interfaced with pin 8 down to pin 1
of IC4 (ULN2803) to control relays RL1
through RL8, respectively. Five out of
eight devices (device 1 through 5)
switch on with their respective alarm
settings and the remaining three de-
vices switch on directly.
Whenever an alarm is activated for
a particular setting, the respective de-
Fig. 3: Power supply
PARTS LIST
Semicondutors: vice is switched on. The device can be the use of any specialised hardware
IC1 - Atmega16 AVR
microcontroller switched off only by pressing the re- functionality of the microcontroller;
IC2 - DS1307 real time clock spective key number on the remote and also help the user to implement
IC3 - TSOP1738 IR receiver
module
control. the same on any other microcontroller
IC4 - ULN2803 darlinton array Controller. The controller unit is that does not have the dedicated facil-
IC5 - 7805 5V regulator based on ATmega16 low-power, 8-bit ity of I2C interface.
IC6 - 78012 12V regulator
T1, T2 - SL100 npn transistor CMOS microcontroller with AVR en- This controller unit first uses serial
BR1 - 1A bridge rectifier hanced RISC architecture. This data received from the IR detector to
- LCD module (16×2) microcontroller has 16 kB of in-system get the information regarding the
Resistors (all ¼-watt, ±5% carbon): programmable flash memory, 512 bytes pressed key and then takes the appro-
R1, R3, R4,
R6, R10 - 10 kilo-ohm on EEPROM, 1 kB of SRAM, two 8-bit priate action, and also updates the in-
R2 - 220 ohm timers, one 16-bit timer, 32 general-pur- formation on the LCD side-by-side.
R5,R9 - 120 ohm pose I/O lines and 32 general-purpose When in operational mode, the
R7, R11 - 2.2 kilo-ohm
R8 - 330 ohm working registers. It integrates all the microcontroller reads the data from the
VR1 - 10 kilo-ohm preset subsystems to form a complete unit. RTC chip every one second (achieved
Capacitors: Although this microcontroller al- through timer interrupts-compare
C1, C2 - 10µF,16V electrolytic ready has an RTC counter and I2C mode). During this 1-second interrupt,
C3, C7, C8 - 0.1µF ceramic disk
C4 - 100µF,25V electrolytic lines, we have used a separate RTC it checks for the alarm setting, controls
C5 - 1µF,16V electrolytic chip and special I 2 C software to the snooze, and also updates the time/
C6 - 1000µF,35V electrolytic
show the functionality with the dedi- date information on the LCD. In be-
Miscellaneous:
X1 - 230V AC primary to 15V,
cated RTC chip, which is much easier tween, it checks the data from the IR
500mA secondary trans- to control and manage in terms of time detector and takes action accordingly.
former keeping as well as achieving calendar Power supply. Fig. 3 shows the
S1 - Push-to-on switch
PZ1 - Piezo buzzer functions. Regarding I2C, we wanted power supply circuit. The 230V, 50Hz
XTAL - 32.768 KHz crystal to show how the same can be achieved AC mains power supply is stepped
RL1-RL8 - 12V, 1C/O relay with the help of the software without down by transformer X1 to deliver a

WWW.EFYMAG.COM ELECTRONICS FOR YOU • APRIL 2007 • 63


CONSTRUCTION
secondary output of 15V at 500 mA. now been allocated to an array, is
TABLE IV
The transformer output is rectified by a checked and the desired action is taken
full-wave bridge rectifier BR1, filtered
Software Files and when the alarm setting data matches
by capacitor C6, and regulated by IC5 Their Function the current time.
and IC6. IC5 and IC6 output is 5V and File Name Function i2cmaster.S and i2cmaster.h. These
12V, respectively. The regulated 12V is .rclock.c Main file which integrates all the files are related to control of the I2C
used for relay-driver IC4 and the rest functions of the sub-units of the interface communication. The details
of the circuit operates with 5V. Capaci- project of the SCL and SDA pins and I/O in-
tors C7 and C8 bypass any ripple ds1307.c Contains the code for the terface line are defined in the
present in the regulated power supply. controlling the functions of i2cmaster.s file and the Assembly code
An actual-size, single-side PCB pat- DS1307 RTC file is compiled along with other code
tern for the remote-controlled real-time .lcd.c Contains the code for controlling files; the parameter to be used in
the LCD
clock with device controller (Fig. 2 and ‘makefile’ for this file is ASRC.
Fig. 3) is shown in Fig. 8 and its compo- .lcd.h Contains the global declarations lcd.c This file contains the code for
and sub-routines, which are used
nent layout in Fig. 9. by other files control of functioning of the attached
LCD module. The code controls the
Software .i2cmaster.h Contains sub-routine information
required for I2C communication initialisation of the LCD, data writing
The system software is used to achieve .i2cmaster.S Contains code for controlling the on the LCD, and also the movement,
integration and functionality. The soft- I2C communication (optimised for characteristics and location of the cur-
ware for this project is written in ‘C’ 4.00 MHz operation) sor. It offers the facility to write data
language and compiled using on the LCD character-by-character or
WINAVR. WINAVR is available free which has been written for 4.00MHz string-wise. The command set used in
of cost for Windows and Linux operat- operation, and for this reason, the the software is based on the command
ing systems. It is capable of handling microcontroller’s fuses have been set set used in the LCD based on Hitachi
all the AVR functionalities like UART, to use the internal 4.00MHz clock. HD44780 ICs.
timer, ADC, interrupts, etc and offers The data stored in the RTC chip is lcd.h This header file contains all
the facility of writing the program in in BCD format. The BCD data is the constant variable values and names
‘C.’ The finally obtained Intel hex code changed into binary format for nor- of the subroutines used by various files
file was burnt into AVR’s flash memory mal processing and displaying. For this used in the software. It clearly indi-
using a suitable programmer. The purpose, the BCD2bin( ) subroutine is cates which variable can be used as a
microcontroller uses a 4MHz internally used. Similarly, the user data is first global variable and which of the sub-
generated clock. To activate, fuse bytes converted into BCD format with routines can be used across the soft-
have to be programmed as follows: bin2BCD( ) sub-routine and then writ- ware files.
Fuse low byte = D3 ten into the RTC chip. This file con- rclock.c This file contains the code
Fuse high byte = 99 tains all the sub-routines that are used that integrates all the subunits together.
The software for the entire project in rclock.c file modules. It contains the code that will call the
was written in modules in accordance I2C-interfaced chips are initiated in initialisation routines to initialise I2C
with the functionality of each sub- a particular sequence for their proper chip, LCD, microcontroller ports, set
system. The files used in this project functioning, and this has been taken timer and its IRQ, check data from the
are shown in Table IV. care of during initialisation and read- IR detector, extract information regard-
The ds1307.c file contains the code ing/writing data from/to DS1307. ing the key pressed, etc.
for controlling the functions related to The user alarm settings are stored Depending upon the key pressed,
serial DS1307 RTC. The chip uses I2C in the NV RAM of DS1307 in two the file initiates the change in RTC data
interface, which essentially uses only fields, namely, hours and minutes. In like year, month, day, date, hours and
two I/O interface lines—SDA and this project, a maximum of five alarm minutes and also in viewing, deleting
SCL—for bidirectional address and settings have been allowed but this and adding new alarm settings. It takes
data communication. This file essen- number can be increased by changing control of the devices attached to the
tially uses sub-routines, which have the variable MAX_ALARM value (in unit and controls their status depend-
been indicated in the I2Cmaster.h lcd.h file). ing upon the alarm settings.
header file. Subroutines i2c_write( ) and Whenever the alarm setting data is All the above-mentioned functions
i2c_read( ) are used for writing and to be viewed, altered, deleted or are implemented in this file by means
reading the data to and from the RTC added, the program checks the user of specific implementation of sub-rou-
chip through DS1307_write( ) and SRAM area, and based on the value tines and global variables whereever
DS1307_read( ), respectively. stored in the ALARM_COUNT_RGST required.
The Assembly code for the com- memory location, further action is per- All the sub-routines used in the
plete I2C operations and communica- mitted. While clock is functioning, the various files are clearly marked and
tion is written in the I2Cmaster.S file, data from this SRAM area, which has commented for their functionalities

64 • APRIL 2007 • ELECTRONICS FOR YOU WWW.EFYMAG.COM


CONSTRUCTION
with codes explained. Once the desired value of the hour
The entire project software was has been achieved, you can change to
compiled and debugged with minute field by pressing ‘Mute’ key.
WINAVR development environment, The change of field is indicated by cur-
which is based on avr-gcc 3.3.1 sor blinking on the appropriate field
(WinAVR-20030913). (here minute field). Value of minutes
can be changed from ‘0’ to ‘59’ and
Remote control operation Fig. 4: Screen display after switch on again to ‘0.’ Again, after the desired
The entire device operation is con- value has been achieved, the field can
trolled through keys of the Philips re- be changed to week day by pressing
mote control. The remote keys are used ‘Mute’ key. Now week days can be
as shown in Table II. The functions of changed by pressing volume up and
these keys are given below. down keys.
Key 0 is used to change the setting Next field-change data is related to
of the RTC. When the RTC is func- day of the month (the date can be
tioning normally, it can be switched changed from ‘1’ to ‘31’) and after this,
to setting mode by pressing the ‘0’ key Fig. 5: Screen display after pressing ‘Timer’ key the month of the year can be changed
and immediately the cursor will blink (from January to December). The year
on the hour field, indicating that this can be changed from ‘00’ to ‘99’. Take
value can be changed through ‘volume care when setting the month and the
up’ and ‘volume down’ keys to a de- days in that particular month.
sired value. The process remains the same
Keys 1 through 8 are used, during when setting the alarm value also,
normal operation, to control the state where only hour and minute fields are
of the external devices. Key 1 is used available for setting. Once the setting
to control Device 1 and so on. Devices Fig. 6: Delete an alarm setting has been made as per the requirement,
1 through 5 are switched on according TV/AV key can be set and now the
to the alarm timing also; however, clock will start functioning with the
these can be switched off by pressing desired settings. The functioning of the
the respective key on the remote con- clock can be observed by change in
trol itself. the second field.
Keys 1 through 3 are also used in
the Alarm menu. Key 1 is used to add Alarm setting
a new alarm value to the alarm table. As explained earlier, the given design
Key 2 is used to delete the alarm set- Fig. 7: View the alarm setting allows five alarm settings with snooze
ting for the table (by changing Yes/ facility and control of five devices only.
No field with volume up/down key). tioning once the desired settings have You can enter the alarm menu by
Key 3 is used to scroll through the been made. This remote control key pressing ‘Timer’ key. The screen at this
alarm settings by use of channel up acts as ‘Enter’ key (confirmation key). point of operation is shown in Fig. 5.
and down keys. Timer key takes the user to alarm Through this menu, you can set new
Power key is used for deactivating setting menu. alarm (1New), delete alarm setting
the alarm and also returning one setup (2Del) and view alarm settings (3See).
back in the Alarm menu. Whenever Clock mode setting The respective menu can be activated
you want to return from the Alarm’s When the RTC is switched on, the by pressing key 1, 2 or 3. In new setting
sub-menu (like New, Del and See), press screen display is as shown in Fig. 4. mode, if five alarm settings have been
this key. Also, this key is used to return The second field value shows 40 sec- made, the same is indicated by a ‘Full’
from the Alarm menu to display screen. onds. These indicated initial values sign. In case new setting has to be made,
Mute key is used to change the have been set in subroutine an already exisiting alarm setting has
field (from hour to minute to day of i2c_initialisation( ). If some other val- to be deleted and then only new alarm
the week to day of the month to month ues are required, the desired values setting will be allowed.
of the year and, finally, the year and can be written. To return from ‘New’ mode to
back to hour and so on and so forth). The cursor blinking on the hour ‘Alarm’ menu, press ‘Power’ key. If
Volume Up and Down keys are field indicates that value can be space is available for new alarm set-
used to change the value of a given changed through volume up and ting, you can change hour-field data
field when setting the clock data or down key—which will now change the and minute-field data by using ‘Vol-
the alarm data. hour value from ‘0’ to ‘23’ hours and ume Up,’ ‘Volume Down’ and ‘Field’
TV/AV key starts the RTC func- back to ‘0’ again. keys, i.e., ‘Mute’ key. Once the desired

WWW.EFYMAG.COM ELECTRONICS FOR YOU • APRIL 2007 • 65


CONSTRUCTION
will be ‘5,’ and if ‘Data:1’ device 1 is
attatched with this data field.) If no
alarm data is found in the memory,
‘No Alarm Data’ is shown on the LCD.
In ‘New’ and ‘Del’ sub-menus of
‘Alarm’ menu, ‘TV/AV’ key is used to
confirm the desired setting/action. To
cancel settings/actions, press ‘Power’
key at any time of the operation.
By default, all the five alarm set-
tings have been made initially through
the software. These values can be
changed in sub-routine dummy( )
found in the ds1307.c file.
As soon as the alarm is activated,
the LCD backlight glows periodically
along with the buzzer sound. Deacti-
vate the alarm with ‘Power’ key; how-
ever, the respective-controlled device
Fig. 8: Actual-size, single-side PCB for the remote-controlled real-time clock with device controller will continue to be ‘on.’ The alarm can
be put into snooze mode by pressing
any key on the remote control. In snooze
mode, the buzzer will not sound but
LCD backlight will glow. The snooze
delay can be changed by setting the
constant snooze_delay variable (in the
lcd.h file) to a desired value.
No doubt the alarm time can be
set in any sequence; the external device
will switch on in a sorted time
sequence. For example, if the alarm
time is ’01:21' at location-3 and ’01:10'
at location-5, device-5 will switch on
at ’01:10' and device-3 will switch on
only at ’01:21,’ even though in the
alarm sequence the location of device-
3 is before device-5. When the clock is
switched on, all the controlled external
devices are in switched-off condition.
In snooze mode, the alarm can be
Fig. 9: Component layout for the PCB de-activated by pressing ‘Power’ key.
All the external devices can be
settings have been made, pressing the that one alarm setting has been deleted. switched off simultaneously by press-
‘TV/AV’ key stores the alarm settings To view the alarm setting data, you ing S1. This will work only in normal
in the NV RAM of the DS1307 chip. can use key ‘3’ in ‘Alarm’ menu. The functioning of the device and not dur-
To delete an alarm setting, first screen at this point will be as shown ing the alarm mode.
press key ‘2.’ The display will be as in Fig. 7, which indicates the total num- The project was assembled on a
shown in Fig. 6. ber of alarm settings in the memory general-purpose PCB.
The alarm settings/values can be (Tot:) and data being viewed. You can EFY notes. All the software files re-
scrolled with the help of ‘Channel Up’ scroll through the data with the help lated to this article have been included
and ‘Channel Down’ keys. For a set- of Channel Up/Down key. in this month’s EFY-CD. For testing
ting that is to be deleted, change the As you scroll though the data, the the project, you can use the RC5-for-
status of the indicator from ‘No’ to ‘Yes’ field ‘Data:’ indicates the alarm setting mat remote published in EFY March
by ‘Volume Up’ and ‘Volume Down’ as per the programmed sequence. The 2007. 
keys. Then delete data by pressing ‘TV/ device-control field number will be the D.S. Oberoi is principal design engineer at
AV’ key and immediately the message same as ‘Data:’ field number. (If DOEACC Centre, Srinagar/Jammu, and Harinder
‘Deleting Data’ is displayed, indicating ‘Data:5,’ the device to be controlled Dhingra is a lecturer at GCET, Jammu

66 • APRIL 2007 • ELECTRONICS FOR YOU WWW.EFYMAG.COM

Вам также может понравиться