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

USE setup_vref in PIC16F628A

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







PostPosted: Wed Oct 11, 2006 9:54 pm     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 12, 2006 12:16 am     Reply with quote

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.
  }
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