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 CCS Technical Support

Timer0 with PIC16F877A

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



Joined: 23 Mar 2008
Posts: 50

View user's profile Send private message

Timer0 with PIC16F877A
PostPosted: Thu Jul 14, 2011 7:43 pm     Reply with quote

I copied this code from another thread and am unsure as to why it doesn't work.
I have read a ton of stuff on this forum and in the F877A data sheet about timer0, but I must be missing something.
The LED turns on in the "welcome" toggle.
Thanks in advance for insight.
Nora

Code:

#include <16f877A.h>
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP      // changed to HS for 20 mHz
#use delay(clock=20000000)                           // one instruction=0.2us
#include <stdlib.h>
#use standard_io(a)
#use standard_io(b)
#use standard_io(c)

// global variables
int16 count=0;
#int_TIMER0
void TIMER0_isr()
{
   if(count == 0)
    output_high(pin_A5);
    count++;
}

void main()
{     
   set_timer0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_256); //
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);

   output_high(PIN_A5); // Welcome     
   delay_ms(1000);
   output_low(PIN_A5);
   delay_ms(1000);

while(1){
      if(count > 500) //
            output_low(PIN_A5);
            count = 0;   
            }
        }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 14, 2011 9:45 pm     Reply with quote

Change 'count' to an int8, and change the test to check for 50 instead of 500.
Nora



Joined: 23 Mar 2008
Posts: 50

View user's profile Send private message

PostPosted: Fri Jul 15, 2011 6:57 am     Reply with quote

Thanks for the reply PCM. I did as suggested and no joy.
I eventually got it to work and for completeness, am posting the solution.
Turns out I was using the wrong function (I am definitely not sleeping enough!).
From the CCS manual,
Quote:

setup_timer_0(mode) Sets the source, prescale etc for timer0
set_timer0(value) or
set_rtcc(value)
Initializes the timer0 clock/counter. Value may be a 8 bit or 16 bit
depending on the device


So I changed the function
Code:
set_timer0
to
Code:
setup_timer_0
and all is well.

Nora
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