CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

alarm clock problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
energetic007



Joined: 10 Nov 2013
Posts: 10

View user's profile Send private message

alarm clock problem
PostPosted: Fri Feb 07, 2014 9:10 am     Reply with quote

hey, i want to design a pic based alarm clock but firstly i need to get familiar with the timing issues and rtc concepts.. i have learnt how to configure the timers i.e. TMR0,TMR1,TMR2 of f877a. But my problem is that i am not able to guess that.. what do we do when we set the time e.g. say on our phones we set alarm at 5AM .. or say a timer for 20 minutes ... i am feeling very confused regarding what do we actually set there ... is it the number of counts after which the timer should interrupt the processor or what else also if that is the case then how can i design a timer that obey the keys .

can someone provide me a working code that has the provision for increasing or decreasing the timing with buttons.
my code does not respond when i press the button.
its been three months since i am stuck in this code and haven't finished a single project because i am feeling very depressed due to my very little understanding of the subject .
////////////////////////////////////////////////////////////////////////////////////

#include<16f877a.h>
#fuses NOCPD,NOWDT,XT
#use delay(clock=4m)
#byte T2CON=0x12
int16 count=0;
int16 count_1=0;
#INT_TIMER2
void isr(void)
{
count++;
if(count==15) // 65.536ms x 15=1000ms = 1 second/ tick
{
count=0;
count_1++;
if(count_1==5) //for 5 sec delay
{ count_1 =0;
output_toggle(PIN_A3); // led toggles at a rate of 1second .
}
}
}

void main()
{
output_a(0x00);
setup_adc(ADC_OFF);
setup_comparator(NC_NC_NC_NC);
setup_psp(PSP_DISABLED);
setup_timer_2(T2_DIV_BY_16,255,16); // 1usx16= 16us x 256 =4096 us x 16= 65536us= 65.536 ms delay
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER2);
do
{ output_high(PIN_C3);
if (input(PIN_C0)==0) // button is here.
count_1=10; // for 10 sec delay
}
while(1==1);
}
/////////////////////////////////////////////////////////////////////////////////


Last edited by energetic007 on Fri Feb 07, 2014 10:51 am; edited 2 times in total
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Feb 07, 2014 9:45 am     Reply with quote

code buttons?
Code:
#include<16f877a.h>
#fuses NOCPD,NOWDT,XT
#use delay(clock=4m)
#byte T2CON=0x12
int16 count=0;
int16 count_1=0;
#INT_TIMER2
void isr(void)
{
count++;
if(count==15) // 65.536ms x 15=1000ms = 1 second/ tick
{
count=0;
count_1++;
if(count_1==5) //for 5 sec delay
{ count_1 =0;
output_toggle(PIN_A3);
}
}
}

void main()
{
output_a(0x00);
setup_adc(ADC_OFF);
setup_comparator(NC_NC_NC_NC);
setup_psp(PSP_DISABLED);
setup_timer_2(T2_DIV_BY_16,255,16); // 1usx16= 16us x 256 =4096 us x 16= 65536us= 65.536 ms delay
// reversed order of ops below
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
 
do
{ output_high(PIN_C3);
if (input(PIN_C0)==0) // button is here.
count_1=10; // for 10 sec delay
}
while(1==1);
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Feb 07, 2014 9:53 am     Reply with quote

Take a step back.

1) What are expecting your code to do?
2) How do your LEDs tell you what's going on?
3) Do you have an RS232 link to a PC?
4) Which CCS samples have you tried and tested?

Mike

PS

Indent your code and use the code button to make it easier to follow.
energetic007



Joined: 10 Nov 2013
Posts: 10

View user's profile Send private message

PostPosted: Fri Feb 07, 2014 10:47 am     Reply with quote

@ asmboy :
code buttons means : on each button press the timer value gets increased by a certain multiple.
e.g. let the counter interrupt the processor after 10 second on first press.
on second press the timer interrupts the processor after 20seconds.
on third press the timer interrupts the processor after 30 seconds.
and so on.
so if i want to take a quick nap of 15 minutes , i set the timer to interrupt after 15 minutes.
sorry, for the exaggeration but this is what i really want to do.

@ MIKE
1) i want to design a timer that times out after a fixed amount of time and rings a bell or does something
2) my led at port A pin A3 toggles at a rate as fixed by the program e.g. it toggles here at a rate of 1 second.
3) no, i don't have a RS232 link.
4) sorry, i couldn't get your last question .
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Feb 07, 2014 12:01 pm     Reply with quote

Quote:
4) sorry, i couldn't get your last question .
CCS provides loads of sample code which does most things you might want, so you don't have to keep asking.
There's also plenty more on this forum.
When you've put in some effort and got stuck, someone here will likely help.

Quote:
3) no, i don't have a RS232 link.
RS232 provides cheap way to do diagnostics.
As your code executes you send pertinent messages to the PC.
Lets you know where you are and what's going on.

For starters you need to find out about real buttons and debouncing.

Mike

EDIT

You ran a thread on similar topic to this a short time ago.
Both Mr. T's gave you some code/guidance.
Did you learn anything?

Yes, you learnt to use TImer2 but forgot to get it to divide by a nice factor which would give you exact timing.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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