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

16f887 timer problem

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



Joined: 22 Apr 2012
Posts: 6

View user's profile Send private message

16f887 timer problem
PostPosted: Sun Apr 22, 2012 10:36 pm     Reply with quote

Code:

#include "16f887.h"
#device adc=8
#device *=16
#include "ham.h" // contain ADC set up.
#include <stdio.h>
#FUSES HS, NOWDT
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
volatile int8 a=0;

#int_TIMER1
void TIMER1_isr()
{
 set_timer1(20000);
}

void main()
{
 set_tris_d(0x00);
 set_tris_a(0x00);
 output_a(0xff);
 cau_hinh_adc(); //set up adc
 setup_timer_1(RTCC_INTERNAL|RTCC_DIV_16);
 setup_timer_2(T2_DISABLED,0,1);
 enable_interrupts(int_TIMER1);
 set_timer1(20000);
 //enable_interrupts(GLOBAL);

 while(1)
 {
  a=read_adc();
  printf(" %u",a); 
  output_d(a);
  delay_ms(500);
 }
}


I try to read ADC and send the value to PC's COM port. Everything worked fine. After that, i decide to make sample with Timer1 and it doesn't work any more. I tested again with this:
Code:

#int_TIMER1
void TIMER1_isr()
{
 set_timer1(20000);
 output_d(a);
}

void main()
{
 set_tris_d(0x00);
 set_tris_a(0x00);
 output_a(0xff);
 cau_hinh_adc(); //set up adc
 setup_timer_1(RTCC_INTERNAL|RTCC_DIV_16);
 setup_timer_2(T2_DISABLED,0,1);
 enable_interrupts(int_TIMER1);
 set_timer1(20000);
 enable_interrupts(GLOBAL); // enable this

 while(1)
 {
  a=read_adc();
  printf(" %u",a); 
  delay_ms(500);
 }
}

COM port still get value from ADC but leds haven't run at all. Every code I put in TIMER1_isr() 's not run too Crying or Very sad. I use CCS 4.104
Thanks for any advices=.=
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 23, 2012 12:51 pm     Reply with quote

Quote:

setup_timer_1(RTCC_INTERNAL|RTCC_DIV_16);

Your constants are not correct. The "RTCC" constants are for Timer0.
You need to use the constants for Timer1. Look in the 16F887.h file
to find the correct constants.
Tak



Joined: 22 Apr 2012
Posts: 6

View user's profile Send private message

PostPosted: Mon Apr 23, 2012 10:42 pm     Reply with quote

Thanks PCM. It did work. my silly Embarassed
Code:
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
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