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

Timer1 as a counter - Help me please

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



Joined: 23 Jan 2012
Posts: 5

View user's profile Send private message AIM Address

Timer1 as a counter - Help me please
PostPosted: Mon Jan 23, 2012 12:18 pm     Reply with quote

Guys, i'm tring to simulate a program that i have to use TIMER0 as a timer for count 1.8 seconds, and use TIMER1 for lights a LED when i press 100 times a button conected in PIN_C0. When i run, the TIMER0 works well, but TIMER1 doesn't work.

Code:
 #include <18F4520.h>
 #use delay(clock=20000000)
 #fuses HS,NOWDT,PUT,NOLVP

 //#use fast_io(a)
 //#use fast_io(b)
 //#use fast_io(c)
// #use fast_io(d)
// #use fast_io(e)

 #byte porta = 0xF80
 #byte portb = 0xF81
 #byte portc = 0xF82
 #byte portd = 0xF83
 #byte porte = 0xF84
 #bit led1 = portd.0
 #bit led2 = portd.1

  //#int_timer0
 //void rotina_timer0 ()
//{

//static int16 contador;
//set_timer0(131);
//contador++;

//if (contador == 1125)
 //{
 //led1 = !led1;
 //contador = 0;
 //}

//}
 
 #int_timer1
 void rotina_timer1 ()
 {
 output_low(pin_a0);
 led2 = !led2;
  set_timer1(65534);
 }
 
 void main ()
 {
   
    portd = 0;
  set_tris_c(0b11111111);
  set_tris_d(0b00000000);
  //setup_timer_0 (RTCC_INTERNAL |RTCC_8_BIT| RTCC_DIV_64);
   enable_interrupts (global | int_timer1 );
  setup_timer_1 (T1_EXTERNAL_SYNC | T1_DIV_BY_1);
 
 
  //set_timer0(131);

  set_timer1(65534);
 
 while(true)
 output_high(pin_a0);
 }


Note, that i commented the "TIMER0 code" for testing the "TIMER1code", but it still doesnt working.
caiomasamune



Joined: 23 Jan 2012
Posts: 5

View user's profile Send private message AIM Address

PostPosted: Mon Jan 23, 2012 12:20 pm     Reply with quote

I tried to substitute "T1_EXTERNAL_SYNC" FOR "T1_EXTERNAL"

But the problem remains!
caiomasamune



Joined: 23 Jan 2012
Posts: 5

View user's profile Send private message AIM Address

PostPosted: Mon Jan 23, 2012 12:24 pm     Reply with quote

http://imageshack.us/photo/my-images/268/esquemao.png/
caiomasamune



Joined: 23 Jan 2012
Posts: 5

View user's profile Send private message AIM Address

PostPosted: Mon Jan 23, 2012 12:28 pm     Reply with quote

I realize that the interruption of timer1 doesnt work.

Someone can tell me why?
caiomasamune



Joined: 23 Jan 2012
Posts: 5

View user's profile Send private message AIM Address

PostPosted: Mon Jan 23, 2012 12:31 pm     Reply with quote

In the program, i load timer 0 for i press the button only 2 times.

Its cause i'm testing the program's operation
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 23, 2012 1:49 pm     Reply with quote

Quote:
enable_interrupts (global | int_timer1 );

This OR'ed syntax does not exist in the CCS manual. Do not invent your
own syntax. You may get lucky. It might work in some cases, but not in
the general case.
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