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

problem with #INT_EXT, #INT_EXT1 and #INT_EXT

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



Joined: 23 Jun 2008
Posts: 3

View user's profile Send private message

problem with #INT_EXT, #INT_EXT1 and #INT_EXT
PostPosted: Mon Jun 23, 2008 2:02 am     Reply with quote

hi, I want make and example to use RB0, RB1 and RB2, RB0 works good but RB1 and RB2 doesn't work. I don't know what is the problem. My program is a cronometer, RB0 start the time, RB1 use a lap aplication keeping the time on display when recive a another interrupt on RB1 and RB2 only start the time same RB0.
Code:
#include <18F4520.h>
#fuses XT,NOWDT,NOPROTECT, NOLVP, NOBROWNOUT, PUT, NOWRT
#use delay(clock=4000000)
#use fast_io(D)
//#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3, ADDRESS=0xa0, SLOW, FORCE_HW)


   #byte port_a=0x05
   #byte port_b=0x06
   #byte port_d=0x08


int min1=0, min2=0, seg1=0, seg2=0, valor=1, i, estado, show=0, tempm1, tempm2, temps1, temps2;
int m1,m2,s1,s2;
unsigned int CONST DISPLAY[10]={0x7E, 0x0C, 0xB6, 0x9E, 0xCC, 0xDA, 0xFA, 0x0E, 0xFE, 0xDE};


/*---------------------------------------------------------------------*/
void mostrar()
{

 if(show<1)
 {m1=min1; m2=min2; s1=seg1; s2=seg2;}
 if(show==1)
 {m1=tempm1; m2=tempm2; s1=temps1; s2=temps2;}
   output_D(DISPLAY[m1]);
   output_high(PIN_A0);
   delay_ms(12);
   output_low(PIN_A0);
   output_D(DISPLAY[m2]);
   output_high(PIN_A1);
   delay_ms(12);
   output_low(PIN_A1);
   output_D(DISPLAY[s1]);
   output_high(PIN_A2);
   delay_ms(12);
   output_low(PIN_A2);
   output_D(DISPLAY[s2]);
   output_high(PIN_A3);
   delay_ms(12);
   output_low(PIN_A3);
   return;
}
/*----------------------------------------------------------------------*/
void retraso()
{
   for(i=1;i<=10;++i)
      {
        mostrar();
        delay_ms(10);
      }
   return;
}
/*----------------------------------------------------------------------*/

void conversion()
{
 do
 {
  do
  {
   do
   {
    do
      {
        mostrar();
        retraso();
        seg2=seg2+1;
       }while(seg2<10);
      seg2=0;
      seg1=seg1+1;
      }while(seg1!=6);
   min2=min2+1;
   seg1=0;
  }while(min2<10);
  min2=0;
  min1=min1+1;
 }while(min1!=6);
}
/*---------------------------------------------------------------------*/

 #int_EXT
void EXT_ISR(void)
 {
   conversion(); 
/*   tempm1=min1, tempm2=min2, temps1=seg1, temps2=seg2;
   show=1;
   valor++;
   if(valor%2 && valor>1)
   {show=0;}
 */
 }

 
 #int_EXT1
void EXT1_ISR(void)
 {
   
   tempm1=min1, tempm2=min2, temps1=seg1, temps2=seg2;
   show=1;
   valor++;
   if(valor%2 && valor>1)
   {show=0;}
 

  }
  #int_EXT2
void EXT2_ISR(void)
 {
   conversion();
 } 
/*---------------------------------------------------------------------*/
void main()
{
   set_tris_a(0xF8);
   set_tris_d(0x00);
 

   port_a=0x00;
   port_d=0x00;
   
   
   enable_interrupts(global);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_EXT1);
   enable_interrupts(INT_EXT2);
   enable_interrupts(INT_RB);
   
   ext_int_edge( L_TO_H );
   ext_int_edge(1,L_TO_H );
   ext_int_edge(2,L_TO_H );

   min1=0, min2=0, seg1=0, seg2=0;


/*do
 {

  conversion();

 }while(1);
}*/
}


I using CCS 3.216
Ttelmah
Guest







PostPosted: Mon Jun 23, 2008 4:24 am     Reply with quote

Your problem is that the first interrupt is taking so long.
You have the 'mostrar' routine, taking something over 48mSec, called repeatedly in this. The whole time you are doing this, no other interrupt can be serviced.
Do a search here. The general rule for handling interrupts, is keep the handler _short_. You should just set a flag in the interrupt, and have the 'main' code perform the display update, when it see this flag. The internal values (min1 etc.,) are also never reset after the first time in the main. Once they climb past their 'test' values, they are going to have to count all the way 'round', to get back to the starting point. This will result in the inner loop being called several million times. The code then spends _ages_ in this loop, never allowing time to handle the other interrupts.
You also have the problem of trying to call the same routines inside, and outside the interrupts. Though you have this 'remmed' out at present, this will result in interrupts being disabled in this routine in the external code, and make things even worse...

Best Wishes
Arael83



Joined: 23 Jun 2008
Posts: 3

View user's profile Send private message

I make more easy but nothing happend
PostPosted: Mon Jun 23, 2008 7:20 pm     Reply with quote

I erase the loop, only try to display several number on displays, #INT_EXT works fine, but my another interrupts on #INT_EXT1 and #INT_EXT2, doesn't work. I was use Oshon PIC18 2.55 and see my RB1-RB4, configured as analog. I donĀ“t know what happend. my code its here
Code:
#include <18F4520.h>
#fuses XT,NOWDT,NOPROTECT, NOLVP, NOBROWNOUT, PUT, NOWRT
#use delay(clock=4000000)
#use fast_io(D)

   #byte port_a=0x05
   #byte port_b=0x06
   #byte port_d=0x08

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
int min1=0, min2=0, seg1=0, seg2=0, valor=1,  estado, show=0, tempm1, tempm2, temps1, temps2;
int m1,m2,s1,s2, start, i;
unsigned int CONST DISPLAY[10]={0x7E, 0x0C, 0xB6, 0x9E, 0xCC, 0xDA, 0xFA, 0x0E, 0xFE, 0xDE};


/*---------------------------------------------------------------------*/
void mostrar()
{

 if(show<1)
 {m1=min1; m2=min2; s1=seg1; s2=seg2;}
 if(show==1)
 {m1=tempm1; m2=tempm2; s1=temps1; s2=temps2;}
   output_D(DISPLAY[m1]);
   output_high(PIN_A0);
   delay_ms(10);
   output_low(PIN_A0);
   output_D(DISPLAY[m2]);
   output_high(PIN_A1);
   delay_ms(10);
   output_low(PIN_A1);
   output_D(DISPLAY[s1]);
   output_high(PIN_A2);
   delay_ms(10);
   output_low(PIN_A2);
   output_D(DISPLAY[s2]);
   output_high(PIN_A3);
   delay_ms(10);
   output_low(PIN_A3);
   return;
}
/*----------------------------------------------------------------------*/
void retraso()
{
   for(i=1;i<=10;++i)
      {
        mostrar();
        delay_ms(10);
      }
   return;
}

/*---------------------------------------------------------------------*/


 #int_EXT
void EXT_ISR(void)
 {

   min1=0, min2=1, seg1=0, seg2=1;
 
 }

 #int_EXT1
void EXT1_ISR(void)
 {
   min1=2, min2=0, seg1=2, seg2=0;
   
  }

 #int_EXT2
void EXT2_ISR(void)
 {
   min1=3, min2=3, seg1=3, seg2=3;
   
 }

 
/*---------------------------------------------------------------------*/
void main()
{
   set_tris_a(0x00);
   set_tris_d(0x00);
   set_tris_b(0xFF);
   
   port_a=0x00;
   port_d=0x00;
   port_b=0x00;

       
        enable_interrupts(INT_EXT);
        enable_interrupts(INT_EXT1);
        enable_interrupts(INT_EXT2);
        enable_interrupts(global);
   ext_int_edge(0, L_TO_H );
   ext_int_edge(1,L_TO_H );
   ext_int_edge(2,L_TO_H );
   
   min1=0, min2=0, seg1=0, seg2=0;
do
{
 mostrar();
}while(1);

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 23, 2008 7:45 pm     Reply with quote

Quote:

#include <18F4520.h>

#byte port_a=0x05
#byte port_b=0x06
#byte port_d=0x08

port_a=0x00;
port_d=0x00;
port_b=0x00;

Download the 18F4520 data sheet.
http://ww1.microchip.com/downloads/en/DeviceDoc/39631D.pdf
Look in the following section and fix the register addresses
for Ports A, B, and D.
Quote:
TABLE 5-1: SPECIAL FUNCTION REGISTER MAP FOR PIC18F2420/2520/4420/4520 DEVICES
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