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

How to write continuous detection?

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



Joined: 07 Mar 2009
Posts: 12

View user's profile Send private message

How to write continuous detection?
PostPosted: Tue Mar 24, 2009 9:45 pm     Reply with quote

Use all the eight bit, XXXX XXXX

XX | XX | XX | XX
box4 | box3 | box2 | box1
Code:

while (1);
{
while (input(pin_B0) && input (pin_B1))
      {
       printf (usb_cdc_putc, "3");
      }
      
while (input(pin_B2) && input (pin_B3))
      {
       printf (usb_cdc_putc, "12");
      }

while (input(pin_B4) && input (pin_B5))
      {
       printf (usb_cdc_putc, "48");
      }

while (input(pin_B6) && input (pin_B7))
      {
       printf (usb_cdc_putc, "192");
      }
}

What I want to ask is if I have four boxes to detect, each represents by 2 pins out of 8 pins and if I have 2 boxes been detected, will the above code able to do the printf job for both boxes? Or it will only run and be stuck with the job of printf of one of the box?

What I want is to continuously detect all the boxes, means after detect the 1st box, if is high for both pins, do printf, else do nothing, then detect 2nd box and third and fourth. If so, how should I modify my coding?
aliciamee



Joined: 07 Mar 2009
Posts: 12

View user's profile Send private message

PostPosted: Tue Mar 24, 2009 10:25 pm     Reply with quote

It is an idea different from the above, but basically there are alike, i come out with two ideas.
Input XXXX XXXX - take the last 4 bits

XX XX
col2 col1 row2 row1

box1 (row1, col1)
box2 (row2, col1)
box3 (row1, col2)
box4 (row2, col2)

idea:
check row 1 follow by column 1 and 2
check row 2 follow by col 1 and 2

Code:
while (1);
{                  
if (input_state (pin_B0));            
    {               
    if (input_state (pin_B2))            
        printf (usb_cdc_putc, '5');             
    if (input_state (pin_B3))
        printf (usb_cdc_putc, '9');
    row2 ();
    }

else (input_state (pin_B1));
      {
      if (input_state (pin_B2));
          printf (usb_cdc_putc, '6');

      if (input_state (pin_B3));
         printf (usb_cdc_putc, '10');
      }
}

void row2 ()
     {
      if (input_state (pin_B1));
          {
           if (input_state (pin_B2));
           printf (usb_cdc_putc, '6');

           if (input_state (pin_B3));
           printf (usb_cdc_putc, '10');
          }
      }

for eg: if I want to notify box1, box2 and box4, check row 1 1st according to the code, since is true, then go and check col 1, if col 1 is high, printf 5 and then continue check col2, if col 2 is high, printf 9 and follow by checking row 2 by going to the function row2 (), if want box 4 instead of box 3, pin_B2 should be low and only printf 10 is done for this part.

So, I need to check from box to box, the coding I write is it according to the idea I generate? What I am afraid of is that it wouldn't continue checking after checking for 1 box. Please point out my mistake...

Please reply to me as soon as possible!!! Appreaciate all helps!!! Smile
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Mar 25, 2009 12:22 am     Reply with quote

I see no reason to use a while loop. Generally, no code that potentially repeats forever should be used.
aliciamee



Joined: 07 Mar 2009
Posts: 12

View user's profile Send private message

PostPosted: Wed Mar 25, 2009 12:59 am     Reply with quote

FvM wrote:
I see no reason to use a while loop. Generally, no code that potentially repeats forever should be used.


which while loop that u mean? The main one, while (1) or the one i put in first post, while (input(pin_B0) && input (pin_B1)) ? So, my code can run as what i think, that it check from box to box?

Please reply... Thanks to FvM.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Mar 25, 2009 1:59 am     Reply with quote

If the while(1) in the second example is your main loop, it's basically O.K.. Some housekeeping action should be done additionally, e.g. calling usb_task() and anything else, that's required as continuous action by your application.

If the criterion is met, your code will permanently fire, sending a shower of numbers without any formatting, most likely unwanted in this way, I guess. But you didn't tell, what you exactly want to achieve.

Cause both codes are apparently performing a rather different input decoding, I didn't yet understand their purpose. But it's not really necessary, I think.
aliciamee



Joined: 07 Mar 2009
Posts: 12

View user's profile Send private message

PostPosted: Wed Mar 25, 2009 2:45 am     Reply with quote

Each box will have two connection to the PIC, first method is separated eight bits to 4 boxes, while the second method is presented in matrix form for indicating the four boxes. The first method is more straight forward, that eg: pin_B0 and pin_B1 is high, box 1 is indicated and send the data to PC, '3' just a value send to the PC via USB, i on my way building a comm port monitor using VB and link it to mysql, so i can update the database, change and telling the database the box1 is in used.

My english is not very good, hope u can understand. the coding i post is only a small part. I need to change the status of box one by one and update the database one by one, after know it is from which box, it will later send out email to notify the user. The different input decoding is based on my circuit, whether i connect with matrix form or not.

So, after what i explained, do u think my part coding working based on what i want?

Hope u can reply me asap... Thanks!!!
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