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

Interrupts Help

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







Interrupts Help
PostPosted: Mon Jun 02, 2008 7:33 am     Reply with quote

Hi, I am currently trying to complete a project which would be best if interrupts were used. However, in trying to create a simple interrupts program in which an LED on pin C6 is blinking in a loop for the main code and whenever an interrupt occurs, an LED on pin C7 will blink once. However, the LED on pin C7 will blink constantly as if an interrupt is constantly being triggered. I contacted CCS and they told me to read port B, which is the port I am using to interrupt (int_RB). However, all that this seemed to do was make C7 blink a few times and then no light changes state for what seems like an arbitrary amount of time.

Code:


#include "C:\Documents and Settings\BrianTi\My Documents\My Projects\Distributorless Ignition Module\Interrupts\StepOne.h"\

int dummy;

#int_RB
void RB_isr(void)
{
 dummy = input_b(); // Read Port B
 output_high(PIN_C6);  // Blink light once
 delay_ms(200);
 output_low(PIN_C6);
 delay_ms(200);
}



void main()
{
   SET_TRIS_C( 0x00 );
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_comparator(FALSE);
   setup_vref(FALSE);
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);
   setup_oscillator(False);

  while(1)
  {
  output_toggle(PIN_C7);
  delay_ms(200);
  }
}



[header file]
#include <16F677.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES RC_IO                    //Resistor/Capacitor Osc
#FUSES PROTECT                  //Code protected from reads
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOCPD                    //No EE protection
#FUSES NOPUT                    //No Power Up Timer
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled

#use delay(clock=20000000)

[/header]
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Jun 02, 2008 8:25 am     Reply with quote

A very good practice is to never never ever get in the habit of putting delays in interrupts.
Instead set a global flag in the interrupt and in main use the flag to control your LED.
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