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

2 serial INT_RDA and INT_EXT

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



Joined: 20 Oct 2006
Posts: 23

View user's profile Send private message

2 serial INT_RDA and INT_EXT
PostPosted: Wed Mar 14, 2007 12:27 pm     Reply with quote

hey guy please tell me,Why INT_EXT doesn't work

Code:

#include <18f452.h>
#include <stdlib.h>
#include <CTYPE.h>
#include <STRING.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#use rs232(stream=CH1,baud=9600,xmit=PIN_C6,rcv=PIN_C7)//Hw UART-->INT RDA
#use rs232(stream=CH2,baud=9600,xmit=PIN_B1,rcv=PIN_B0,FORCE_SW)//SW UART-->INT EXT

BOOLEAN RX=0;
int j,i,a,b,c;
float Ans,cTemp,mask=0.1;
float Inact_valve,act_valve;
int LEN;
int ptr,ptr2=0;
char command;
unsigned char recv1[5];
static byte Temp[16],Temp2[8];
float MASK_value;
void CHECK_Valve(float);
int convHex(char);

/************************  INT Rx Service Routine  ***************************/
#INT_RDA  //Rx PIN Connect to D.O. Meter
void hw_uart_isr (){


      fgets(Temp,CH1);
         
         a =convHex(Temp[12]);   //Convert Ten Digit
         b =convHex(Temp[13]);   //Convert Unit Digit
         c =convHex(Temp[14]);   //Convert .X Digit
                         
         a =a*10;                 //multiply 10 for TEN Digit
         cTemp =c*(mask);         //Assigned floating point Ctemp value
         Ans=a+b+cTemp;
         CHECK_Valve(Ans);
         RX=1;      //Set RX for INT Service finish

         for (i=0;i>15;i++){
               Temp[i]=0; //Clear value in Temp[]
         }
            
            return;
         
}

/**********************  INT EXT <Virtual> Routine  *************************/
#INT_EXT
void sw_uart_isr (){
 
      fgets(Temp2,CH2);
      command=Temp2[0];
      
      recv1[0]=temp2[1];
      recv1[1]=temp2[2];
      recv1[2]=temp2[3];
      recv1[3]=temp2[4];
            
      switch (command){
         case 'A' :
               MASK_value=atof(recv1);
               act_valve=MASK_value;
                fprintf(CH2,"ACTIVE Value is : %f\n\r",act_valve);   
                     
               break;
         case 'I' :
               MASK_value=atof(recv1);
               Inact_valve=MASK_value;
               fprintf(CH2,"INACTIVE Value is : %f\n\r",Inact_valve);
               break;
         }// Close Switch

            for(i=0;i>7;i++){
               Temp2[i]=0;
            }
            for(i=0;i>4;i++){
               recv1[i]=0;

            }
      fprintf(CH2,"Oxygen in AIR is : %f\n\r",Ans);
      
                     return;   
}

/********************************  MAIN Routine  **********************************/
void main ()
{
ext_int_edge(H_TO_L);

enable_interrupts(INT_EXT);
enable_interrupts(INT_RDA);

enable_interrupts(GLOBAL);

set_tris_d(0xFE);
   
for(;;){
      if (RX){

            RX=0;

         }   
         delay_ms(5000);
         fprintf(CH2,"GODD\n\r");
   }
}

/*******************  convert Routine  ************************/
int convHex(char Data) {
      switch  (Data) {
         case '0' :
                return 0x00;
               break;
         case '1' :
                return 0x01;
               break;
         case '2' :
                 return 0x02;
               break;
         case '3' :
                 return 0x03;
               break;
         case '4' :
                return 0x04;
               break;
         case '5' :
                return 0x05;
               break;
         case '6' :
                return 0x06;
               break;
         case '7' :
                   return 0x07;
               break;
         case '8' :
                return 0x08;
               break;
         case '9' :
               return 0x09;
               break;   
         default :break;
      }

}

/*******************  CHECK_Valve Routine  ************************/
void CHECK_Valve(float Ans){
         if (Ans <act_valve>act_valve) & (Ans >= Inact_valve)){
            output_low(PIN_D0);
   }
}


And how to set INT priority...

Thank alot
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 14, 2007 12:49 pm     Reply with quote

Quote:

static byte Temp[16],Temp2[8];
unsigned char recv1[5];

for(i=0;i>7;i++){
Temp2[i]=0;
}

for(i=0;i>4;i++){
recv1[i]=0;
}

The loops above will never execute, because the test is wrong.
It should be "less than", not "greater than".

Also, if you want to clear the 'Temp2' array, your loop count is wrong.
It should be 8. The following loop will go through indexes 0 to 7,
which is a total of 8. Temp2 has 8 elements.
Code:
for(i=0; i < 8; i++)
   {
     Temp2[i]=0;
    }


A better way to do it is like this:
Code:
for(i=0; i < sizeof(Temp2); i++)
   {
     Temp2[i]=0;
    }

This way, the compiler calculates the size of the array. You don't
have to enter a number. If you change the array size later, the
compiler will automatically change the loop count to match the new size.

These things may not have anything to do with your #int_ext problem,
but that's what I saw immediately. There might be other problems.
G-TECHNIC
Guest







PostPosted: Fri May 11, 2007 7:45 am     Reply with quote

Hello,

Only a little comment. Your HexConv routine ...it was the same effect to substact 48 from the ascii value

'0' -> 48 or 30Hex

so '0' - 48 = 0 !!


int convHex(char Data)
{
return (Data-48)
}


Best regards
Ttelmah
Guest







PostPosted: Fri May 11, 2007 10:08 am     Reply with quote

Also, as soon as _one_ serial character is received, it'll sit in the RDA interrupt, till an entire string is received, and while this is happening, not be able to respond to int_ext. Similarly, if it does get to int_ext, it'll stay in the int_ext, and not respond to the RDA interrupts.
Don't use 'gets' inside interrupts. Get one character only, and attach this to a 'string' yourself.

Best Wishes
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