View previous topic :: View next topic |
Author |
Message |
midoroi
Joined: 05 Apr 2013 Posts: 11
|
tx433 & rx433 |
Posted: Tue Apr 09, 2013 10:43 am |
|
|
I have tried many code, and that doesn't work.
I really need a real help here (correcting the code).
Transmission
Code: |
#include <16F876.h>
#fuses XT,NOWDT,PROTECT,NOBROWNOUT,PUT
#use delay(clock=10M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
int start;
int addr;
int data ;
int chksum;
set_tris_b(0x00);
set_tris_a(0xff);
start = 0x55 ;
addr = 0x8E;
data = 0x27;
chksum = (addr + data);
while(true)
{
if (input(pin_b1))
{
output_high(pin_a1);
putc(start);
delay_ms(20);
putc(addr);
delay_ms(20);
putc(data);
delay_ms(20);
putc(chksum);
delay_ms(20);
}
else
{
putc(0x66);
delay_ms(20);
putc(0x66);
delay_ms(20);
putc(0x66);
delay_ms(20);
putc(0x66);
delay_ms(20);
}
}
}
|
receiver code
Code: |
#include <16F876.h>
#fuses XT,NOWDT,PROTECT,NOBROWNOUT,PUT
#use delay(clock=10M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
char c;
int start;
int addr;
int data;
int chksum;
set_tris_b(0x03);
while(true)
{
if(kbhit())
{
start=getc();
delay_ms(20);
addr=getc();
data=getc();
delay_ms(20);
chksum=getc();
delay_ms(20);
if (start ==0x55)
{
output_high(pin_b1);
}
else
{
output_low(pin_b1);
}
if (data ==0x27)
{
output_high(pin_b2);
}
else
{
output_low(pin_b2);
}
if (addr ==0x8E)
{
output_high(pin_b3);
}
else
{
output_low(pin_b3);
}
if (chksum ==(addr + data))
{
output_high(pin_b4);
}
else
{
output_low(pin_b4);
}
}
}
}
|
in isis this work perfectly
Last edited by midoroi on Tue Apr 09, 2013 11:37 am; edited 1 time in total |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Apr 09, 2013 11:05 am |
|
|
On the receiver get rid of the 2ms delays. Once the PIC reaches getc() it will wait until a character comes in. Beware it will wait forever if a character never comes in.
If your receiver 2ms is a little longer than the transmitter 2ms then the receiver will wait too long and getc() will miss the start of the next byte. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
midoroi
Joined: 05 Apr 2013 Posts: 11
|
|
Posted: Tue Apr 09, 2013 11:38 am |
|
|
i thinked to make if(kbhit()) to read all the bytes.on the place of delay_ms(20)
i means make 5 ==> if (kbhit()) |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Apr 09, 2013 12:16 pm |
|
|
Hi,
Why have you started a new thread on exactly the same topic? This is confusing, because people won't realize it, and a lot of information will need to be repeated. This is a sure way to annoy the forum members and get your thread locked!
Use your original thread here: http://www.ccsinfo.com/forum/viewtopic.php?t=50212
John |
|
|
midoroi
Joined: 05 Apr 2013 Posts: 11
|
|
Posted: Tue Apr 09, 2013 3:32 pm |
|
|
ezflyr wrote: | Hi,
Why have you started a new thread on exactly the same topic? This is confusing, because people won't realize it, and a lot of information will need to be repeated. This is a sure way to annoy the forum members and get your thread locked!
Use your original thread here: http://www.ccsinfo.com/forum/viewtopic.php?t=50212
John |
i opened new topic because it is new idea |
|
|
midoroi
Joined: 05 Apr 2013 Posts: 11
|
|
Posted: Tue Apr 16, 2013 12:47 pm |
|
|
help friends,
I need simple program for these components. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Apr 17, 2013 5:11 am |
|
|
You have not explained:-
1) What you are trying to do.
2) What result(s) you expect.
3) What result(s) you get.
4) What does/doesn't work.
5) What the problem is.
Start by posting the SHORTEST possible, complete, compilable code which shows the issue you've got.
Mike |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Wed Apr 17, 2013 8:06 am |
|
|
Classic thing.
What is the maximum clock frequency supported by the XT fuse setting?.
Isis doesn't check such things at all, and the things it does check it often gets wrong. It is like repeatedly shooting yourself in the foot, to look at Isis as being 'helpful' with the PIC..... |
|
|
|