Getting Started

(lily) #1

Chapter 6: C Functions and Program Structures


nctions, which use extra RAM. Also macros create in-line code that can be
rocessor overhead). And finally, macros don’t
es:

double da = 12;
double db = 14;

tion, the parameters require a data type such as int or double,
there is casting, but that’s another topic).

on

amilies that differ only in a few features, pinouts,
ons. You can write C code for the entire family if
hings that differ. Let’s say that SuprMic16 uses pins
ansmit and receive, while SuprMic8 uses pins 6 and 14,
and 2. We put the following in our SuprMic.h file:

define RXD 13
cX == 8
TXD 6
# define RXD 14
uprMicX = 4

or SuprMicX TXD and RXD pins."

rMic8 in our Killer Cylon Robot project we should put the

fu
faster than function calls (no p
require formally declared data typ


double dc = 7;
double dd = 0;


dd = larger( (db-da), dc);


If larger() was a func
but couldn’t use both (okay,


Conditional Inclusi


Often microcontrollers come in f
memory size, and register locati
you substitute alias for the t
12 and 13 for USART tr
and SuprMic4 uses pins 1


#if SuprMicX == 16


define TXD 12



#elif SuprMi


define


#elif S


define TXD 1


define RXD 2


#else


error “No definition f


#endif


If we are using the Sup
following in our CylonKillerRobot.h file:


#ifndef SuprMicX
# define SuprMicX = 8
# include <SuprMic.h>
Free download pdf