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

16F628A RX TX wirelessly

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



Joined: 16 Jul 2008
Posts: 50

View user's profile Send private message

16F628A RX TX wirelessly
PostPosted: Wed Jul 16, 2008 7:23 pm     Reply with quote

Hi all, I got a WRL-07816 from sparkfun.

Now I'm trying to communicate wirelessly with the TX and RX.

My problem is:
I can communicate with the two, but I've to use a POT in the receiver and it has to be adjusted precisely, otherwise it wont work.

The receiver is always getting something (I know it has noise) but what can I do to make it work? The way I'm doing probably it will work here in the protoboard (I'm using one PIC to both transmit and receive) but when I get another PIC and use one to transmit and another one to receive probably it wont work, because the signal will get weaker as the distance increases, I thought that when I get my new PIC (16f88) I could use read_adc to get the voltage, this way it will work as a precise POT, but the signal strength still resides..


My code:
Code:
#include <16F628A.h>
#use delay (clock=4000000)
#fuses INTRC_IO, NOWDT, NOPUT, NOBROWNOUT, NOMCLR, NOLVP, NOPROTECT

void transmit()
{
   output_high(PIN_A0);
   delay_ms(100);
   output_low(PIN_A0);
   delay_ms(100);
}

void receive()
{
      if (input(PIN_A1) == 1)
      {
         output_high(PIN_B0);
      }
      else
      {
         output_low(PIN_B0);
      }
      delay_ms(100);
}
void main()
{
   while (true)
   {
      transmit();
      receive();
   }
}



Anyone?

Thanks



EDIT:

I forgot to mention that I have my receiver connected to PIN_A1 and transmitter to PIN_A0
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

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

RE:
PostPosted: Wed Jul 16, 2008 10:56 pm     Reply with quote

You need to configure the UART on the mcu using the #uses rs232 directive.

Ex:

#use rs232(baud=4800,xmit=pin_b2, rcv=pin_b1,parity=n,bits=8)

thanks
arunb
nuno12345



Joined: 16 Jul 2008
Posts: 50

View user's profile Send private message

PostPosted: Thu Jul 17, 2008 8:31 am     Reply with quote

Can you give me some code I can work with please?
nuno12345



Joined: 16 Jul 2008
Posts: 50

View user's profile Send private message

PostPosted: Thu Jul 17, 2008 6:44 pm     Reply with quote

Ok, I looked at other examples and made this code:

Code:
#include <16F628A.h>

//-------------------------------------------------------------------------------
#define WireTX PIN_B2 // <--------- C 6
#define WireRX PIN_B1
//-------------------------------------------------------------------------------

#use delay (clock=4000000)
#fuses INTRC_IO, NOWDT, NOPUT, NOBROWNOUT, NOMCLR, NOLVP, NOPROTECT

#use rs232(baud=2400,xmit=WireTX , rcv=WireRX ,ERRORS , STREAM=COM_A )


unsigned int8 data;
int1 flag=0;

#int_rda
void rd_isr(void)               
{
   disable_interrupts(INT_RDA);           // Disable Serial Recieve Interrupt
   disable_interrupts(GLOBAL);            // Disable Global Interrupts

   data= fgetc(COM_A);

   if(data=='T')
   {
      flag=1;
   }

   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);
}

void transmit()
{
   if(input(PIN_A0)==0)  //if button pressed
   {
      delay_ms(20);
      fputc('T',COM_A);
      delay_ms(20);
                   
      delay_ms(200);         //delay some ms
   }
}

void receive()
{
   if(flag==1)
   {
      output_high(PIN_A1);
      delay_ms(1000);
      output_low(PIN_A1);
      flag=0;
   }   
}



void main()
{
   enable_interrupts(global);
   enable_interrupts(int_rda);

   while(1)
   {
      transmit();

      receive();
        }
}


Thing is, my LED flashes randomly, but when I connect PIN_A0 to GND nothing happens, or it keeps flashing randomly, and when I connect PIN_A0 to VCC the LED shuts off..
nuno12345



Joined: 16 Jul 2008
Posts: 50

View user's profile Send private message

PostPosted: Thu Jul 17, 2008 10:37 pm     Reply with quote

Got it to work thanks to the following thread

Code:
Code:
#include <16F628A.h>

#define WireTX PIN_B2
#define WireRX PIN_B1

#use delay (clock=4000000)
#fuses INTRC_IO, NOWDT, NOPUT, NOBROWNOUT, NOMCLR, NOLVP, NOPROTECT

#use rs232(baud=1200,xmit=WireTX , rcv=WireRX)

unsigned int data;

#INT_RDA
rda_isr()
{
   data = getc();
}

void main()
{
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   
   while(true)
   {
      if (input(PIN_A0) == 0)
      {
         putc('1');                         //Repeat data out
         output_high(WireTX);
         delay_ms(300);
         putc('2');                       //Repeat data out
         output_low(WireTX);
         delay_ms(300);
      }
     
      if(data == '1')
      {
         output_high(PIN_A1);
         delay_ms(100);
         output_low(PIN_A1);
      }
      else if(data == '2');
      {
         output_high(PIN_A1);
         delay_ms(100);
         output_low(PIN_A1);
      }

   }
}
nuno12345



Joined: 16 Jul 2008
Posts: 50

View user's profile Send private message

PostPosted: Fri Jul 18, 2008 5:02 am     Reply with quote

Actually its not working, if I disconnect my TX and RX the LED still does the same thing :/
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