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

Multiple RS232 port

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



Joined: 04 Nov 2005
Posts: 3

View user's profile Send private message

Multiple RS232 port
PostPosted: Tue Jan 03, 2006 6:15 am     Reply with quote

I need two serial port in my proyect but the problem is that when i use #int_RDA the pic hang up.It run into the interrupt routine all time and never go out.It seems like a INT_RDA flag not cleared.Here is my code.What is wrong?.

Code:

#include <18F252.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV45                   //Brownout reset at 4.5V
#FUSES PUT                      //Power Up Timer
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(clock=20000000)

#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=VIEJO)
#use rs232(baud=9600,parity=N,xmit=PIN_C5,rcv=PIN_B0,bits=8,stream=NUEVO)


Main c
Code:

#include "c:\Pic\Interfaz Paneles\18F252\Prueba Puertos\INTERFAZ COMUNICACIONES_V1_5.h"
char caracter,caracter2;

#priority EXT,RDA

#define BUFFER_SIZE 20

BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;

#int_RDA
RDA_isr()
{

 int t;
 
   buffer[next_in]=fgetc(VIEJO);
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
   next_in=t;           // Buffer lleno !!
   



}
#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}
#define BUFFER_SIZE2 16
BYTE buffer2[BUFFER_SIZE2];
BYTE next_in2 = 0;
BYTE next_out2 = 0;
/************* INTERRUPCION DEL PUERTO SERIE NUEVO **********************/
#int_EXT
EXT_isr()
{
  int t2;
   buffer2[next_in2]=fgetc(NUEVO);
   t2=next_in2;
   next_in2=(next_in2+1) % BUFFER_SIZE2;
   if(next_in2==next_out2)
     next_in2=t2;           // Buffer lleno !!
}
#define bkbhit2 (next_in2!=next_out2)

BYTE bgetc2() {
   BYTE c2;

   while(!bkbhit2) ;
   c2=buffer2[next_out2];
   next_out2=(next_out2+1) % BUFFER_SIZE2;
   return(c2);
}


void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   ext_int_edge(H_TO_L);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);   
   #use fast_io(A)
   #use fast_io(B)
   #use fast_io(C)
   SET_TRIS_A( 0b00111111 );
   SET_TRIS_B( 0xFF );
   SET_TRIS_C( 0b10011111 );
   delay_ms(100);
   fprintf(VIEJO,"VIEJO");
   fprintf(NUEVO,"NUEVO");

   while(1)
   {

     if(bkbhit)
     {
         caracter=bgetc();
         fprintf(VIEJO,"%c",caracter);

     }
     if(bkbhit2)
     {
         caracter2=bgetc2();
         fprintf(NUEVO,"%c",caracter2);

     }
   }
}

I use 3.235 compiler version
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