05.08.2013 Views

Ming Hsieh Department of Electrical Engineering Programming the ...

Ming Hsieh Department of Electrical Engineering Programming the ...

Ming Hsieh Department of Electrical Engineering Programming the ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

if ( RAMSel == 2) {<br />

VidMode = 6;<br />

}<br />

Bits are assigned in <strong>the</strong> “struct” in <strong>the</strong> order LSB (bit 0) to MSB (bit 7.) It is necessary to list all eight<br />

bits in <strong>the</strong> data structure but a name does not have be assigned to all <strong>the</strong> bits, just <strong>the</strong> ones where you want<br />

to group <strong>the</strong>m toge<strong>the</strong>r, or to refer to it by some name o<strong>the</strong>r than <strong>the</strong> one defined by <strong>the</strong> system.<br />

The multi-bit quantities are oriented <strong>the</strong> same as <strong>the</strong> full register as far as <strong>the</strong> least significant and most<br />

significant bits. In <strong>the</strong> example above, bit 3 is <strong>the</strong> MSB and bit 1 is <strong>the</strong> LSB <strong>of</strong> <strong>the</strong> VidMode group <strong>of</strong> three<br />

bits. The instruction “Vidmode = 6” will result in a one stored in PTB3 and PTB2, and a zero stored in<br />

PTB1. This is important to remember when deciding how to assign functions to <strong>the</strong> different bits.<br />

Bits can still be referred to in <strong>the</strong> program with <strong>the</strong> names defined for <strong>the</strong>m by <strong>the</strong> standard header files.<br />

For example, if we use <strong>the</strong> definition above, <strong>the</strong>n <strong>the</strong> following lines <strong>of</strong> code<br />

PTB_PTB6 = 1;<br />

PTB_PTB7 = 1;<br />

do <strong>the</strong> same thing as<br />

RAMSel = 3;<br />

5.11 Floating Point<br />

The CodeWarrior compiler can generate code that does floating point calculations. This allows programs to<br />

be written in a style very similar to how it would be written for a larger computer. However programmers<br />

should keep in mind that <strong>the</strong> JL16 processor does not contain any floating point arithmetic hardware so<br />

all floating point calculations are implemented by doing multiple 8-bit integer arithmetic operations. The<br />

resulting code can be relatively slow to execute. Programs should not use floating point unless <strong>the</strong>re are<br />

compelling reasons to do so. Whenever possible, integer arithmetic should be used instead.<br />

When floating point arithmetic is used, CodeWarrior will add library routines that do <strong>the</strong> floating point<br />

operations to <strong>the</strong> final binary program. This can dramatically increase <strong>the</strong> size <strong>of</strong> <strong>the</strong> program. For example,<br />

a program that does a few floating point multiplies, adds and square root operations will cause <strong>the</strong> executable<br />

code to be about 4KB larger than without <strong>the</strong> floating point operations. This can be a problem if <strong>the</strong> program<br />

is close to filling out all <strong>the</strong> ROM space in <strong>the</strong> processor.<br />

If using floating point, do not use 64-bit “double” variables unless absolutely necessary since doing 64-bit<br />

operations requires a larger number <strong>of</strong> 8-bit operations that must be done for each floating point operations.<br />

5.12 Standard C Library<br />

CodeWarrior includes a standard C library that contains many <strong>of</strong> <strong>the</strong> routines that programmers are used<br />

to having available to use in <strong>the</strong>ir programs. Routines like “sprintf” and “sscanf” can be used <strong>the</strong> same<br />

way as on larger systems. Routines that would do I/O operations are not usable since <strong>the</strong> system does not<br />

have a file system or o<strong>the</strong>r I/O capability.<br />

The CodeWarrior linker will include any needed routines from <strong>the</strong> standard C library in <strong>the</strong> binary output<br />

when <strong>the</strong> program is compiled and linked. Programmers must keep in mind that <strong>the</strong>se can significantly<br />

increase <strong>the</strong> size <strong>of</strong> <strong>the</strong>ir final executable program. For example, using “sprintf” in a program to create<br />

formatted strings <strong>of</strong> characters will cause about 3.5KB <strong>of</strong> extra code to be included in <strong>the</strong> final executable<br />

program.<br />

5.13 Including Assembly Language Code in C<br />

You can write assembly instructions and call assembly language routines from within your C code by using<br />

<strong>the</strong> “asm{ }” construct. Below are some guidelines for writing assembly code.<br />

• Within <strong>the</strong> brackets you may write one assembly instruction per line.<br />

• Labels must be defined on <strong>the</strong>ir own line.<br />

EE 459Lx, Rev. 5/29/13 10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!