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

two serial ports and two interrupts by fgetc()

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



Joined: 24 Mar 2004
Posts: 53
Location: Portugal

View user's profile Send private message Send e-mail MSN Messenger

two serial ports and two interrupts by fgetc()
PostPosted: Fri Jun 25, 2004 11:19 am     Reply with quote

Hello

I have this problem.
For comunication betwen a PC and a mobil Modem I need two serial ports, for receive data of PC or Modem.
The hardware port work fine, but the software ports don't work, when use the fgetc(PORT_B).
How can i resolve this?

the interrupt:
Code:

#int_rda
void seirala_isr()
{
   boolean Ea, Eb;
   Ea=kbhit(COM_A);
   Eb=kbhit(COM_B);
   if (Ea)
      {
       cmd=fgetc(COM_A);
        cmd=toupper(cmd);
        fputc(cmd, COM_A);
        Ea=0;
        }
   if (Eb)
      {
      dado_b=fgetc(COM_B);
        dado_b=toupper(dado_b);
        fputc(dado_b, COM_B);
        Eb=0;
        }



Carlos
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Fri Jun 25, 2004 11:49 am     Reply with quote

You can't use #int_rda for software serial, only hardware. Move your software serial RX to B0, B4-B7 or the CCP and you can use #int_ext, #int_rb or #int_ccp respectively.
carlosma



Joined: 24 Mar 2004
Posts: 53
Location: Portugal

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Jun 28, 2004 4:51 am     Reply with quote

Ok I change to RB0 but now I have a error caracter when fputc()

I have now the program:

Code:



#include <16F877.h>
#fuses HS,NOPROTECT,NOWDT,NOLVP,PUT,NOBROWNOUT
#use delay(clock=16000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, STREAM=COM_A) 
#USE RS232(BAUD=9600, XMIT=PIN_B1, RCV=PIN_B0, STREAM=COM_B)


#int_ext   //interrupt for sotftware COM_B USART port
void vira()   
{
   dado_b=fgetc(COM_B);
   dado_b=toupper(dado_b);
   fputc(dado_b,COM_B);

}

#int_rda      //interrupt for hardware COM_A USART port
void seirala_isr()
{

   cmd=fgetc(COM_A);
        cmd=toupper(cmd);
        fputc(cmd, COM_A);

}

#int_timer0      //interrupt for real time clock

timer0_isr()
{
   clock-=256; // 256 > dois elevado a 8
   if(clock<256)
      {
      clock+=CLOCK_VAL;
      tick=1;
      seconds++;
      }
}


void init_chip()
{

   setup_adc_ports(No_Analogs);
   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_32);
   enable_interrupts(int_timer0); // Enable timer0 interrupt
   enable_interrupts(INT_RDA);
   enable_interrupts(int_ext);
   enable_interrupts(GLOBAL);
}


//...

void main()
{
      static boolean led2;
      init_ext_eeprom();

    init_chip();
   fprintf(COM_A,"\r\nRead or Write: ");
   
   while(1)
   {
         if (tick) // real time clock 1 second
         {
            tick=0;
            update_clock();
               led2 = !led2; // led flash 1 second
      output_bit (pin_c0,led2);
            
            }
     
      if(dado_b=='A')
      fprintf(COM_A,"Tunga........->");
     
      if(cmd=='R')
      {
     
      //...      
      read_eeprom_string(s, ROM_SMTP, ROM_SMTP_SIZE);
      fprintf(COM_B,"AT#ESMTP=\"%s\"\r\n",s);
      //...
       }



[/quote]
steve.booth



Joined: 18 Oct 2004
Posts: 7

View user's profile Send private message

PostPosted: Fri Feb 11, 2005 2:18 am     Reply with quote

I would suggest that you don't use fputc within your interrupt routines.
ISR's should be kept as short as possible, and a 'put' take a comparable long time to execute.
Use the interrupt routine to set a flag and then detect the flag in your MAIN.
_________________
Steve
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Feb 11, 2005 7:10 am     Reply with quote

You do realize that you are respoding to a post from June of last year!
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