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

My problem Timer 0

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



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

My problem Timer 0
PostPosted: Wed Feb 27, 2008 9:54 am     Reply with quote

Hi! My crystal is 4MHz, I have a relay connected with PIN_C0 (PIC16F877A)
Here is my code, I intend to wait for 2 seconds by timer and then interrupt will activate the relay, then delay 2 seconds again and deactivate relay, this thing will repeat and repeat (ok and it's not like I expect, nothing happen, my hardware is okay)
Code:

int count;
#int_RTCC
void RTCC_isr()
{
   set_timer0(6);
   if (count==2000)
   {
   output_high(PIN_C0);
   delay_ms(2000);
   count=0;
   }
   else
   count++;
}
//**********************
void main()
{
   // TODO: USER CODE!!
   InitPic();
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);
   count=0;
   do
   {
   output_low(PIN_C0);
   }
   while(1);
}
//**********************
void InitPic()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_4);
   output_b(0x00);
   output_d(0x00);
}
//**********************

Could you tell me where I am wrong, thanks !
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 27, 2008 12:48 pm     Reply with quote

Quote:
int count;
#int_RTCC
void RTCC_isr()
{
set_timer0(6);
if (count==2000)
{


Download the CCS manual:
http://www.ccsinfo.com/downloads/CReferenceManual.pdf
Go to page 49 in the Acrobat reader (page 37 in the manual).
It has a table of data types, and their sizes. What is the size
of an 'int' in CCS ? Can you compare it to 2000 ?
smiles



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Wed Feb 27, 2008 7:51 pm     Reply with quote

Oh I forgot, I will repair it Confused
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Feb 28, 2008 1:59 am     Reply with quote

I hope your program isn't intending on doing anything else.
Having that delay_ms(2000); in the ISR will stop anything else from running.

Even if this is the only code in your PIC you may want to revise the way you do this as it is bad practice.
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