You are on page 1of 16

Seven segment based alarm clock using 8051 microcontroller (AT89C51

)
MC010

• • • • • • •

Summary Description Circuit Diagram Video Code Components Free Circuit Design & Simulation Tool by TI

An alarm clock is a clock that indicates a pre-set time by producing sound at that time. This unctionality o digital clock is used to a!aken people or remind them o something. This circuit is an e"tension to the digital clock !ith time setting option. #ere an e"tra s!itch is pro$ided to set the alarm. %hile the alarm is set& the clock time does not stop and runs in the background. The pro'ect is build around the ()*+ microcontroller ,AT(-C*+.

/ S!itch * . . / S!itch 1 . / 0eset Select Increment Start Alarm .S*.S+. %hene$er S * is pressed& the time display goes o and only +st segment is acti$ated. .S3. A ter selecting the desired segment& its $alue can be changed by using S2. The option to set alarm is pro$ided by pro$iding an e"tra s!itch S *& !ith the microcontoller At(-C*+& !hich is made acti$e lo!. 5nce the digits and hence the alarm is set& S 3 is pressed to start the . .to select the segment !here $alue is to be changed.to initiate the time set option. / S!itch 3 . .to start the clock !ith the set time options. / S!itch 2 . 4ut the clock time still runs in the background.To pro$ide $arious options in the digital clock& ollo!ing s!itches are used/ S!itch + .to increase the $alue at selected segment.to initiate the alarm set option. In this mode& a segment can be selected in cyclic order by pressing S 1.S2.S1.

S3 S* / / 7282 7+8* 728.7+8) 9 7+82.h> sbit dig_ctrl_4=P1 !" segments sbit dig_ctrl_&=P1 1" sbit dig_ctrl_'=P1 '" sbit dig_ctrl_1=P1 &" sbit bu((er=P& )" sbit resetalarm=P1 5" sbit resetclock=P1 4" sbit start=P& &" setting sbit incr=P1 )" time setting. sbit set=P1 -" //*eset alarm $in to reset the alarm..h. //#eclare the control $ins for the se%en // +tart $in for starting the clock after time // . //*eset clock $in to reset the clock.a . 4u66er / The bu66er is connected to the output pin o microcontroller at the negati$e end and to V cc at the positi$e end.clock again.. The enable pins are connected to pins +-3 o port 7 + . The s!itches S+S* and bu66er are connected as ollo!ing/ S+ S1 S2 / / / 7+83 7+8: 7+8.ncrement $in to increase the digits during // +et $in to set the time. // Program to make a digital clock with time and alarm setting features #include<reg51. As soon as the set alarm time is reached& a bu66er gets signal rom the microcontroller thus producing sound. The se$en segments are inter aced to port 7 1 o the microcontroller AT(-C*+ through its data pins . .

1!/=0!14!2!1342!1'42!1&!2!1142!11'2!1!'2!1352!1!!2!11!6" // 7e1 %alues corres$onding to digits ! to 4 %oid dela89int time: //3unction to $ro%ide time dela8.int sel_seg_to_incr=!" int ret_seg_to_incre=!" int recnt_incr_seg" int begin" unsigned char dig_dis$=!" int min'=!" int min1=!" int sec'=!" int sec1=!" int minalarm'=!" int minalarm1=!" int secalarm'=!" int secalarm1=!" int alarmmin'=!" int alarmmin1=!" int alarmsec'=!" int alarmsec1=!" int kee$min'=!" int kee$min1=!" int kee$sec'=!" int kee$sec1=!" int loo$=!" int mode" char dig_%al. .

0 while9set==!: 0 // 3unction to select miniute and seconds digit set switch9recnt_incr_seg: 0 case 1= if9set==!: 0 dig_ctrl_4=1" dig_ctrl_&=!" dig_ctrl_'=!" dig_ctrl_1=!" recnt_incr_seg=1" ret_seg_to_incre=1" P'=dig_%al.<1')5".minalarm'/" dela891!!:" 6 //+elect the min' digit .0 int i2.=!"." for9i=!"i<time"i<<: for9.<<:" 6 int setfn9: time.

case '= if9set==!: 0 dig_ctrl_4=!" dig_ctrl_&=1" dig_ctrl_'=!" dig_ctrl_1=!" recnt_incr_seg='" ret_seg_to_incre='" P'=dig_%al.secalarm'/" dela891!!:" 6 //+elect the sec ' digit case 4= .minalarm1/" dela891!!:" 6 //+elect the min1 digit case &= if9set==!: 0 dig_ctrl_4=!" dig_ctrl_&=!" dig_ctrl_'=1" dig_ctrl_1=!" recnt_incr_seg=&" ret_seg_to_incre=&" P'=dig_%al.

if9set==!: 0 //+elect the sec1 digit recnt_incr_seg=1" dig_ctrl_4=!" dig_ctrl_&=!" dig_ctrl_'=!" dig_ctrl_1=1" ret_seg_to_incre=4" P'=dig_%al. P'=dig_%al.minalarm'/" .secalarm1/" dela891!!:" recnt_incr_seg=1" 6 6 6 return9ret_seg_to_incre:" 6 %oid increase9int a: digit 0 while9incr==!: 0 switch9a: 0 //3unction to set the minutes or seconds case 1= // +et the min' digit.

P'=dig_%al.secalarm'/" dela891!!:" secalarm'<<" if9secalarm'==-: secalarm'=!" P'=dig_%al.minalarm'/" dela89'!:" break" case '= //+et the min1 digit.minalarm1/" dela891!!:" minalarm1<<" if9minalarm1==1!: minalarm1=!" P'=dig_%al.minalarm1/" dela89'!:" break" case &= // +et the sec' digit. P'=dig_%al.dela891!!:" minalarm'<<" if9minalarm'==-: minalarm'=!" P'=dig_%al.secalarm'/" dela89'!:" break" .

secalarm1/" dela891!!:" secalarm1<<" if9secalarm1==1!: secalarm1=!" P'=dig_%al. 0 begin=1" dig_ctrl_4=1" dig_ctrl_&=!" dig_ctrl_'=!" dig_ctrl_1=!" if9mode==!: 0 . // 3unction to bring the clock to reset or //>nable the min' digit and disable others //?heck if clock is in set alarm mode //#isable @imer! interru$t to sto$ the dis$la8 of sel_seg_to_incr=1" .case 4= //+et the sec1 digit. //recnt_incr_seg=4" P'=dig_%al.secalarm1/" dela89'!:" break" 6 6 6 %oid resetfn9mode: set mode.>=!155" clock.

>=!15!" //#isable @imer! interru$t to sto$ the clock.kee$min'/" dela891!!:" minalarm'=kee$min'" minalarm1=kee$min1" secalarm'=kee$sec'" secalarm1=kee$sec1" 6 if9mode==1: 0 .min'/" dela891!!:" 6 while91: 0 if9start==!: 0 if9mode==!: 0 kee$min'=minalarm'" //?heck if start $in is $ressed . //?heck if clock is in set clock mode minalarm'=min'" minalarm1=min1" secalarm'=sec'" secalarm1=sec1" sel_seg_to_incr=1" recnt_incr_seg=1" P'=dig_%al.recnt_incr_seg=1" P'=dig_%al.

kee$min1=minalarm1" kee$sec'=secalarm'" kee$sec1=secalarm1" alarmmin'=minalarm'" alarmmin1=minalarm1" alarmsec'=secalarm'" alarmsec1=secalarm1" 6 if9mode==1: 0 min'=minalarm'" min1=minalarm1" sec'=secalarm'" sec1=secalarm1" 6 @AB#=!111" @C!=!1f-" @7!=!13f" .>=!15D" clock @*!=1" break" 6 if9set==!: //?heck if set $in is $ressed //>nabling @imer! interru$t to start the dis$la8 of //*eset the timer! sel_seg_to_incr=setfn9:" if9incr==!: //?heck if incr $in is $ressed increase9sel_seg_to_incr:" .

0 @C!=!1&-" //*eload @imer! @7!=!1f-" P'=!133" dig_ctrl_1 = dig_ctrl_& = dig_ctrl_' = dig_ctrl_4 = !" dig_dis$<<" dig_dis$=dig_dis$E4" switch9dig_dis$: 0 case != P'=dig_%al.sec'/" dig_ctrl_' = 1" break" case '= P'= dig_%al.min1/" dig_ctrl_& = 1" .sec1/" dig_ctrl_1 = 1" break" case 1= P'= dig_%al.6 6 %oid dis$la89: interru$t 1 // 3unction to dis$la8 the digits on se%en segment using the conce$t of se%en segment multi$le1ing.

break" case &= P'= dig_%al.min'/" dig_ctrl_4 = 1" break" 6 6 %oid mo%eclock9: interru$t & digits 0 loo$<<" if9loo$=='!: 0 sec1<<" if9sec1==1!: 0 sec1=!" sec'<<" if9sec'==-: 0 sec1=!" sec'=!" min1<<" if9min1==1!: 0 // 3unction to increment clock .

nitiali(e set2 reset2 start and incr $ins as in$ut resetalarm=1" resetclock=1" start=1" incr=1" begin=!" .sec1=!" sec'=!" min1=!" min'<<" if9min'==-: 0 sec1=!" sec'=!" min1=!" min'=!" 6 6 6 6 loo$=!" 6 6 %oid main9: 0 mode=!" set=1" //.

>=!15D" @*!=1" //.@AB#=!111" @C!=!1f-" @7!=!13f" .ntiali(e @imer ! //Coad timer! //>nable @imer! interru$t //+tart @imer! @C1=!13#" @71=!14F" @*1=1" while91: 0 h if9resetalarm==!: 0 resetfn9!:" 6 if9resetclock==!://?heck if reset clock $in is $ressed 0 resetfn91:" 6 if9min'==alarmmin'GGmin1==alarmmin1GGsec'==alarmsec'GGsec1==alarm sec1GGbegin==1:// ?heck for Dlarm condition 0 bu((er=!" dela895!!:" bu((er=1" 6 6 //?heck if reset alarm $in is $ressed // +tart @imer1 .

6 .