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

help me! it does not work (interrupt, timer1)

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



Joined: 24 Aug 2010
Posts: 3
Location: south korea, incheon,

View user's profile Send private message MSN Messenger

help me! it does not work (interrupt, timer1)
PostPosted: Sun Nov 14, 2010 7:56 pm     Reply with quote

Hi everyone.
This is below my codes...to use time clock. (sorry, i'm not native).
It doesn't work - interrupts routine.
What is problem in my codes? plz, tell me what are problems.
My devices are 16f877a, ccs-c V.4.008 compiler, picdem2 board, icd2.
Code:

#include<16f877a.h>
#fuses xt,noprotect,nowrt,nobrownout,nolvp,nocpd,put
#use delay(clock=4000000)
#zero_ram

#byte porta=0x05
#byte portb=0x06
#byte portc=0x07
#byte trisc=0x87
#byte trisa=0x85
#byte trisb=0x86

int cnt=0;

#int_timer1
void timer1_isr()
{
   cnt++;                     
   if(cnt%2==1)               
   {
      portb=0xff;
   }
   else                      
   {
      portb=0x00;
   }   
   set_timer1(32768);               
}


void main()
{
   trisa=0xff;                  trisb=0x00;            
//   trisc=0xff;                  
   portb=0;                  portb=0xff;            

   set_timer1(32768);            
         
   setup_timer_1(T1_EXTERNAL);   
                //32.768hz ,portc.0(T1oso),portc.1(T1osi)
   setup_timer_1(T1_DIV_BY_1);      
   setup_timer_1(T1_CLK_OUT);      

   enable_interrupts(int_timer1);   
   enable_interrupts(global);         

   while(1)                  {
                    <--continous loop..
                 }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 14, 2010 8:58 pm     Reply with quote

Quote:
setup_timer_1(T1_EXTERNAL);
//32.768hz ,portc.0(T1oso),portc.1(T1osi)
setup_timer_1(T1_DIV_BY_1);
setup_timer_1(T1_CLK_OUT);

This is wrong. CCS functions don't work with sequential calls.
The parameters must all be in place for just one call to the function.
The .h file for your PIC explains how to do this. Here is an example
of the correct method:
Code:
setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1 | T1_CLK_OUT);

This line will setup Timer1 to work with the external oscillator, with a
32.768 KHz crystal on the T1OSC pins. The PicDem2-Plus board has
this crystal on those pins.


Also, vs. 4.008 is a bad version to use. It's too early in the vs. 4.000
series. It has bugs. It's better to use at least vs. 4.068, and preferably
a version much later than that. Vs. 4.008 might work for some very
simple code. It might work for your program here. But if you try to do
any more complicated programs, you will find some compiler bugs.
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