![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Marcos Coseglio Guest
|
|
Posted: Wed Oct 11, 2006 9:54 pm |
|
|
I need to clear some things about my project.
I dont use keyboard, only communication PIC to PIC.
The communication is simple and dont have problems with distance because it is only before 500cm.
My first PIC send data from PIN B2
Quote: | for example : 0b11111000. |
I used kbhit function to detect my received data in PIN B1 in my second PIC. Can i use it?
for example:
Quote: | if (kbhit()) { // when sensor receive data for serial port
in = getc(); |
After receive data , the second PIC will process information and will sns from your PIN B2 only 2 types answer 0b00000000 or 0b11111111.
he has only 250ms to sens this infrmation to first PIC.
My first PIC will receive this data from second PIC and will process the information.
Quote: | if ( kbhit() ) {
in = getc();
}
if (in == (0b00000000) || in == (0b11111111)) |
MY several problem is wth USART communication.
Do you know how can i to make this communication?
We can call PICA and PICB:
Quote: | PICA send 0b11111000
PICB receive 0b11111000
PICB will compare the data with your address.If your address is the same that 0b11111000, he will send answer 0b00000000 or 0b11111111.
PICA wait 250ms and verify that PICB answer .
IF answer he will process information.If dont answer will realize other function. |
Note that 2 PIS will stay in infinite loop for this work.
Can i use kbhit to detect my data ?
Do you know a more eficient mode that i can realize this simple communication? i only neeed detect when my PICB receive data and when my PICA receive answer.
Thanks for help me. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 12, 2006 12:16 am |
|
|
The getc() function will wait for a character to come in.
The program will not advance beyond the getc() statement until
a character comes in.
The kbhit() function will check if a character is available.
If the purpose of your while() loop is to do several things, such as
check for a character, and also check the status of a push-button
switch, and also read an A/D converter, then you should use kbhit()
to see if you have a character before you call getc(). Example:
This code does many things in the loop, so you don't want to wait
at the getc() line for a character. kbhit() is called to check if a
character is ready before getc() is called. If a character is not
ready, then the code will call the other functions in the loop.
Code: |
while(1)
{
if(kbhit())
{
c = getc();
// Put other code here to do something
// with the character.
}
check_switch();
check_adc();
check_battery();
}
|
If the purpose of the while() loop is just to wait for a character to
come in and then take some action, then you can use getc() by
itself. Example:
Code: |
while(1)
{
c = getc();
// Put other code here to do something
// with the character.
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|