|
|
View previous topic :: View next topic |
Author |
Message |
E_KARVELAs
Joined: 14 Feb 2007 Posts: 46 Location: Greece & Cyprus
|
Simple code for 1way wireless link |
Posted: Tue Jan 29, 2008 7:27 pm |
|
|
HI
i wanted to test some wireless module from SparkFun on a simple one way link but with NO results something wrong on the code.
http://www.sparkfun.com/commerce/product_info.php?products_id=7815
From the code of receiver the #int_rda does not fire .
Can any one help me what i got wrong here???
Trasmitter Code:
Code: |
#include <18F452.h>
#fuses XT, NOWDT, NOPROTECT,NOLVP,NOBROWNOUT, PUT
#use delay (clock = 4000000)
#use rs232(baud=1200, xmit=PIN_D3, rcv=PIN_D4, ERRORS, STREAM=COM_A)
void main()
{
for(;;){
if(input(PIN_C4)==0) //if button pressed
{
output_high(PIN_D2); //enable Vcc of transmitter module
output_high(PIN_D1); //output high Led
delay_ms(20);
fputc('T', COM_A);
delay_ms(20);
delay_ms(1000); //delay some ms
output_low(PIN_D1); // output low led
output_low(PIN_D2); //disable Vcc of transmitter module TSW434
}
output_high(PIN_D1); // if button not pressed then just on off led on pin D1
delay_ms(50);
output_low(PIN_D1);
delay_ms(50);
}
}
|
Receiver Code:
Code: |
#include <18F452.h>
#fuses XT, NOWDT, NOPROTECT,NOLVP,BROWNOUT, PUT
#use delay (clock = 4000000)
#use rs232(baud=1200,parity=N, xmit=PIN_D3, rcv=PIN_D2, ERRORS, STREAM=COM_A)
char data;
#int_RDA
void RDA_isr(void)
{
data= fgetc(COM_A);
}
void main()
{
enable_interrupts(global);
enable_interrupts(int_rda);
for(;;){
if(data=='T')
{
output_high(PIN_D1);
delay_ms(1000);
output_low(PIN_D1);
data=0;
}
output_high(PIN_D1);
delay_ms(50);
output_low(PIN_D1);
delay_ms(50);
}
}
|
Code can compile OK with no errors i just can't sent data right from Tranmitter-pic to Receiver-pic..
i have wired data-pin from PIC-Receiver wich is rcv=PIN_D2 to the data pin
of RWS 434.
On the ather PIC-Tramitter i have wired the xmit=PIN_D3 to data pin of TWS 434. _________________ ---- GREECE ---- |
|
|
E_KARVELAs
Joined: 14 Feb 2007 Posts: 46 Location: Greece & Cyprus
|
|
Posted: Wed Jan 30, 2008 9:02 am |
|
|
Hi again!!!
Can Any one offer me a small example code that actually work with these wireless module as a one way link ??
Im trying to be familiar with these wireless module ,sending data from one pic to ather. _________________ ---- GREECE ---- |
|
|
E_KARVELAs
Joined: 14 Feb 2007 Posts: 46 Location: Greece & Cyprus
|
|
Posted: Wed Jan 30, 2008 10:09 am |
|
|
hi.
I found the problem,Now code works ok!!!!!!!!!!!
The issue was i had to change the ----pin_C7 for Tx
and the ----pic_C6 for Rx
for both pic of course. Cheers!!!
As i found this info from the datasheets -18F542 -USART.
These code now works file with wireless module from :
http://www.sparkfun.com/commerce/product_info.php?products_id=7815
transmitter
Code: |
#include <18F452.h>
//-------------------------------------------------------------------------------
#define WireTX PIN_C6 // <--------- C 6
#define WireRX PIN_C7
//-------------------------------------------------------------------------------
#fuses XT, NOWDT, NOPROTECT,NOLVP,NOBROWNOUT, PUT
#use delay (clock = 4000000)
#use rs232(baud=2400,xmit=WireTX , rcv=WireRX ,ERRORS , STREAM=COM_A )
void main()
{
for(;;){
if(input(PIN_C4)==0) //if button pressed
{
output_high(PIN_D2); //enable Vcc of transmitter module
output_high(PIN_D1); //output high Led
delay_ms(20);
fputc('T',COM_A);
delay_ms(20);
delay_ms(1000); //delay some ms
output_low(PIN_D1); // output low led
output_low(PIN_D2); //disable Vcc of transmitter module TSW434
}
output_high(PIN_D1); // if button not pressed then just on off led on pin D1
delay_ms(50);
output_low(PIN_D1);
delay_ms(50);
}
}
|
Receiver
Code: |
#include <18F452.h>
#fuses XT, NOWDT, NOPROTECT,NOLVP,BROWNOUT, PUT
#use delay (clock = 4000000)
//------------------------------
#define WireTX PIN_C6
#define WireRX PIN_C7 //<-----
//------------------------------
#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 main()
{
enable_interrupts(global);
enable_interrupts(int_rda);
for(;;){
if(flag==1)
{
output_high(PIN_D1);
delay_ms(1000);
output_low(PIN_D1);
flag=0;
}
output_high(PIN_D1);
delay_ms(50);
output_low(PIN_D1);
delay_ms(50);
}
}
|
_________________ ---- GREECE ---- |
|
|
anandpv2009
Joined: 26 Jul 2009 Posts: 31
|
Thanks Thanks |
Posted: Mon Sep 21, 2009 12:26 pm |
|
|
Thank u friend for this code.....................
It works............... |
|
|
|
|
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
|