|
|
View previous topic :: View next topic |
Author |
Message |
elizabeth ann
Joined: 16 Feb 2008 Posts: 33
|
simultaneous alarm events without clock stop |
Posted: Wed Mar 12, 2008 9:55 pm |
|
|
hello everyone...i have a problem with this simple alarm program. i am using CCS C and Proteus VSM and i would like to implement this program in actual user interface. i've used the DS1307.c driver found in this forum and made some modifications according to my program.
here's what i want to do:
1) set the alarm for 10 bins independently. that is, i can immediately set the alarm for another bin when i'm done setting the time for Bin #1, for example, WITHOUT affecting the alarm event that i have just configured.
2) the alarm should repeat if intake>1 and will execute until it is equal to "intake", and should afterwards go back to the part where the user will be asked to choose another bin if he still wants to set an alarm. (---thankfully, i've done this already)
3) clock should continue to run in the background all throughout the program, even when the alarm event for that certain bin is over.
however, what's happening with this program is this:
1) i can set the alarm for the other bins ONLY WHEN the ongoing alarm has finished.
2) Time stops and restarts to original time i've set when the alarm event is finished.
that's it for now. but i still have so many questions to ask...
i'm running out of ideas...can somebody help please...
Code: |
///////////////////////////////////////////////////////////////////////////////
#include "D:\All SP\all programs\white\scarlet.h"
#include "C:\Documents and Settings\SP2008\Desktop\rtc programs\rtcdriver.c"
#include <stdlib.h>
#include <LCD.C>
#include <KBD.C>
void showtime();
void intake();void rtc1();void second();
char k[5];
int dig2,termi,dura,a,secnow;
int x;
BYTE sec;
BYTE min;
BYTE hrs;
BYTE day;
BYTE month;
BYTE yr;
BYTE dow;
BYTE aHr=0;
BYTE aMin=0;
BYTE aSec=0;
BYTE isAlarm = 0;
void second()
{
lcd_putc("\finterval: 0=exit");
lcd_putc("\n4,6,8,12,24");
for(;;)
{
k[2]=kbd_getc();
if(k[2]!=0)
{if (k[2]=='4' || k[2]=='6' || k[2]=='8')
{ printf(lcd_putc,"\fevery %c hrs",k[2]);
dig2=0;}
else
{if (k[2]=='1' || k[2]=='2')
{if (k[2]=='1')
{lcd_putc("\fevery 12 hrs");
dig2=1;}
else
{lcd_putc("\fevery 24 hrs");
dig2=2;}
}
}
/////////////////////SET NUMBER OF INTAKE////////////////////
lcd_putc("\f# of intake:");
for(;;)
{
k[3]=kbd_getc();
if (k[3]!=0)
if (k[3]=='*' || k[3]=='#')
{ lcd_putc("\fINVALID\nenter intake:"); }
else
{ printf(lcd_putc,"\fintake: %c",k[3]);
rtc1(); //GO TO TIMER PROPER
lcd_putc("\fback");
termi=k[3]-'0';
dura=termi;
for (termi=1;termi<dura;termi++)
{
isAlarm=0;
ds1307_get_time(hrs,min,sec);
secnow=sec;
aSec=secnow+x;
while(1)
{
showtime();
lcd_gotoxy(1,1);
if (( aHr==hrs ) && ( aMin==min ) && ( aSec==sec ))
{ isAlarm=1;
}
if (isAlarm )
{ output_toggle(PIN_C0);
delay_ms(100);
if (!input(PIN_A1))
{ output_low(PIN_C0);
break;
}
}
}
}lcd_putc("\fAlarm over\nEnter bin #");
return;
}
}
}
}
}
void showtime()
{
ds1307_get_date(day,month,yr,dow);
ds1307_get_time(hrs,min,sec);
printf(lcd_putc,"\f\%02d/\%02d/\%02d\r\n",day,month,yr);
printf(lcd_putc,"\%02d:\%02d:\%02d", hrs,min,sec);
delay_ms(500);
}
void rtc1()
{
ds1307_init();
ds1307_set_date_time(19,3,87,2,0,0,0);
set_tris_a(0x02);
if (k[2]=='1' || k[2]=='2')
{
if(k[2]=='1')
k[2]='2';
else
{k[2]='4';}
x=(dig2*10+(k[2]-'0'));
}
else
x=(k[2]-'0');
aSec=x;
a=x;
while(1)
{
showtime();
lcd_gotoxy(1,1);
if (( aHr==hrs ) && ( aMin==min ) && ( aSec==sec ))
{ isAlarm=1;
}
if (isAlarm )
{
output_toggle(PIN_C0);
if (!input(PIN_A1))
{
output_low(PIN_C0);
return;
}
}
}
}
void main()
{
port_b_pullups(TRUE);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
lcd_init();
kbd_init();
init_io();
while(TRUE)
{
ds1307_get_time(hrs,min,sec);
lcd_putc("\fbin #:\n#-bin 10"); //set bin number
for(;;)
{
k[1]=kbd_getc();
if(k[1]!=0)
if (k[1]=='0' || k[1]=='*')
{ lcd_putc("\fINVALID\nenter #");}
else
{
printf(lcd_putc,"\fbin %c",k[1]);
delay_ms(100);
second();
}
}
}
}
|
Last edited by elizabeth ann on Sun Mar 23, 2008 1:21 am; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 14, 2008 12:10 am |
|
|
Your code is too complicated to look at. I think that's why you're not
getting any replies. There are too many comparisons to '1' and '2', that
just go on and on. It's easier to get an answer from us when you post
a short program that shows the problem. |
|
|
elizabeth ann
Joined: 16 Feb 2008 Posts: 33
|
|
Posted: Fri Mar 14, 2008 12:37 am |
|
|
thank you for the comment.
i will post a flowchart when i come back online.
i hope that will help you guys visualize my program better.
thank you. |
|
|
SimpleAsPossible
Joined: 19 Jun 2004 Posts: 21
|
Delay_ms() |
Posted: Mon Mar 17, 2008 10:00 pm |
|
|
I just glanced at the code briefly (did someone mention that it's very long and complicated?). You have some delay_ms() calls that seem to be keeping your program from responding to user input.
Have you considered the RTOS options? Or a similar homebrew version? It looks like you need to respond to multiple things at once. You might want to break each large item into small pieces so you are able to respond to them all during a fast main loop. The large items are, for example, printing to the LCD, reading user input, checking for an alarm (either on or off), etc. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|