Real Time Clock/Calendar with Remote Control – CCS C

Remote Controlled Real Time Clock/Calendar with PIC12F1822 and DS1307

It is good idea to build a simple and low cost DIY remote controlled real time clock/calendar using simple components. This post show how to make a remote controlled real time clock using PIC12F1822 microcontroller, DS1307 RTC chip, NEC IR remote control and all data are displayed on 1602 LCD.
The DS1307 is an 8-pin integrated circuit uses I2C communication protocol to communicate with master device which is in our case PIC12F1822 microcontroller. This small chip can count seconds, minutes, hours, day, date, month and year with leap-year up to year 2100.

The DS1307 receives and transfers data (clock data and calendar data) as BCD format, so after receiving data we have to convert these data into decimal data, and before writing data to the DS1307 we have to convert this data from decimal to BCD format. For example we have the BCD number 33, converting this number into decimal gives 21.

PIC12F1822 microcontroller has an I2C hardware module which can work as master device. The I2C bus specifies two signal connections:
Serial Clock (SCL) (pin RA1)
Serial Data (SDA) (pin RA2)

The time and calendar are displayed on 1602 LCD display. This LCD is interfaced with the microcontroller using 74HC595 shift register as what was done in this post:
Interfacing PIC12F1822 microcontroller with LCD display

The IR remote control used in this project uses NEC communication protocol. The following post shows how this protocol works and how to decode its data with PIC12F1822:
Extended NEC Protocol Decoder Using PIC12F1822 Microcontroller

An image of the remote control used in this project with used buttons data is shown below. Only 3 buttons are used in this project and the rest of buttons have no effect on the circuit.

Car MP3 remote control

Components List:

  • PIC12F1822 Microcontroller
  • NEC Protocol IR Remote Control (Example: Car MP3)
  • DS1307 RTC
  • 1602 LCD
  • 74HC595 Shift Register
  • IR Receiver
  • 47µF Capacitor
  • 32.768 Crystal
  • 3V Lithium Coin Cell Battery
  • 10K Variable Resistor
  • 3 x 10K Resistor
  • +5V Power Supply
  • Protoboard
  • Jumper Wires

Remote controlled real time clock using PIC12F1822 and DS1307 circuit:

Remote controlled real time clock circuit

For this project internal oscillator of the microcontroller is used and MCLR pin is configured to work as a digital input pin.
The IR receiver has 3 pins: GND, VCC (+5V) and OUT. The OUT pin is connected to RA3 pin of PIC12F1822. The IR receiver is used to receive IR signals comes from the remote control and sends data to the microcontroller.
DS1307 RTC has 8 pins and only pin 7 is not used. The DS1307 RTC needs an external crystal oscillator of 32.768KHz which is connected between pins 1 & 2. A 3V coin cell Lithium battery is connected between pin 3 (VBAT) and GND. This battery is used as a backup power supply for the DS1307 whenever the main power fails, it keeps the time running without any problem. DS1307 is connected to microcontroller via two lines SCL and SDA. A pull-ups resistors must be added to the two lines because both are open drain.
The 1602 LCD display pins are connected to 74HC595 shift register except the Enable pin (E) which is connected directly to PIC12F1822. With the help of the shift register 74HC595 the LCD uses only 3 data lines: clock, data and Enable. Other types of serial-in parallel-out shift registers can be used such as 74HC164 and CD4094 (74HC4094).

Remote controlled real time clock using PIC12F1822 and DS1307 C code:
PIC12F1822 internal oscillator is used in this project at 8MHz and by enabling PLL we get a frequency of 32MHz (8 x 4).
Timer1 is configured to increment by 1 every 1us. It is used to measure IR signals spaces and pulses.
RA3 Pin interrupt is used to interrupt when the IR receiver receives an IR signal. So when the IR receiver receives a signal the output of the IR receives goes from high to low which causes the microcontroller to interrupt and starts decoding the received IR signal. Enabling RA3 interrupt is done using the following two lines:
enable_interrupts(GLOBAL);
enable_interrupts(INT_RA3_H2L);
Complete CCS C code is below, it was tested with version 5.051.

Real Time Clock/Calendar with Remote Control Video:
Project hardware circuit.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.