View previous topic :: View next topic |
Author |
Message |
olivier
Joined: 08 Apr 2010 Posts: 11
|
need help in set up timer0 |
Posted: Thu Apr 15, 2010 11:57 am |
|
|
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
|
|
Posted: Thu Apr 15, 2010 12:05 pm |
|
|
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:
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
|
|
Posted: Thu Apr 15, 2010 1:47 pm |
|
|
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
|
|
|
johnbravado
Joined: 07 Apr 2010 Posts: 11
|
|
Posted: Thu Apr 15, 2010 4:31 pm |
|
|
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 |
|
|
|