|
|
View previous topic :: View next topic |
Author |
Message |
diehardfans
Joined: 23 Aug 2007 Posts: 3
|
putc not function? in wireless rx n tx simultanously |
Posted: Tue Mar 11, 2008 1:43 am |
|
|
why the putc is not function ?
it only works with kbhit();
is that mean that i need to a new PIC to do these two simultanous function
currently i doing wireless tx and rx using RF
do i need use the interrupt
//the code is post
#include <16F84A.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=110, xmit=PIN_A0, rcv=PIN_A2) //pin b0 is rcv via rf module
void chksum(char data, char chk)
{
char sum;
sum=116+data; //preamble =49
if (chk==sum)
{
output_high(PIN_B3);
}
//else
//putc('r'); //r std for error, this statement can be erase
}
void main ()
{
char b='1';//49
int number;
int i=0;
char data='9';//57
char data2='9';//
char data3='9';//
char data4='9';//
char from='H';//72
char to = 'S';//83
char checksum=432;
char a;
char cmd[2];
number=0;
output_high(PIN_B2);
delay_ms(1000);
output_low(PIN_B2); // notify strt up
while (1){
output_high(PIN_A3);
delay_ms(100);
putc(b);
output_low(PIN_A3);
delay_ms(10);
if (kbhit())
{
a=getc();
if (a=='t') //preamble '1'=49
{
output_high(PIN_B2); //notify in this loop liao
cmd[0]=getc();//data1
cmd[1]=getc();//data2
chksum(cmd[0],cmd[1]);
}
//else
// output_high(PIN_B1);
}
}// end while
} |
|
|
Ttelmah Guest
|
|
Posted: Tue Mar 11, 2008 3:51 am |
|
|
Not sure what you are actually having problems with. The 'putc', will work in every location shown, _but_key thing to remember, is that with _software_ RS232 (which is what you are using, and will have to use on any chip that doesn't have a UART module), communication, is only half duplex. While you are sending a byte, any data received, _will_ be lost. While you are receiving a byte, you cannot send. Also characters are only checked for, when you use kbhit, or getc. If you are doing other things (waiting in delays etc.), any data arriving _will_ be missed.
With the huge delays in your main loop, and the time needed for the putc as well, the probability of actually receiving a character with getc, is tiny...
At the slow rate you are using, you may well be able to receive the characters quite well, using the external interrupt. However if you leave this enabled, while using putc, any character in transmission will be destroyed, if a character is received.
Best Wishes |
|
|
|
|
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
|