You are on page 1of 20

ALARM CLOCK

(SOFTWARE)
BY
S.INDUMATHI
M.E(APPLIED ELECTRONICS)
EMBEDDED C PROGRAM FOR DIGITAL
ALARM CLOCK
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<graphics.h>
#include<time.h>
void main()
{
int i,j,k,hour,min,g,y=1;
struct time t;
char msg[80];
int gd=DETECT,gm; /* GRAPHICS INITIALIZATION*/
initgraph(&gd,&gm,"..//bgi"); /*THE PATH SHOULD BE
GIVEN*/
gettime(&t);
setcolor(14);
sprintf(msg,"The current time is: %d %02d %02d",
t.ti_hour,t.ti_min,t.ti_sec);
outtextxy(150,50,msg);
outtextxy(40,100,"GIVE ONLY THE HOUR AND MINUTE YOU
WANT TO SET THE ALARM(hh,mm)");
outtextxy(97,149,"HOUR:");
gotoxy(19,10);
scanf("%d",&hour); /*GETS THE HOUR AND SECOND
TO SET THE ALARM*/
outtextxy(85,198,"MINUTE:");
gotoxy(20,13);
scanf("%d",&min);
outtextxy(485,400,“ALARM");
outtextxy(460,430,“WAKE UP");
if( t.ti_hour > hour )
goto b;
else if(hour == t.ti_hour && min<=t.ti_min )
goto b;
else
{
for(i=t.ti_hour;i<=hour;i++)
{
for(j=t.ti_min;j<60;j++)
{
k=0;
while(k<60)
{
cleardevice();
k++;
setfillstyle(1,1);
bar(510,170,90,230);
settextstyle(1,0,3);
sprintf(msg,"%d %d %d",i,j,k);
outtextxy(230,188,msg);
sound(1000);
delay(100);
nosound();
sleep(1);
if(j==min && i==hour)
{
cleardevice();
while(!kbhit())
{
delay(300);
sound(1000);
setcolor(y);
outtextxy(250,200,"WAKE UP");
delay(300);
nosound();
y++;
}
goto a;
}}}}}
a:
getch();
exit(0);
b:
cleardevice();
outtextxy(250,250,"INVALID TIME");
getch();
}
SYSTEM ARCHITECTURE
The following two major software component
1. An interrupt-driven routine can update the current
time
• The current time will be kept in a variable in memory
• A timer can be used to interrupt periodically and update
the time
• The display must be sent the new value when the
minute value changes
• This routine can also maintain the PM indicator
2. A foreground program can poll the buttons and execute
their commands
• Since buttons are changed at a relatively slow rate, it
makes sense to add the hardware required to connect
the buttons to interrupts
• Foreground program will read the button values and
then use simple conditional tests to implement the
commands
• Setting the current time
• Setting the alarm
• Turning off the alarm.
• Another routine called by the foreground program will
turn the buzzer on and off based on the alarm time.
FLOW CHART FOR SETTING TIME
FOREGROUND CODE IMPLEMENTED
IN WHILE LOOP
while (TRUE)
{
read_buttons(button_values);/* read inputs */
process_command(button_values);/* do
commands */
check_alarm();/* decide whether to turn on the
alarm */
}
• The loop first reads the buttons using
read_buttons()
• Routine must preprocess button values so that
the user interface code will respond properly
• The buttons will remain depressed for many
sample periods since the sample rate is much
faster than any person can push and release
buttons
• The clock responds to this as a single
depression of the button,not one depression
per sample interval.
PREPROCESSING BUTTON INPUTS
• Simple edge detection on the button input
The button event value is 1 for one sample
period when the button is depressed and
then goes back to 0 and does not return to
1 until the button is depressed and then
released. This can be accomplished by a
simple two-state machine.
• The process_command() function is
responsible for responding to button
events.
• The check_alarm() function checks the
current time against the alarm time and
decides when to turn on the buzzer.
COMPONENT DESIGN AND TESTING
• The two major software components,the
interrupt handler and the foreground code,
can be implemented relatively straight
forwardly.
• Functionality of the interrupt handler is in the
interruption process itself, that code is best
tested on the microprocessor platform.
• The foreground code can be more easily
tested on the PC or workstation used for code
development.
• A better testing strategy is to add testing code
that updates the clock, perhaps once per four
iterations of the foreground while loop.
• The timer will probably be a stock component, so
we would then focus on implementing logic to
interface to the buttons, display, and buzzer.
• The buttons will require debouncing logic.
• The display will require a register to hold the
current display value in order to drive the display
elements.
SYSTEM INTEGRATION AND TESTING
• System integration is relatively easy.
• The software must be checked to ensure that
debugging code has been turned off.
• Three types of tests can be performed.
• First, the clock accuracy can be checked
against a reference clock.
• Second, the commands can be exercised from
the buttons.
• Finally, the buzzer’s functionality should be
verified.
THANK YOU

You might also like