Difference between revisions of "ARDUINO 328 Functions Miscellaneous"

From ROBOTC API Guide
Jump to: navigation, search
Line 1: Line 1:
 
{{DISPLAYTITLE:328 Miscellaneous Functions}}
 
{{DISPLAYTITLE:328 Miscellaneous Functions}}
<yambe:breadcrumb self="328 Miscellaneous Functions">ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb>
+
<yambe:breadcrumb self="328 Miscellaneous Functions">ARDUINO_328_Functions_and_Variables|Functions and Variables</yambe:breadcrumb>
 
<br />
 
<br />
  

Revision as of 20:40, 11 May 2012

ARDUINOFunctions and Variables → 328 Miscellaneous Functions


Color Key
Function:
Variable:


memcpy

void memcpy(void &pToBuffer, const void &pFromBuffer, const short nNumbOfBytes)
(void) Function copies characters from pFromBuffer to pToBuffer. nBytesToCopy is the number of bytes to copy. Identical to the function found in conventional C 'string.h' library.
Parameter Explanation Data Type
pToBuffer buffer to copy to void
pFromBuffer buffer to copy from void
nNumbOfBytes number of bytes to copy short
string sTemp = "ROBOTC";               // create a string, 'sTemp' to be "ROBOTC"
char sArray[20];                       // create a char array, 'sArray' of size 20
memcpy(sArray, sTemp, sizeof(sTemp));  // copy characters from 'sTemp' to 'sArray'


memset

void memset(void &pToBuffer, const short nValue, const short nNumbOfBytes)
(void) Sets a block of memory at pToBuffer to the value nValue. nNumbOfBytes is the number of bytes to set. This is a useful function for initializing the value of an array to all zeros. Identical to the function found in conventional C 'string.h' library.
Parameter Explanation Data Type
pToBuffer buffer to set void
nValue value to set buffer to short
nNumbOfBytes number of bytes to set short
int kSendSize = 1;                                   // we will be sending 1 byte
ubyte BytesToSend[kSendSize];                        // create a ubyte array of size 1
short nMsgXmit = 0;                                  // we will be setting them to 0
memset(BytesToSend, nMsgXmit, sizeof(BytesToSend));  // set the Byte Array to 0


memcmp

intrinsic short memcmp(void &pToBuffer, void &pFromBuffer, const short nNumbOfBytes)
(void) Compares the first set bytes of the block of memory referenced by "pToBuffer" to the first number of bytes referenced by "pFromBuffer". The function will return zero if they all match or a value different from zero representing which is greater if they do not.
Parameter Explanation Data Type
pToBuffer First buffer to compare. void
pFromBuffer Second buffer to compare. void
nNumbOfBytes Number of bytes to compare short
  char temp1[5] = {'A', 'B', 'C', 'D', 'E'};  //Create an Array
  short result = 0;                           //Variable to store result
  result = memcmp(temp1[0], temp1[2], 2);     //Perform the memory compare


memmove

void memmove(void &pToBuffer, const void &pFromBuffer, const short nNumbOfBytes)
(void) Function copies characters from pFromBuffer to pToBuffer. nBytesToCopy is the number of bytes to copy. Identical to the function found in conventional C 'string.h' library.

The advantage of "memmove" is that the buffers can overlap in memory space - the "memcpy" function they cannot overlap.

Parameter Explanation Data Type
pToBuffer buffer to copy to void
pFromBuffer buffer to copy from void
nNumbOfBytes number of bytes to copy short
task main()
{
  string source = "ROBOTC is cool!....";  // create string variable 'source' and set it to "ROBOTC is cool!...."
  string destination = "";                // create string variable 'destination' and set it equal to ""
  int length = 15;                        // create int variable 'length' and set it equal to 15
 
  memmove(destination, source, length);   // copy 'length' number of bytes (15) from 'source' to 'destination'
 
  while(true);                            // infinite loop to keep the debugger alive to see output
  // after running:
  // source       = "ROBOTC is cool!...."
  // destination  = "ROBOTC is cool!"
}