Clock & Timer Circuit Diagrams

Digital Clock Circuit using 8051 and DS12C887

In this project, I will show you how to design a simple Digital Clock Circuit using 8051 and DS12C887 as well as DS1307 RTC Modules.

Outline

  • Introduction
  • Circuit Principle
  • Circuit Diagram Digital Clock Circuit using 8051 and DS12C887
    • Circuit Components
    • Circuit Design
    • DS12C887 Real Time Clock
    • Code
  • Circuit Diagram Digital Clock Circuit using 8051 and DS1307
    • Components Required
    • Code
  • How to Operate?
  • Circuit Applications

Introduction

There are several limitations to GSM, despite its great benefits. This can’t be utilised in applications that require a quick response because it might not work if there aren’t any signals available.

Digital Clock Circuit

The time is displayed on the LCD using the circuit. We can change the time on this clock at any time. The clock may be set to function in either 24 or 12 hour mode, and the RTC chip is programmed using an 8051 controller.

I’ll show two digital clock circuits utilising an 8051 microcontroller: one uses the RTC DS12C887 and the other uses the RTC DS1307.

Circuit Principle

The 8051 controller constantly reads data from Real Time Clock ICs and processes it in the correct order to display the time on the LCD in both circuits.

Circuit Diagram Digital Clock Circuit using 8051 and DS12C887

blank

Circuit Diagram of Digital Clock using RTC DS12C887 and 8051 Microcontroller

Circuit Components

  • 8051 microcontroller
  • Project PCB
  • Programming cable
  • DC Battery or 12V, 1A adaptor
  • DS12C887 RTC IC
  • 16*2 alphanumeric LCD
  • Push buttons – 4
  • Slide switches – 3
  • 2 ceramic capacitors – 33pF
  • 12 MHz crystal
  • Electrolytic capacitor – 10uF, 16V
  • Resistor (1/4 watt) – 10k
  • Pot – 10k
  • 5V DC power supply circuit
  • Single pin connecting wires

Circuit Design

The circuit demonstrates how to connect an RTC IC to an 8051 controller. The data port of the Real Time Clock is Port P0. The data pins of the LCD are connected to the controller’s port P2. The RS, RW, and EN pins are connected to the controller’s pins P1.1, P1.2, and P1.3, respectively. The RESET of the RTC is connected to P1.0. The P1.4 and P1.5 have push buttons connected to them. These are used to keep track of time. P1.6 is set as the START pin, which is used to start the clock with the time selected by the user. The push button used to call the set time function is attached to P3.3.

DS12C887 Real Time Clock

The majority of apps use this IC to deliver accurate time and date. This IC displays the time in both 12 and 24 hour formats. This IC also includes day, month, and year calendar components. When the power goes out, this RTC uses an internal lithium battery to keep the time and date updated. The RAM memory on this IC is 128 bytes. 14 bytes of RAM are used for time, date, and registers in this 128 bytes of RAM. The remaining 114 bytes are utilised to store data for general usage.

Only when power is applied from an external source can the RTC’s control registers be accessed. When external power is connected to this IC, it requires more than 4.25V and the control registers are available after 200ms.

blank
DS12C887 IC

DS12C887 IC

Pin Description

  • MOT: This is a bus type selection pin that allows you to choose between Intel and Motorolabus. To pick Motorola bus type, this pin is linked to VCC, and to select Intel bus type, it is connected to GND or disconnected.
  • 2, 3: Pins that haven’t been used
  • These pins (AD0 – AD7) are RTC’s bidirectional address and data lines. Address is present in the first half of the bus cycle on these pins, and data is present in the second half.
  • This pin is connected to Ground.
  • 12 (GND): This pin is connected to Ground.
  • 13 (CS): To access the chip during read and write operations, this pin must be low.
  • 14 (AS): This pin’s high pulse is utilised to demultiplex data and addresses.
  • 15 (R/W): This pin is used to do reads and writes.
  • 16: Unused pin
  • 17 (DS): This is a Data Strobe pin.
  • 18 (RESET): The low pulse on this pin resets all the flags and interrupts but it does not affects time and date.
  • 19 (IRQ): Thisis active low pin used as an interrupt input to the controller.
  • 20 – 22: Unused pins
  • 23 (SQW): Used to generate square wave with predefined frequencies
  • 24 (VCC): This pin is connected 5V supply

RTC Address Map

With addresses 00H – 07H, this RTC has 128 bytes of RAM. Clock, calendar, and alarm data are stored in the first ten positions (00–09). Status and control registers are located in the 0A – 0D address range. For generic data, the remaining address locations are used. The address locations for the clock, calendar, and alarm are listed in the table below.

blank

Address Locations for Time, Date and Alarm

Register A, register B, register C, and register D are the four control and status registers on this IC. To obtain precise time and date, we must configure all of these registers. The DS12C887 Datasheet can be used to customise these registers.

Code

#include<reg51.h>
#include<absacc.h>
#define dataport P2
#define port P1
#define lcdport P3
sbit reset = port^0;
sbit rs =port^1;
sbit rw =port^2;
sbit e = port^3;
sbit dig_hr1=port^4;
sbit dig_min1=port^5;
sbit start=port^6;
int min1=0,hr1=0;
int min0=60,hr0=25;
unsigned char temp=60,hr,min,sec,num[60]={0x00,0x01,0x02,
0x03,0x04,0x05,0x06,0x07,0x08,0X09,0X10,0X11,0X12,0X13,
0X14,0X15,0X16,0X17,0X18,0X19,0X20,0X21,0X22,0X23,0X24,
0X25,0X26,0X27,0X28,0X29,0X30,0X31,0X32,0X33,0X34,0X35,
0X36,0X37,0X38,0X39,0X40,0X41,0X42,0X43,0X44,0X45,0X46,
0X47,0X48,0X49,0X50,0X51,0X52,0X53,0X54,0X55,0X56,0X57,
0X58,0X59};
void delay(unsigned int msec )
{
int i ,j ;
for(i=0;i<msec;i++)
for(j=0; j<1275; j++);
}
void lcd_cmd(unsigned char item)
{
dataport = item;
rs= 0;
rw=0;
e=1;
delay(1);
e=0;
return;
}
// function to send data
void lcd_data(unsigned char item)
{
dataport = item;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
return;
}
void lcd_string(unsigned char *str)
{
int i=0;
while(str[i]!=’\0′)
{
lcd_data(str[i]);
i++;
delay(1);
}
return;
}
lcd_int(int time_val)
{
int int_amt;
int_amt=time_val/10;
lcd_data(int_amt+48);
int_amt=time_val%10;
lcd_data(int_amt+48);
}
void lcd()
{
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x0C);
delay(5);
lcd_cmd(0x80);
delay(5);
}
void set_rtc_time()
{
XBYTE[10]=0x20;
XBYTE[11]=0x82;
XBYTE[0]=0x00;
XBYTE[2]=min;
XBYTE[4]=hr;
XBYTE[7]=0x01;
XBYTE[8]=0x01;
XBYTE[9]=0x10;
XBYTE[1]=0xFF;
XBYTE[3]=0xFF;
XBYTE[5]=0xFF;
XBYTE[11]=0x22;
}
void set_hr1()
{
hr1++;
if(hr1>23)
hr1=0;
lcd_cmd(0xc3);
lcd_int(hr1);
lcd_data(‘:’);
hr0=hr1;
}
void set_min1()
{
min1++;
if(min1>59)
min1=0;
lcd_cmd(0xc6);
lcd_int(min1);
min0=min1;
}
void set_time() interrupt 2
{
lcd_cmd(0x01);
if(start==0)
{
lcd_string(“SET TIMING”);
lcd_cmd(0xc3);
lcd_int(hr1);
lcd_data(‘:’);
lcd_int(min1);
while(start==0)
{
delay(10);
if(dig_hr1==0)
set_hr1();
if(dig_min1==0)
set_min1();
}
}
lcd_cmd(0x01);
hr=num[hr1];
min=num[min1];
set_rtc_time();
lcd_cmd(0x80);
lcd_string(“TIME:”);
hr0=25;
min0=60;
}
bcdconv(unsigned char mybyte)
{
unsigned char x,y;
x= mybyte & 0x0F;
x=x | 0x30;
y= mybyte & 0xF0;
y=y>>4;
y=y | 0x30;
lcd_data(y);
lcd_data(x);
}
void read_rtc_display()
{
XBYTE[11]=0x02;
hr=XBYTE[4];
lcd_cmd(0x85);
//if(hr!=hr0)
{
bcdconv(hr);
lcd_data(‘:’);
hr0=hr;
}
min=XBYTE[2];
//if(min!=min0)
{
bcdconv(min);
lcd_data(‘:’);
//min0=min;
}
sec=XBYTE[0];
//if(sec!=temp)
{
bcdconv(sec);
//temp=sec;
}
}
void main()
{
reset=1;
lcd();
XBYTE[10]=0x20;
XBYTE[1]=0xFF;
XBYTE[3]=0xFF;
XBYTE[5]=0xFF;
XBYTE[11]=0x02;
lcd_cmd(0x01);
IE=0x84;
lcd_cmd(0x80);
lcd_string(“TIME:”);
while(1)
{
read_rtc_display();
}
}

Circuit Diagram Digital Clock Circuit using 8051 and DS1307

blank

Components Required

  • 8051 Microcontroller
  • 8051 Development Board (Optional)
  • 8051 Programmer
  • DS1307 RTC Module
  • 11.0592MHz Crystal (for 8051)
  • 32.768 KHz Crystal (for DS1307 RTC)
  • Capacitors – 33pF x 2, 10µF
  • Resistors – 1KΩ x 2, 10KΩ x 2, 8 x 1KΩ Pull-up, 10KΩ POT
  • 3V Lithium Battery
  • Push Button
  • 16×2 LCD Display
blank

Code

#include<reg51.h>
#include<string.h>
#define lcd P3
sbit rs=P2^0;
sbit e=P2^1;
sbit c=P0^0;
sbit d=P0^1;
void delay (int);
void cmd (unsigned char);
void display (unsigned char);
void string (char *);
void init (void);
void i2c_start (void);
void i2c_stop (void);
void i2c_write (unsigned char);
unsigned char i2c_read (void);
void i2c_ack (void);
void i2c_noack (void);
void write (unsigned char, unsigned char, unsigned char);
unsigned char read (unsigned char, unsigned char);
void set_time (unsigned char, unsigned char, unsigned char);
int no[10]={48,49,50,51,52,53,54,55,56,57};
unsigned int temp1[3]=0;
void delay (int d)
{
unsigned char i=0;
for(;d>0;d–)
{
for(i=250;i>0;i–);
for(i=248;i>0;i–);
}
}
void cmd (unsigned char c)
{
lcd=c;
rs=0;
e=1;
delay(5);
e=0;
}
void display (unsigned char c)
{
lcd=c;
rs=1;
e=1;
delay(5);
e=0;
}
void string (char *p)
{
while(*p)
{
display(*p++);
}
}
void init (void)
{
cmd(0x38);
cmd(0x0c);
cmd(0x01);
cmd(0x80);
}
void i2c_start (void)
{
c=1;
d=1;
delay(1);
d=0;
delay(1);
}
void i2c_stop (void)
{
c=0;
delay(1);
d=0;
delay(1);
c=1;
delay(1);
d=1;
delay(1);
}
void i2c_write (unsigned char a)
{
char j;
for(j=0;j<8;j++)
{
c=0;
d=(a&0x80>>j)?1:0;
c=1;
}
}
unsigned char i2c_read (void)
{
char j;
unsigned char temp=0;
for(j=0;j<8;j++)
{
c=0;
if(d)
temp=temp|(0x80>>j);
c=1;
}
return temp;
}
void i2c_ack (void)
{
c=0;
delay(1);
d=1;
delay(1);
c=1;
delay(1);
while(d==1);
c=0;
delay(1);
}
void i2c_noack (void)
{
c=0;
delay(1);
d=1;
delay(1);
c=1;
delay(1);
}
void write (unsigned char sa, unsigned char w_addr, unsigned char dat)
{
i2c_start();
i2c_write(sa);
i2c_ack();
i2c_write(w_addr);
i2c_ack();
i2c_write(dat);
i2c_ack();
i2c_stop();
delay(10);
}
unsigned char read (unsigned char sa, unsigned char w_addr)
{
unsigned char buf=0;
i2c_start();
i2c_write(sa);
i2c_ack();
i2c_write(w_addr);
i2c_ack();
i2c_start();
i2c_write(sa|0x01);
i2c_ack();
buf=i2c_read();
i2c_noack();
i2c_stop();
return buf;
}
void set_time (unsigned char hour, unsigned char min, unsigned char sec)
{
unsigned int temp[3];
temp[0]=(((unsigned char)(sec/10))<<4)|((unsigned char)(sec%10));
temp[1]=(((unsigned char)(min/10))<<4)|((unsigned char)(min%10));
temp[2]=(((unsigned char)(hour/10))<<4)|((unsigned char)(hour%10));
write(0xd0,0x00,temp[0]);
write(0xd0,0x01,temp[1]);
write(0xd0,0x02,temp[2]);
}
void main()
{
unsigned char temp=0;
init();
string(” Digital Clock “);
cmd(0xc0);
string(” using 8051 “);
delay(3000);
cmd(0x01);
set_time(12,59,51);
delay(500);
while(1)
{
cmd(0x80);
temp=read(0xd0,0x00);
temp1[0]=((temp&0x7F)>>4)*10 + (temp&0x0F);
temp=read(0xd0,0x01);
temp1[1]=(temp>>4)*10 + (temp&0x0F);
temp=read(0xd0,0x02);
temp1[2]=(temp>>4)*10 + (temp&0x0F);
display(no[(temp1[2]/10)%10]);
display(no[temp1[2]%10]);
display(‘:’);
display(no[(temp1[1]/10)%10]);
display(no[temp1[1]%10]);
display(‘:’);
display(no[(temp1[0]/10)%10]);
display(no[temp1[0]%10]);
}
while(1);
}

How to Operate?

  1. Burn the software to the 8051 microcontroller first.
  2. Make the connections as shown in the circuit diagram.
  3. Turn on the board’s power supply.
  4. On the LCD, you can now see the time. Set the time by pulling the start pin low and pressing the push button connected to the P3.3
  5. LCD, which displays the set time message. Use the P1.4-connected push button to set the hours, and the other push button to set the minutes.
  6. To start the clock, set the start pin to a high value.

Circuit Applications

  • This project is used to show the time and date in offices, homes, hotels, and automobiles.
  • With a little tweaking, we can also set the alarm in this project.
Tags

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close
Close