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

Problem on revise function to operate many commands once

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







Problem on revise function to operate many commands once
PostPosted: Thu Jan 14, 2010 1:47 pm     Reply with quote

Code:
void receive_packet()
{
   int8 pn, pos, checksum, num_bytes, save_bytes;
   
   num_bytes=read_usb();//get the number of bytes
   buffer[0]=num_bytes;
   save_bytes = num_bytes;//save a copy
   pos=1;
   while(num_bytes--)
      buffer[pos++]=read_usb();

   checksum=0;
   for(pn=0; pn<save_bytes+1; pn++)
      checksum ^= (int8)buffer[pn];

   if(read_usb() == checksum)//if checksums match
   {
      delay_us(100);
      if(input(RXF)==0)//if more data in FIFO
      {
         delay_ms(5);//still have data in the FIFO but not exceed 100 bytes, read out. Or error!
         
                        while(input(RXF)==0)//clear the FIFO
                             {
                                 delay_ms(5);
                                 read_usb();
                             }
                                 send(0xAb);//error!
                                 packet_ready=0;
      }
                       
                       else
                       for(num_bytes=0; num_bytes++; num_bytes=60000)
                        {
                            if(num_bytes<=100)
                                    {
                                      send(0x55);//no error
                                      delay_us(100);
                                      packet_ready=1;
                                    }   
                        }
else//checksum failed
   {
      send(0xaa);//error!
      packet_ready=0;
   }

   strobe_SND();//send now
}

I have a problem of writing the function 'receive_packet'. This function can only operate one command (several lines) at once. But as I want it to read many commands and operate once, I tried to revise the code. After compiling, no results came out, either the only one command. The code above is what I revised. Could you help me with this? Thank you very much! The code below is the original code for one command.
Code:

 if(read_usb() == checksum)//if checksums match
   {
      delay_us(100);
      if(input(RXF)==0)//if more data in FIFO
      {
         //still have data in the FIFO -- ERROR!
         delay_ms(5);
         while(input(RXF)==0)//clear the FIFO
         {
            delay_ms(5);
            read_usb();
         }

         send(0xAb);//error!
           packet_ready=0;
      }
       else
      {
         send(0x55);//no error
         delay_us(100);
         packet_ready=1;
      }
   }
   else//checksum failed
   {
      send(0xaa);//error!
      packet_ready=0;
   }

   strobe_SND();//send now
}
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