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 and 12f675

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







Timer1 and 12f675
PostPosted: Thu Jan 09, 2003 1:39 pm     Reply with quote

Hello I have a probleme with timer1 in a 12f675. This is my code

can you help me.
The led turn on but only once after that the led is always on.

#int_TIMER1
TIMER1_isr()
{
set_timer1(0xFC4F);
if(!EtatLed1)//led1==off
{
output_low(Led1);//Led1=ON, active sur un 0
EtatLed1=1;
}
else//Led1==on
{
output_high(Led1);//Led1=OFF, active sur un 0
EtatLed1=0;
}
}
Main()
{
CptrIntT0=15;
set_tris_a (0b11111100); //PIN_A0 en PIN_A1 Output, //PIN_A3,A4,A5 en Input
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
enable_interrupts(INT_TIMER1); //enable TMR1 INT
setup_counters(RTCC_INTERNAL,RTCC_DIV_256);
set_rtcc(0);
enable_interrupts(INT_RTCC);
enable_interrupts(global);

while(1);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10571
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Timer1 and 12f675
PostPosted: Thu Jan 09, 2003 3:00 pm     Reply with quote

:=Hello I have a probleme with timer1 in a 12f675. This is my code
:=
:=can you help me.
:=The led turn on but only once after that the led is always on.
----------------------------------------------------------------
That's because the LED is turning on and off at a high
frequency. To your eye, it appears to be constantly on.
You need to use a lower frequency.


Change this line,
set_timer1(0xFC4F);
to be this:
set_timer1(0x0);


Also, change this line,
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
to be this:
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
___________________________
This message was ported from CCS's old forum
Original Post ID: 10576
kolio
Guest







Re: Timer1 and 12f675
PostPosted: Fri Jan 10, 2003 2:24 am     Reply with quote

:=Hello I have a probleme with timer1 in a 12f675. This is my code
:=
:=can you help me.
:=The led turn on but only once after that the led is always on.
:=
:=#int_TIMER1
:=TIMER1_isr()
:={
:= set_timer1(0xFC4F);
:= if(!EtatLed1)//led1==off
:= {
:= output_low(Led1);//Led1=ON, active sur un 0
:= EtatLed1=1;
:= }
:= else//Led1==on
:= {
:= output_high(Led1);//Led1=OFF, active sur un 0
:= EtatLed1=0;
:= }

Hi,
Just one more hint. I'm using compiler 2.731 version. It doesn't support 12F675, but generally at each ISR the proper IF should be cleared in order to allow normal operation. Otherwise the same ISR will be executed after exiting it. Forever. May be the new versions have such a feature to maintain IF with adding automaticaly at compilation time such an instructions, but for sure

bit_clear(PIR1,TMR1IF);

before the closing bracket of TMR1 ISR will not damage your program.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10586
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Timer1 and 12f675
PostPosted: Fri Jan 10, 2003 11:50 am     Reply with quote

<font face="Courier New" size=-1>:=Just one more hint. I'm using compiler 2.731 version. It doesn't support 12F675, but generally at each ISR the proper IF should be cleared in order to allow normal operation. Otherwise the same ISR will be executed after exiting it. Forever. May be the new versions have such a feature to maintain IF with adding automaticaly at compilation time such an instructions, but for sure
:=
:=bit_clear(PIR1,TMR1IF);
:=
:=before the closing bracket of TMR1 ISR will not damage your program.
---------------------------------------------------------

You don't actually have to do that. The CCS compiler will
take care of it for you. See the code below, compiled for
a 12F675.

<PRE>
0000 00270 ......... #int_timer1
0000 00271 ......... void timer1_isr(void)
0000 00272
0000 00273 ......... {
0000 00274 ......... char c;
0000 00275 .........
0000 00276 ......... c = 0x55;
0030 3055 00277 MOVLW 55
0031 00A8 00278 MOVWF 28
0000 00279 .........
0032 100C 00280 BCF 0C.0 <-- This clears TMR1IF bit.
0033 118A 00281 BCF 0A.3 <-- This changes PCLATH.
0034 2821 00282 GOTO 021
0000 00283 ......... }
0000 00284 .........
</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 10595
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