Download CC8E C Compiler for the PIC18 Devices

Transcript
CC8E C Compiler
B Knudsen Data
A warning is printed when there is ONE call to a unsigned integer math library function. The warning can
be disabled by the -wm command line option.
NOTE that the inline type modifier is currently IGNORED, except for the math operations.
Detection of multiple inline math integer operations
The compiler will print a warning when detecting more than one inline math integer operation of the
same type. Including a math library will save code, but execute slightly slower. Note that assembly code
inspection and type casts are sometimes needed to reduce the number of library functions inserted.
The warning can be disabled by the -wi command line option.
Fixed point example
#pragma chip PIC18C242
#include "math24x.h"
uns16 data;
fixed16_8 tx, av, mg, a, vx, prev, kp;
void main(void)
{
vx = 3.127;
tx += data;
// automatic type cast
data = kp;
// assign integer part
if (tx < 0)
tx = -tx;
// make positive
av = tx/20.0;
mg = av * 1.25;
a = mg * 0.98;
// 0.980469, error: 0.000478
prev = vx;
vx = a/5.0 + prev;
kp = vx * 0.036;
// 0.03515626, error: 0.024
kp = vx / (1.0/0.036); // 27.7773437
}
CODE: 266 code words including library (129)
Floating point example
CODE: 596 code words including library (424). The statements are identical to the above fixed point
example to enable code size comparison.
#pragma chip PIC18C242
#include "math24f.h"
uns16 data;
float tx, av, mg, a, vx, prev, kp;
void main(void)
{
InitFpFlags();
vx = 3.127;
tx += data;
data = kp;
if ( tx < 0)
tx = -tx;
av = tx/20.0;
mg = av * 1.25;
// enable rounding as default
// automatic type cast
// assign integer part
// make positive
66