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

more than one rs232

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



Joined: 27 Feb 2006
Posts: 20

View user's profile Send private message

more than one rs232
PostPosted: Mon Apr 24, 2006 7:55 am     Reply with quote

I want to be able to send stream information from pc to PIC to gsm sim card and also to be able to send from gsm sim card to PIC to pc but i am having trouble setting up the 2 rs232 connections using the code i have implemented, i am using the int_rda interrupt to see if info is coming from the gsm card and printing it to visual basic, there is no problem with this , but i dont know how i would implement the stream from the pc to the PIC using the same interupt i am using the following code
Code:
#include <16F74.h>
#device adc=8
#fuses NOWDT,XT, NOPUT, NOPROTECT, BROWNOUT
#use delay(clock=3645000)
#use rs232(baud=9600, parity=n, bits=8, xmit=pin_a2, rcv=pin_a4,ERRORS, stream=PC)//PC
#use rs232(baud=9600, parity=n, bits=8, xmit=pin_c6, rcv=pin_c7,ERRORS, stream=GSM)//GSM

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in=0;
BYTE next_out=0;

#define bkbhit (next_in!=next_out)

long timeout;
char answer;
long testtimer;
int i;

#int_rda
void serial_isr()
{
int t;
buffer[next_in]=getc(GSM);
t=next_in;
next_in=(next_in+1)%BUFFER_SIZE;
if (next_in==next_out)
   next_in=t;         //buffer full!!
}
BYTE bgetc()
{
BYTE c;
while (!bkbhit);
c=buffer[next_out];
next_out=(next_out+1)%BUFFER_SIZE;
return(c);
}

void Reset()
{
enable_interrupts(int_rda);
output_high(PIN_B1);
delay_ms(200);
while (bkbhit)
   fprintf(PC,"%X",bgetc());
disable_interrupts(INT_RDA);
}
void main()
{
   command[1]=0x80;
   command[2]=0xC0;
   command[3]=0x02;
   command[4]=0xA4;
   command[5]=0x0D;
   enable_interrupts(global);
   InitialContacts();
   start:
   timeout=0;
   testtimer=0;
   
   test=0xFF;
   
   while(!kbhit(PC)&&(++timeout<1000))
      delay_us(10);

   if(kbhit(PC))
   {
      answer=getch(PC);
   if (answer=='s')
      {
         enable_interrupts(int_rda);
         output_low(PIN_B7);
         delay_us(10);
         for(i=0;i<=5;i++)
            fprintf(GSM,"%X",command[i]);
            fprintf(PC,"%X",command[1]);
         output_high(PIN_B7);
         delay_ms(50);
         while (bkbhit)
            fprintf(PC,"%X",bgetc());
         disable_interrupts(int_rda);
         goto start;
         
      }
   else
      {
         goto start;
      }
   }
   else
   {
      goto start;
   }   
}

as you can see the interrupt is set up to take info from the gsm,
Code:
buffer[next_in]=getc(GSM);
how could i set it up so i could take info from pc or gsm depending on which i want to read information.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Apr 24, 2006 11:53 am     Reply with quote

Quote:

I want to be able to send stream information from pc to PIC to gsm sim card and
also to be able to send from gsm sim card to PIC to pc

It is possible to do it in such way but it is a little twisted. It would be easiest
if you can select one of the two modes using a switch selector.

YouŽll need to re-define the dedicated pins for a software UART to detect the incoming
character, you can use the #INT_EXT capability to detect it.

I wrote a simple test code just to show how you can do it, hope you understand
the idea. Code not tested.

Code:
 
#use rs232(baud=9600,parity=n,bits=8,xmit=pin_B1,rcv=pin_B0,stream=PC) // PC
#use rs232(baud=9600,parity=n,bits=8,xmit=pin_C6,rcv=pin_C7,stream=GSM,ERRORS)//GSM

 
#INT_EXT
void software_receiver()
{
  if(kbhit(PC))
    {
     answer=getc(PC);
    }   
}

#INT_RDA
void serial_isr()
{
   answer=getc(GSM);
}

void main()
{
   enable_interrupts(global);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT);
   answer=0;
   while(1)
   {
    do
      {
      }while(!answer);
       
    fprintf(PC,"%C", answer); 
    answer=0;
   }
}     


Humberto
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