Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Adjustable/Resetable Digital Alarm Clock using 8051(89s52/89c52) in 7 segment display

Status
Not open for further replies.

adambose1990

Newbie level 4
Joined
Oct 7, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Kolkata, India
Activity points
1,389
This is a whole new Digital alarm clock in 7-segment display....... Some user interface facility is given here.
This is the circuit diagram....
RTC_CLOCK.jpg

Components used:
4 7-segment displays
1 AT89s52/AT89c52
28 Resistors of 150 ohm
1 Capacitor 10uF
2 Capacitors 33pF
5 volt Buzzer
1 12MHz crystal
5 Red LEDs
4 DIP switches (push button)

Description:
2 switches 'HOUR' and 'MINUTE' have been used for increasing the hour and minute in display. The clock will show 12:00 AM while switching for the first time. Then adjust the time using those HOUR and MINUTE buttons. If you want to set alarm push SET ALARM button then adjust the hour and minute and then push SAVE ALARM button. When the alarm buzzer is ringing press SET ALARM twice to stop the buzzer. This will ensure your awaking. There are two LEDs for indication AM and PM respectively. Another 2 LEDs are used for second-clock-indication. The lower LED will blink for the first 30 secs and upper one will blink for the rest 30 secs. When you are have set an alarm timing, another LED will glow.
So this is pretty cool na? I think this is much user friendly.

Coding: Coding is done in BASCOM 8051 V2.0.11.0. Its very easy, you can convert it to its equivalent C program after you understand the code.

Code:
' Description:
'
' Compiled by BASCOM 8051 Demo
'
' [url=https://www.mcselec.com]Home - MCS Electronics[/url]
'
'===========================================================================
$regfile = "REG51.DAT"
'---------------------------------------------------------------------------
' 7 Segment Pattern Data
Const Segpat0 = &B11000000                                    ' 0   ****A***
Const Segpat1 = &B11111001                                    ' 1   *      *
Const Segpat2 = &B10100100                                    ' 2   F      B
Const Segpat3 = &B10110000                                    ' 3   *      *
Const Segpat4 = &B10011001                                    ' 4   ****G***
Const Segpat5 = &B10010010                                    ' 5   *      *
Const Segpat6 = &B10000010                                    ' 6   E      C
Const Segpat7 = &B11011000                                    ' 7   *      *
Const Segpat8 = &B10000000                                    ' 8   ****D***
Const Segpat9 = &B10011000                                    ' 9
Const Segpblk = &B11111111                                    ' 10 BLANK
'---------------------------------------------------------------------------
Hour10 Alias P1.0
Led_am Alias P1.1
Led_pm Alias P1.2
Piezo Alias P1.3
Sw_alarm Alias P1.4
Sw_exit Alias P1.5
Sw_hour Alias P1.6
Sw_min Alias P1.7
'---------------------------------------------------------------------------
Dim Icount As Word
Dim Clock_cent As Byte
Dim Clock_second As Byte
Dim Clock_min As Byte
Dim Clock_hour As Byte
Dim Alarm_min As Byte
Dim Alarm_hour As Byte
Dim Data_min As Byte
Dim Data_hour As Byte
Dim Tempa As Byte
Dim Tempb As Byte
Dim Tempc As Byte
Dim Beep As Bit
Dim Dot_high As Bit
Dim Dot_low As Bit
Dim Dot_alarm As Bit
'===========================================================================
On Timer0 Timebase                                            ' Timer0 Interrupt
'---------------------------------------------------------------------------
Config Timer0 = Timer , Gate = Internal , Mode = 2            ' Timer0 Auto Reload Timer Mode
Load Timer0 , 200                                             ' Auto Reload Constant 200 uSec
Start Timer0                                                  ' Start Timer0
Enable Timer0                                                 ' Enable Timer0
Enable Interrupts                                             ' Enable All Interrupt
'===========================================================================
Icount = 0
Clock_cent = 0
Clock_second = 0
Clock_min = 0
Clock_hour = 0
Alarm_min = 0
Alarm_hour = 0
Beep = 0
Dot_alarm = 1
'---------------------------------------------------------------------------
Main_clock:
'
If Clock_cent > 99 Then
   Clock_cent = 0
   Incr Clock_second
End If
'
If Clock_second > 59 Then
   Clock_second = 0
   Incr Clock_min
End If
'
If Clock_min > 59 Then
  Clock_min = 0
  Incr Clock_hour
End If
'
If Clock_hour > 23 Then
  Clock_hour = 0
End If
'
Data_min = Clock_min : Data_hour = Clock_hour
'
Gosub Dot_proc
Gosub Clock_disp
'
If Sw_alarm = 0 Then
   Gosub Alarm_proc
End If
'
If Sw_min = 0 Then
   Clock_second = 0
   Incr Clock_min
   If Clock_min > 59 Then
      Clock_min = 0
   End If
   Waitms 100
End If
'
If Sw_hour = 0 Then
   Incr Clock_hour
   If Clock_hour > 23 Then
      Clock_hour = 0
   End If
   Waitms 100
End If
'
If Dot_alarm = 0 Then
   If Clock_hour = Alarm_hour Then
      If Clock_min = Alarm_min Then
         Set Beep
      Else
         Reset Beep
      End If
   Else
      Reset Beep
   End If
Else
   Reset Beep
End If
'
Goto Main_clock
'===========================================================================
Clock_disp:
'
Tempa = Data_min Mod 10 : Gosub Patconv
If Dot_alarm = 0 Then
  Tempb = Tempb And &H7F
End If
P3 = Tempb
'
Tempa = Data_min / 10 : Gosub Patconv
If Dot_high = 0 Then
   Tempb = Tempb And &H7F
End If
P2 = Tempb
'
If Data_hour < 12 Then
   Reset Led_am : Set Led_pm
   Tempc = Data_hour
 Else
   Reset Led_pm : Set Led_am
   Tempc = Data_hour - 12
End If
'
If Tempc = 0 Then
  Tempc = 12
End If
'
Tempa = Tempc Mod 10 : Gosub Patconv
If Dot_low = 0 Then
   Tempb = Tempb And &H7F
End If
P0 = Tempb
'
Tempa = Tempc / 10
'
If Tempa = 1 Then
   Reset Hour10
   Else
   Set Hour10
End If
'
Return
'
'===========================================================================
Dot_proc:
'
If Clock_second < 30 Then
   Reset Dot_low
   If Clock_cent < 50 Then
       Reset Dot_high
   Else
       Set Dot_high
   End If
Else
   Reset Dot_high
   If Clock_cent < 50 Then
       Reset Dot_low
   Else
       Set Dot_low
   End If
End If
'
Return
'
'===========================================================================
Alarm_proc:
'
Set Dot_high : Set Dot_low
Data_min = Alarm_min : Data_hour = Alarm_hour
Gosub Clock_disp
Waitms 100
'
Alarm_loop:
Data_min = Alarm_min : Data_hour = Alarm_hour
Gosub Clock_disp
If Sw_min = 0 Then
   Incr Alarm_min
   If Alarm_min > 59 Then
      Alarm_min = 0
   End If
   Waitms 100
End If
'
If Sw_hour = 0 Then
   Incr Alarm_hour
   If Alarm_hour > 23 Then
      Alarm_hour = 0
   End If
   Waitms 100
End If
'
If Sw_alarm = 0 Then
   Set Dot_alarm
   Goto Alarm_ret
End If
'
If Sw_exit = 0 Then
   Reset Dot_alarm
   Goto Alarm_ret
End If
'
Goto Alarm_loop
'
Alarm_ret:
'
Waitms 100
'
Return
'===========================================================================
Patconv:
'
Tempa = Tempa And &H0F
Select Case Tempa
  Case 0 : Tempb = Segpat0
  Case 1 : Tempb = Segpat1
  Case 2 : Tempb = Segpat2
  Case 3 : Tempb = Segpat3
  Case 4 : Tempb = Segpat4
  Case 5 : Tempb = Segpat5
  Case 6 : Tempb = Segpat6
  Case 7 : Tempb = Segpat7
  Case 8 : Tempb = Segpat8
  Case 9 : Tempb = Segpat9
  Case Else
End Select
'
Return
'===========================================================================
Timebase:
'
Incr Icount
'
If Icount > 49 Then                                           ' 49
'
   Icount = 0
   Incr Clock_cent
End If
'
If Beep = 1 Then
   If Piezo = 1 Then
     Reset Piezo
   Else
     Set Piezo
   End If
End If
'
If Beep = 0 Then
   Set Piezo
End If

'
Return
'---------------------------------------------------------------------------
'
'============================ END OF FILE ==================================
'

or do something funny, just make a .hex file using you notepad and copy these following codes into it.

Code:
:1000000002006632000000000000000203700000E1
:10001000000000320000000000000032000000007C
:10002000000000320000000000000000000012008C
:100030003A60044002E422740122C3EDB50706ECE5
:10004000B50602E422740122F874AD040000000039
:100050000000000070F500D8F022E62401F6FA084E
:10006000E63400F64A22787FE4F6D8FD75813075D3
:100070002000C28CE58954F02402F589758A387510
:100080008C38D28CD2A9D2AF75220075230075248A
:100090000075250075260075270075280075290054
:1000A000C205D208E524B46302800250030200B501
:1000B0007524000525E525B43B02800250030200AB
:1000C000C67525000526E526B43B028002500302D2
:1000D00000D77526000527E527B4170280025003D4
:1000E0000200E675270085262A85272B511A316BD9
:1000F000A294920450030200FB5154A29792045020
:100100000302011C7525000526E526B43B0280028A
:10011000500302011875260074641148A2969204D7
:10012000500302013A0527E527B417028002500365
:1001300002013675270074641148A2089204500326
:10014000020166E527B529028003020161E526B5B3
:100150002802800302015CD20502015EC205020191
:1001600063C205020168C2050200A475F00AE52A0F
:1001700084C0F0782CD0E0F651CCA2089204500351
:10018000020186532D7F852DB075F00AE52A84C0C3
:10019000E0782CD0E0F651CCA20692045003020184
:1001A000A4532D7F852DA0E52BB40C0280024003C3
:1001B0000201BDC291D292852B2E0201D0C292D2F1
:1001C0009175F00CE52BC395F0C0E0782ED0E0F6E9
:1001D000E52EB4000280030201DD752E0C75F00AD5
:1001E000E52E84C0F0782CD0E0F651CCA207920422
:1001F00050030201F8532D7F852D8075F00AE52EFE
:1002000084C0E0782CD0E0F6E52CB4010280030233
:100210000217C290020219D29022E525B41E028074
:1002200002400302023EC207E524B43202800240CB
:1002300003020239C20602023BD206020253C20680
:10024000E524B4320280024003020251C2070202D6
:1002500053D20722D206D20785282A85292B316B53
:100260007464114885282A85292B316BA297920442
:10027000500302028A0528E528B43B02800250039D
:1002800002028675280074641148A29692045003F5
:100290000202A80529E529B41702800250030202D0
:1002A000A475290074641148A294920450030202B8
:1002B000B6D2080202C7A295920450030202C4C239
:1002C000080202C70202647464114822532C0FE52D
:1002D0002CB4000280030202DF752DC002036FE51B
:1002E0002CB4010280030202EF752DF902036FE5C1
:1002F0002CB4020280030202FF752DA402036FE5F5
:100300002CB40302800302030F752DB002036FE5C6
:100310002CB40402800302031F752D9902036FE5BC
:100320002CB40502800302032F752D9202036FE5A2
:100330002CB40602800302033F752D8202036FE591
:100340002CB40702800302034F752DD802036FE51A
:100350002CB40802800302035F752D8002036FE551
:100360002CB40902800302036F752D9802036F22DB
:10037000C0D0C2D3C0E0C0F0C083C082C000C00102
:10038000C002C003C004C005C006C007C008C00941
:10039000C00AC00BC00CC00DC00EC00FC010C011F1
:1003A0007822115AAC22AD237E317F00112E6003DA
:1003B0000203BB7522007523000524A205920440A8
:1003C000030203D4A293920440030203D2C2930215
:1003D00003D4D293A205920450030203DFD293D038
:1003E00011D010D00FD00ED00DD00CD00BD00AD021
:1003F00009D008D007D006D005D004D003D002D051
:1004000001D000D082D083D0F0D0E0D0D032000034
:00000001FF

You also can download following rar file containing everything you need.
.bas //for Bascom
.hex
.jpg
.dsn
 

Attachments

  • Desktop.rar
    158.8 KB · Views: 321

did you write your code by yourself ? where is rtc chip?

---------- Post added at 01:42 ---------- Previous post was at 01:38 ----------

as you said this is easy its easy to copy or easy to write code i could not understand ?
 

@harishwww you dont need to incorporate the RTC IC here, because the delay loop inside the main clock is adjusted for 1 sec by itself for 12MHz crystal.
and I said If you dont have any compiler, just copy the hex code written above and paste in a .hex file(which can be made easily by notepad) and burn it on th MCU chip. so its easy. And if you go for writing the code by yourself, you are always welcome.
 

Adam..Thanks for the nice project. In fact i had built a similar project from josepino.com which used PIC16F628 with 4.000 mhz crystal with high accuracy. Using 4.0 Mhz will affect the accuracy of the clock. The accuracy of the later was better than Ds1307+crystal kits where all depends on the cylindrical crystal. I was wondering wether you have checked this project about how is the accuracy.
Cheers
 

@pranam Yes you are right, there's nothing about accuracy here, but i have checked the main delay loop, and set that for 1 sec delay. I didnt used RTC IC only to reduce the cost and size and complicity as well. One can surely use those stuffs. This is a simple project for a beginner I thought.
Thanks.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top