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

need help in set up timer0

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



Joined: 08 Apr 2010
Posts: 11

View user's profile Send private message

need help in set up timer0
PostPosted: Thu Apr 15, 2010 11:57 am     Reply with quote

Hi everyone
I am new in C programming of PIC chip. I programmed pic chip in assembly before but now want to convert to C.

I have question on setup timer0 and run it as a timer with 16bit. How can I set it to be a 16 bit timer, how do I start and stop the timer? how can I check the overflow bit without using interrupt?

I knew that in assembly, I can check the overflow bit, start timer, stop timer. Is there away to do the similar thing in C?
thank you
Olivier
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 15, 2010 12:05 pm     Reply with quote

Download the compiler manual and look up the Timer0 functions:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf

For the overflow bit, look up this function:
Code:
interrupt_active()


To see the Timer0 function parameter values, look in the Timer0
section in the .h file for your PIC. Example:
Quote:
c:\program files\picc\devices\18f4520.h
olivier



Joined: 08 Apr 2010
Posts: 11

View user's profile Send private message

PostPosted: Thu Apr 15, 2010 1:47 pm     Reply with quote

Why the compiler ask for close paren at line 33 and line 36 ?
It has to be a newbie error.
Code:

#include "C:\Microcontroller Firmware Center\Delay Time Counter\My Lab\main-18F4680.h"
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdlibm.h>
#include <string.h>

void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF);

   // TODO: USER CODE!!
   int32 count=0;
   int clear_bit=0;
   float Delay_Time=0;
   disable_interrupts(INT_TIMER0);
   clear_interrupt(INT_TIMER0);
   output_high(PIN_A1);
   while(input(start_switch==1)
   {
      set_timer0(0);
 L1:  if (input(stop_switch==1 || count<6500)
      {
         if (interrupt_active(INT_TIMER0))
         { 
            count++;
            clear_bit = interrupt_active(INT_TIMER0);
         }
         else
         {
            goto L1 ;
         }
      }
      else 
      {
      Delay_Time=count/1000;
      }
      return; 
   }
while(true);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 15, 2010 2:10 pm     Reply with quote

Download the manual and look up what the allowable parameters are
for the input() function.
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
johnbravado



Joined: 07 Apr 2010
Posts: 11

View user's profile Send private message

PostPosted: Thu Apr 15, 2010 4:31 pm     Reply with quote

olivier wrote:

Code:

 L1:  if (input(stop_switch==1 || count<6500)


you are missing parenthesis.
Code:

 L1:  if (input(stop_switch==1 || count<6500))

the second error may be a result from this missing parenthesis
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