Dspic30f language tool libraries.pdf




















Their descriptions can be found under scanf, but they are also used by fscanf and sscanf. The output formats, or print formats, are used for writing data. Their descriptions can be found under printf. These print formats are also used by fprintf, sprintf, vfprintf, vprintf and vsprintf.

The options are summarized below: The -msmart-io option, when enabled, will attempt to convert printf, scanf and other functions that use the input output formats to an integer only variant. The functionality is the same as that of the C standard forms, minus the support for floating point output.

Mixing modules compiled with these options may result in a larger executable size, or incorrect execution if large and small double-sized data is shared across modules. If an error condition is encountered, the error indicator is set. Error conditions include write errors and input or read errors. Output: This is a sentence. This causes the error indicator to be set.

The function ferror is used to check the error indicator and find the error. The function clearerr is used to reset the error indicator so the next time ferror is called it will not report an error. Returns EOF if a write error occurs; otherwise, returns zero for success. If stream is a null pointer, all output buffers are written to files.

Returns the character read or EOF if a read error occurs or end of file is reached. The function reads the next character from the input stream, advances the file-position indicator and returns the character as an unsigned char converted to an int.

Returns 0 if successful; otherwise, returns a non-zero value. Returns a pointer to the string s if successful; otherwise, returns a null pointer The function reads characters from the input stream and stores them into the string pointed to by s until it has read n-1 characters, stores a newline character or sets the end-of-file or error indicators.

If any characters were stored, a null character is stored immediately after the last read character in the next element of the array. If fgets sets the error indicator, the array contents are indeterminate. Returns a pointer to the open stream. If the function fails a null pointer is returned. An existing file will be overwritten. A file is created if it doesn't exist. Explanation: afile1 must exist before it can be opened for reading r or the fopen function will fail.

If it doesn't exist, it will be created and then opened. Return Value: Remarks: Example: pointer to the stream in which to output data format control string optional arguments. Returns number of characters generated or a negative number if an error occurs. The format argument has the same syntax and use that it has in print. Returns the character written or EOF if a write error occurs.

The function writes the character to the output stream, advances the file-position indicator and returns the character as an unsigned char converted to an int. Returns a non-negative value if successful; otherwise, returns EOF.

The function writes characters to the output stream up to but not including the null character. Returns the number of complete elements read up to nelem whose size is specified by size.

If n is not a multiple of size, the value of the last element is indeterminate. If the function sets the error indicator, the file-position indicator is indeterminate. This allows the numbers to be saved in the same pattern of bits as the program is using which provides more accuracy and consistency.

Using fprintf would save the numbers as text strings which could cause the numbers to be truncated. Each number is divided into 10 to produce a variety of numbers. Retrieving the numbers with fread to a new array and multiplying them by the original number shows the numbers were not truncated in the save process. Returns a pointer to the new open file. The function closes the file associated with the stream as though fclose was called.

Then it opens the new file as though fopen was called. See fopen for the possible types of file access. If the freopen call is successful, myfile2 can be used to close the stream properly.

Return Value: pointer to the open stream from which to read data format control string optional arguments. Returns the number of items successfully converted and assigned. If no items are assigned, a 0 is returned.

EOF is returned if end of file is encountered before the first conversion or if an error occurs. The format argument has the same syntax and use that it has in scanf.

Returns 0 if successful; otherwise, returns a non-zero value and set errno. The first 39 characters are "this is the middle and this is the end. It stops at the EOF after reading 16 characters "this is the end. Returns the number of complete elements successfully written, which will be less than nelem only if a write error is encountered. The function writes characters to a given stream from a buffer pointed to by ptr up to nelem elements whose size is specified by size.

The file position indicator is advanced by the number of characters successfully written. Using fprintf would save the numbers as text strings, which could cause the numbers to be truncated. Same effect as fgetc with the argument stdin.

If any characters were read, a null character is stored immediately after the last read character in the next element of the array. If gets sets the error indicator, the array contents are indeterminate. The string s is printed followed by a colon and a space. There must be exactly the same number of arguments as there are format specifiers. If the are less arguments than match the format specifiers, the output is undefined.

If there are more arguments than match the format specifiers, the remaining arguments are discarded. If the result is less than the field width, pad characters will be used on the left to fill the field. If the result is greater than the field width, the field is expanded to accommodate the value without padding.

No characters are printed. Returns the character or EOF if an error occurs or end of file is reached. Same effect as fputc with stdout as an argument. The function writes characters to the stream stdout. A newline character is appended. The terminating null character is not written to the stream. Returns 0 if successful, -1 if not. If filename does not exist or is open, remove will fail.

Return Value: Remarks: Example: Return 0 if successful, non-zero if not. The new name must not already exist in the current working directory, the old name must exist in the current working directory. I ate 10 cookies. EOF is returned if an input failure is encountered before the first. This will cause the input field to be skipped and no assignment made. No characters are scanned. Allows a search of a set of characters. A dash character - may be used to specify a range beginning with the character before the dash and ending the character after the dash.

A null character can not be part of the scanset. See setvbuf. Returns 0 if successful setvbuf must be called after fopen but before any other function calls that operate on the stream. Return Value: Remarks: Example: storage string for output format control string optional arguments.

Returns the number of characters stored in s excluding the terminating null character. The format argument has the same syntax and use that it has in printf. Return Value: storage string for input format control string optional arguments.

EOF is returned if an input error is encountered before the first conversion. It will automatically be removed when exit is called; otherwise the file will remain in the directory. Returns a pointer to the filename generated and stores the filename in s. If it can not generate a filename, the NULL pointer is returned. The created filename will not conflict with an existing file name. Returns the pushed character if successful; otherwise, returns EOF The pushed back character will be returned by a subsequent read on the stream.

If more than one character is pushed back, they will be returned in the reverse order of their pushing. A successful call to a file positioning function fseek, fsetpos or rewind cancels any pushed back characters. Only one character of pushback is guaranteed. Multiple calls to ungetc without an intervening read or file positioning operation may cause a failure. This must be done before the vfprintf function is called. For more details see stdarg. Error: Requires 3 or more characters.

This must be done before the vprintf function is called. Returns number of characters stored in s excluding the terminating null character. This must be done before the vsprintf function is called. See exit for example of use.

A negative number is returned as positive; a positive number is unchanged. For the registered functions to be called, the program must terminate with the exit function call. That's an awful number Now go count something.

The number may consist of the following: [whitespace] [sign] digits [. The conversion stops when the first unrecognized character is reached. The conversion is the same as strtod s,0,0 except it does no error checking so errno will not be set. The number may consist of the following: [whitespace] [sign] digits optional whitespace, followed by an optional sign then a sequence of one or more digits. The conversion is equivalent to int strtol s,0,10 except it does no error checking so errno will not be set.

Returns a pointer to the object being searched for if found; otherwise, returns NULL. In the following example, qsort is used to sort the list before bsearch is called. This comp uses ascending order. Returns a pointer to the allocated space if successful; otherwise, returns a null pointer. Memory returned by calloc is aligned correctly for any size data element and is initialized to zero. Returns the quotient and the remainder. The returned quotient will have the same sign as the numerator divided by the denominator.

Division by zero will invoke the math exception error, which by default, will cause a reset. Write a math error handler to do something else. This function is customizable. See piclibs. If free is used on space that has already been deallocated by a previous call to free or by realloc or on space not allocated with calloc, malloc, or realloc, the behavior is undefined.

This function must be customized to be used as described see piclibs. By default there are no entries in the environment list for getenv to find. If the denominator is zero, the behavior is undefined. See Remarks. Returns zero if s points to a null character; otherwise, returns 1. Returns the number of wide characters stored excluding the null character. Returns zero if s points to a null character; otherwise, returns 1 The resulting wide character will be stored at pwc.

The comparison function is supplied by the user. In the following example, the list is sorted according to the comparison function. To use this function effectively, you must seed the random number generator using the srand function. This function will always return the same sequence of integers when no seeds are used as in the example below or when identical seed values are used. See srand for seed example. Notice if the program is run a second time, the numbers are the same.

See the example for srand to seed the random number generator. If the existing object is smaller than the new object, the entire existing object is copied to the new object and the remainder of the new object is indeterminate. If the existing object is larger than the new object, the function copies as much of the existing object as will fit in the new object. If realloc succeeds in allocating a new object, the existing object will be deallocated; otherwise, the existing object is left unchanged.

Keep a temporary pointer to the existing object since realloc will return a null pointer on failure. The rand function will always return the same sequence of integers when identical seed values are used.

If rand is called with a seed value of 1, the sequence of numbers generated will be the same as if rand had been called without srand having been called first. Returns the converted number if successful; otherwise, returns 0. If a range error occurs, errno will be set. If base is zero, strtol attempts to determine the base automatically.

It can be octal, determined by a leading zero, hexadecimal, determined by a leading 0x or 0X, or decimal in any other case. If base is specified strtol converts a sequence of digits and letters a-z case insensitive , where a-z represents the numbers Conversion stops when an out of base number is encountered. By default system will cause a reset if called with anything other than NULL. The resulting multibyte character is stored at s. Returns the number of characters stored excluding the null character.

Returns a pointer to the location of the match if successful; otherwise, returns null. Returns a positive number if s1 is greater than s2, zero if s1 is equal to s2, or a negative number if s1 is less than s2. This function compares the first n characters in s1 to the first n characters in s2 and returns a value indicating whether the buffers are less than, equal to or greater than each other.

If the buffers overlap, the behavior is undefined. Returns a pointer to the destination buffer If the buffers overlap, the effect is as if the characters are read first from s2 then written to s1 so the buffer is not corrupted. Returns the buffer with characters written to it. The character c is written to the buffer n times. Returns a pointer to the destination string. This function appends the source string including the terminating null character to the end of the destination string.

The initial character of the source string overwrites the null character at the end of the destination string. Returns a pointer to the location of the match if successful; otherwise, returns a null pointer. This function searches the string s to find the first occurrence of the character c. This function compares successive characters from s1 and s2 until they are not equal or the null terminator is reached.

Using the locale-dependent rules, it returns a positive number if s1 is greater than s2, zero if s1 is equal to s2, or a negative number if s1 is less than s2. All characters of s2 are copied, including the null terminating character. If the strings overlap, the behavior is undefined.

Returns the length of the segment in s1 not containing characters found in s2. This function will determine the number of consecutive characters from the beginning of s1 that are not contained in s2. In the second result, a is in s2. In the third result, none of the characters of s1 are in s2 so all characters are counted.

The array pointed to by strerror may be overwritten by a subsequent call to this function. This function determines the length of the string, not including the terminating null character.

This function appends up to n characters a null character and characters that follow it are not appended from the source string to the end of the destination string.

If a null character is not encountered, then a terminating null character is appended to the result. Characters that follow a null character are not compared. Copies n characters from the source string to the destination string. If the source string is less than n characters, the destination is filled with null characters to total n characters. If n characters were copied and no null character was found then the destination string will not be null-terminated. Standard C Libraries with Math Functions strncpy Continued Explanation: Each buffer contains the string shown, followed by null characters for a length of Using strlen will find the length of the string up to but not including the first null character.

In the first example, 6 characters of buf2 Where replace the first 6 characters of buf1 "We're " and the rest of buf1 remains the same "here" plus null characters. In the second example, 18 characters replace the first 18 characters of buf1 and the rest remain null characters.

In the third example, 5 characters of buf3 "Why? In the fourth example, since buf4 is only 7 characters strncpy uses 2 additional null characters to replace the first 9 characters of buf1.

The result of buf1 is 6 characters "Where? Returns a pointer to the matched character in s1 if found; otherwise, returns a null pointer. This function will search s1 for the first occurrence of a character contained in s2.

Returns a pointer to the character if found; otherwise, returns a null pointer. The function searches the string s, including the terminating null character, to find the last occurrence of character c. Returns the number of consecutive characters from the beginning of s1 that are contained in s2. This function stops searching when a character from s1 is not in s2. In the second result, the terminating null is not in s2. In the third result, a is not in s2 , so the comparison stops.

Returns the address of the first element that matches the substring if found; otherwise, returns a null pointer. This function will find the first occurrence of the string s2 excluding the null terminator within the string s1. If s2 points to a zero length string, s1 is returned. Returns a pointer to the first character of a token the first character in s1 that does not appear in the set of characters of s2.

If no token is found, the null pointer is returned. A sequence of calls to this function can be used to split up a string into substrings or tokens by replacing specified characters with null characters. The first time this function is invoked on a particular string, that string should be passed in s1. After the first time, this function can continue parsing the string from the last delimiter by invoking it with a null value passed in s1. It skips all leading characters that appear in the string s2 delimiters , then skips all characters not appearing in s2 this segment of characters is the token , and then overwrites the next character with a null character, terminating the current token.

The function strtok then saves a pointer to the character that follows, from which the next search will start. If strtok finds the end of the string before it finds a delimiter, the current token extends to the end of the string pointed to by s1.

If this is the first call to strtok, it does not modify the string no null characters are written to s1. The set of characters that is passed in s2 need not be the same for each call to strtok. If strtok is called with a non-null parameter for s1 after the initial call, the string becomes the new string to search.

The old string previously searched will be lost. Returns the length of the transformed string not including the terminating null character. If n is zero, the string is not transformed s1 may be a point null in this case and the length of s2 is returned.

If the return value is greater than or equal to n, the content of s1 is indeterminate. Since MPLAB C30 does not support alternate locales, the transformation is equivalent to strcpy, except that the length of the destination string is bounded by n If it is zero, Daylight Saving time is not in effect.

If it is a negative value, the status of Daylight Saving Time is not known. This function is equivalent to asctime localtime tod. Returns the number of seconds between t1 and t0.

By default, MPLAB C30 returns the time as instruction cycles so difftime returns the number of ticks between t1 and t0. This function breaks down the tod value into the time structure of type tm. Returns the number of characters placed in the array s if the total including the terminating null is not greater than n. Otherwise, the function returns 0 and the contents of array s are indeterminate. It was 42 weeks into the year or days into the year. Error conditions may be handled with a domain error or range error see errno.

A domain error occurs when the input argument is outside the domain over which the function is defined. The error is reported by storing the value of EDOM in errno and returning a particular value defined for each function.

A range error occurs when the result is too large or too small to be represented in the target precision. Responses to special values, such as NaNs, zeros, and infinities, may vary depending upon the function. Each function description includes a definition of the function's response to such values. A domain error occurs if x is less than -1 or greater than 1. No domain or range error will occur. Returns the arc tangent in radians in the range of -pi to pi inclusive with the quadrant determined by the signs of both parameters.

Returns the arc tangent in radians in the range of -pi to pi with the quadrant determined by the signs of both parameters. Returns the smallest integer value greater than or equal to x. See floor. See floorf. A domain error will occur if x is a NaN or infinity. Standard C Libraries with Math Functions exp Description: Include: Prototype: Argument: Return Value: Remarks: Example: Calculates the exponential function of x e raised to the power x where x is a double precision floating point value.

On an overflow, exp returns inf and on an underflow exp returns 0. A range error occurs if the magnitude of x is too large. On an overflow, expf returns inf and on an underflow exp returns 0. A negative number is returned as positive, a positive number is unchanged. Returns the largest integer value less than or equal to x. See ceil. See ceilf. Returns the remainder of x divided by y. If y is nonzero, the result will have the same sign as x and the magnitude of the result will be less than the magnitude of y.

Returns the fraction, exp points to the exponent. If x is 0, the function returns 0 for both the fraction and exponent. On an overflow, ldexp returns inf and on an underflow, ldexp returns 0. A range error will occur on overflow or underflow. A domain error occurs if x 0. Returns the signed fractional part and pint points to the integer part. The absolute value of the fractional part is in the range of 0 inclusive to 1 exclusive. If y is 0 pow returns 1. If the result overflows or underflows, a range error occurs.

If y is 0 powf returns 1. A domain error will occur if t x is a NaN or infinity. If x is negative, a domain error occurs. These functions are called by other functions in the standard C library and must be modified for the target application.

The corresponding object modules are distributed in the libpicomf. Additionally, several standard C library functions must also be modified for the target application. They are: getenv remove rename system time get a value for an environment variable remove a file rename a file or directory execute a command get the system time. Although these functions are part of the standard C library, the object modules are distributed in the libpicomf.

These modules are not distributed as part of libc-omf. By default, the helper functions listed in this chapter were written to work with the sim30 simulator. The header file, simio. It is provided so you can rebuild the libraries and continue to use the simulator. However, your application should not use this interface since the simulator will not be available to an embedded application. The helper functions must be modified and rebuilt for your target application. The libpicomf.

Execute the batch file from a command window. Then copy the newly compiled file libpicomf. The default behavior section describes what the function does as it is distributed. The description and remarks describe what it typically should do.

As distributed, this function flushes stdout and terminates. The parameter status is the same as that passed to the exit standard C library function. The change is made by resetting the process's break value and allocating the appropriate amount of space. The break value is the address of the first location beyond the end of the data segment.

The amount of allocated space increases as the break value increases. Newly allocated space is uninitialized. This helper function is used by the Standard C Library function malloc. The argument endds must be within the heap range see data space memory map below. Stack Heap variables SFR Notice that, since the stack is located immediately above the heap, using brk or sbrk has little effect on the size of the dynamic memory pool. The brk and sbrk functions are primarily intended for use in run-time environments where the stack grows downward and the heap grows upward.

For MPLAB C30, using the linker's heap size option is the standard way of controlling heap size, rather than relying on brk and sbrk.

File: brk. None int close int handle ; handle handle referring to an opened file Returns 0 if the file is successfully closed. A return value of -1 indicates an error. This helper function is called by the fclose Standard C Library function. As distributed, this function passes the file handle to the simulator, which issues a close in the host file system. As distributed, this function returns a null pointer.

There is no support for environment variables. None long lseek int handle, long offset, int origin ; handle offset origin refers to an opened file the number of characters from the origin the position from which to start the seek.

Returns the offset, in characters, of the new position from the beginning of the file. A return value of -1L indicates an error. This helper function is called by the Standard C Library functions fgetpos , ftell , fseek , fsetpos, and rewind.

As distributed, the parameters are passed to the host file system through the simulator. The return value is the value returned by the host file system. If successful, the function returns a file handle, a small positive integer. The access flag is a union of one of the following access methods and zero or more access qualifiers: 0 Open a file for reading.

The following access qualifiers must be supported: 0x Move file pointer to end of file before every write operation. The mode parameter may be one of the following: 0x Reading only permitted.

This helper function is called by the Standard C Library functions fopen and freopen. Returns the number of characters read, which may be less than len if there are fewer than len characters left in the file or if the file was opened in text mode, in which case each carriage return-linefeed CR-LF pair is replaced with a single linefeed character.

Only the single linefeed character is counted in the return value. The replacement does not affect the file pointer. If the function tries to read at end of file, it returns 0. If the handle is invalid, or the file is not open for reading, or the file is locked, the function returns This helper function is called by the Standard C Library functions fgetc , fgets , fread , and gets.

Returns 0 if it is successful. On an error, the function returns a nonzero value. This is a helper function called by the Standard C Library function malloc. If brk returns -1, so does this function. Otherwise, the function returns See the description of brk. As distributed, this function acts as a stub or placeholder for your function. If s is not NULL, an error message is written to stdout and the program will reset; otherwise, a value of -1 is returned.

There is no error return. As distributed, if timer2 is not enabled, it is enabled in bit mode. The return value is the current value of the bit timer2 register. Except in very rare cases, this return value is not the elapsed time in seconds. If successful, write returns the number of characters actually written.

If the actual space remaining on the disk is less than the size of the buffer the function is trying to write to the disk, write fails and does not flush any of the buffer's contents to the disk.

If the file is opened in text mode, each linefeed character is replaced with a carriage return linefeed pair in the output. The replacement does not affect the return value. This is a helper function called by the Standard C Library function fflush. Built-in functions give the C programmer access to assembler operators or machine instructions that are currently only accessible using inline assembly, but are sufficiently useful that they are applicable to a broad range of applications.

Built-in functions are coded in C source files syntactically like function calls, but they are compiled to assembly code that directly implements the function, and do not involve function calls or library routines. View More. Recent Blog Posts. Unread PMs. Forum Themes Elegant Mobile. Essentials Only Full Version. Starting Member. Thanks Cime. Super Member. Hi, No problem, please send the payment first. It is always better to post the code you have, and then suggestions can be made to your code.

This way, you "understand" why the changes were suggested. Configuration Bits System clock source can be provided by: 1. Timer 2 and 3 can be incorporated together to form a bit timer.

Prescale is the ratio between timer counts and system clock counts. Prescales of , , and are available. Timers may be used to implement free time clock or mesaure time. Setting priority to 0 disable a specific interrupt. Level 7 interrupt has the highest priority. Current priority level is stored in IPL.

Setting IPL to 7 disables all interrupts except traps. DSN is needed. On the first rising edge of the start bit, the target board starts the timer. The measured period corresponds to 8 bits transmitted at a baud rate uxbrg.

Standard communication speed includes 1. Standard speed mode: kHz 2. Fast speed mode: kHz 3. High speed mode: 3. The maximum speed attainable is 1MHz.

A maximum of kps of sampling rate when using auto sampling mode. The ADC module will be set to interrupt when the specified channels are updated.

Scan input is enabled, and the module will generate an interrupt when all selected channels have been scanned. Since the lowest register will always be filled first, when some of the channels are not scanned i. These pins are shared with port D.

Suggested range of operation is 2Hz to kHz. The following code uses timer 2 for all 8 channels. To introduced delay to the PWM signals, the signal from selected channels may be made to pass through a series of inverters e. This adds propagation delay to the signal. However, as propagration delay of logic gates depends on applied voltage, temperature and load capacitance, the accuracy is low and performance is poor.

For accurate delay, delay lines may be used, but they are expensive. Table 6. Build-in Library Some assembler operators can only be accessed by inline assembly code, for example, 1. Manuipulation of accumulators A and B add, sub, mul, divide, shift, clear, square Bit toggling Access to psv program space visiblity page and offset Access to table instruction page and offset Built-in functions are written as C-like function calls to utilize these assembler operators.

The producer can download a program even when the chip is on the target board. However, ICSP requires an external programmer. To allow the user to change the program after production but without the need of an external programmer, bootloader becomes useful. Bootloader is a small program installed via ICSP. Everytime the device is reset, the bootloader is run first. The bootloader first detects the default serial channel whether the user wishes to download a new program to the device.

If so, the bootloader will pause there, and wait for the user to download the hex file from the PC. The hex file is written to the device via RTSP instructions in the bootloader. If a new download is not necessary, the bootloader redirects to the previously installed user's program. The disadvantage of bootloaders is that they consume some of the memory of the device.

The bootloader hereafter called dsPicBootloader employs the following settings: 1. Use U2ART channel 2. The project for Linux environment is currently suspended. The programmer supports both Linux and Windows environments, and may be used as a substitution for the official programmer developed by ingenia. The programmer has the following specification and limitations: 1.



0コメント

  • 1000 / 1000