View previous topic :: View next topic |
Author |
Message |
pic16freak
Joined: 10 Oct 2011 Posts: 7
|
pic16f616 timer 0 interrupt problems |
Posted: Mon Oct 10, 2011 12:18 pm |
|
|
Hi All,
I am having problems running my code on PIC16F616.
I have following simple code where I want to use timer0 int as RTC.
Clock = 8 MHz, hardware int 0 is enabled.
Nothing is working if I enable or add timer0 interrupt code.
I appreciate the help.
===============================
Code: |
#include <16F616.h>
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC //Internal RC Osc
#FUSES BROWNOUT_NOSL //Brownout enabled during operation, disabled during SLEEP
#use delay(clock=8000000) //int=8000000)
#define KEY1 PIN_C3
#define PUMP PIN_C2
#define IGN PIN_C1
void EXT_isr(void)
{
intcnt = 0;
}
#int_TIMER0
void TIMER0_isr(void)
{
//even if i have nothing here
}
void main()
{
unsigned int x = 0;
port_A_pullups(0x01);
setup_adc_ports(sAN3);
setup_adc(ADC_CLOCK_INTERNAL);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1|RTCC_8_bit); //128 us overflow
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
enable_interrupts(INT_EXT);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
WHILE(1)
{
OUTPUT_HIGH(IGN);
OUTPUT_HIGH(PUMP);
OUTPUT_HIGH(LED1); // = 1;
for(x = 0;x < 6000;x++)
{
;
}
//delay_ms(1000);
OUTPUT_LOW(IGN);
OUTPUT_LOW(PUMP);
OUTPUT_LOW(LED1); // = 1;
for(x = 0;x < 6000;x++)
{
;
}
//delay_ms(1000);
}
} |
Last edited by pic16freak on Mon Oct 10, 2011 12:40 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 10, 2011 12:30 pm |
|
|
You need to place an interrupt directive in the line just before the isr
function declaration. This tells the compiler that the routine is an isr
for the specified device.
Download the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Look in this section for a list of interrupt directives for each peripheral
module, etc.
|
|
|
pic16freak
Joined: 10 Oct 2011 Posts: 7
|
I have interrupt directive.. |
Posted: Mon Oct 10, 2011 12:42 pm |
|
|
Sorry I missed "#" in the code posted..code now modified.
Still nothing works.. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 10, 2011 12:56 pm |
|
|
Quote: |
unsigned int x = 0;
for(x = 0;x < 6000;x++)
|
Look in the CCS manual in this section:
Quote: |
Basic and Special types
|
Note the size of an 'int' in CCS. Look at the two tables at the start of
that section.
Also you're still missing the #int_ext directive for your other isr. |
|
|
pic16freak
Joined: 10 Oct 2011 Posts: 7
|
Thank you so much.. |
Posted: Mon Oct 10, 2011 1:17 pm |
|
|
As soon as I added #int for the other interrupt,
and changed the data type to int16 from unsigned int, the code started working.
I appreciate the quick replies.
Thank you. |
|
|
|