View previous topic :: View next topic |
Author |
Message |
caiomasamune
Joined: 23 Jan 2012 Posts: 5
|
Timer1 as a counter - Help me please |
Posted: Mon Jan 23, 2012 12:18 pm |
|
|
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
|
|
Posted: Mon Jan 23, 2012 12:20 pm |
|
|
I tried to substitute "T1_EXTERNAL_SYNC" FOR "T1_EXTERNAL"
But the problem remains! |
|
|
caiomasamune
Joined: 23 Jan 2012 Posts: 5
|
|
|
caiomasamune
Joined: 23 Jan 2012 Posts: 5
|
|
Posted: Mon Jan 23, 2012 12:28 pm |
|
|
I realize that the interruption of timer1 doesnt work.
Someone can tell me why? |
|
|
caiomasamune
Joined: 23 Jan 2012 Posts: 5
|
|
Posted: Mon Jan 23, 2012 12:31 pm |
|
|
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
|
|
Posted: Mon Jan 23, 2012 1:49 pm |
|
|
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. |
|
|
|