In the last post we have been able to develop the design so
that it can now measure seconds. Now it’s just a matter of few lines of coding
before we convert it to a alarm.
Basically, we can now measure minutes. If we keep a value in
a register, let’s say 10, and keep on decreasing the register by one for each
minute then we will come to the value zero in 10 minutes. If we reach zero we
can program the processor such that it will print “Alarm” in the LCD so that we
can see that our program works.
Almost all the coding will be done inside the interrupt
routine,
Following is how the interrupt routine is going to be.
Following is how the interrupt routine is going to be.
void
interrupt(){
INTCON.GIE = 0; // global interrupts disabled
if(INTCON.T0IF){ // handling the timer0 interrupt
timer_val++;
if(timer_val ==
15000){ // 19531.25 overflows per second
timer_sec++;
timer_val =
0;
if(timer_sec = 60){
//minute
time_val--;
i(time_val ==
0){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,”Alarm”);
}
}
timer_sec = 0;
}
}
}
INTCON.T0IF = 0; // clearing the interrupt flag bit
INTCON.GIE = 1; //
enabling global interrupts
}
1.
Calculate a second by using timer_val variable.
2.
Calculate number of seconds elapsed using timer_sec
variable.
3.
if(timer_sec = 60) will only be true if number
of seconds become 60 and that is a minute.
4.
If it’s a minute our known value time_val will
be reduced by one.
5.
When time_val is equal to zero LCD will show “Alarm”.
Now we have the alarm. Basically this is what we needed. Now
if we tell our processor to drive a relay once the alarm is being triggered it
will be enough to switch on a light. J
In the next post I will talk about developing the program to
drive a single relay which is even easier than this.
Thank you.
No comments:
Post a Comment