📄 chapter 1 program structure -- valvano.htm
字号:
<DIR>
<P><CODE>void OpenSCI(void)<BR>{
<BR>BAUD=<BR> 0x30;<BR>SCCR2=<BR> 0x0C;<BR>}</CODE></P></DIR>
<P>At this point I will warn the reader, just because C allows such syntax, it
does not mean it is desirable. After much experience you will develop a
programming style that is easy to understand. Although spaces, tabs, and line
breaks are syntatically equivalent, their proper usage will have a profound
impact on the readability of your software. For more information on programming
style see chapter 2 of <U>Embedded Microcomputer Systems: Real Time
Interfacing</U> by Jonathan W. Valvano, Brooks/Cole Publishing Co., 1999.</P>
<P>A <I>token</I> in C can be a user defined name (e.g., the variable
<CODE><B>Info</B></CODE> and function <CODE><B>OpenSCI</B></CODE>) or a
predefined operation (e.g., <CODE><B>* unsigned while</B></CODE>). Each token
must be contained on a single line. We see in the above example that tokens can
be separated by white spaces (space, tab, line break) or by the special
characters, which we can subdivide into punctuation marks (Table 1-1) and
operations (Table 1-2). Punctuation marks (<A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#SEMICOLONS">semicolons</A>,
<A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#COLONS">colons</A>,
<A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#COMMAS">commas</A>,
<A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#APOSTROPHES">apostrophes</A>,
<A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#QUOTATIONS">quotation
marks</A>, <A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#BRACES">braces</A>,
<A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#BRACKETS">brackets</A>,
and <A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#PARENTHESES">parentheses</A>)
are very important in C. It is one of the most frequent sources of errors for
both the beginning and experienced programmers.</P>
<P>
<TABLE cellSpacing=0 border=0>
<TBODY>
<TR>
<TD vAlign=top width="17%">punctuation </TD>
<TD vAlign=top width="83%">Meaning</TD></TR>
<TR>
<TD vAlign=top width="17%"><CODE>;</CODE></TD>
<TD vAlign=top width="83%"><A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#SEMICOLONS">End
of statement</A></TD></TR>
<TR>
<TD vAlign=top width="17%"><CODE>:</CODE></TD>
<TD vAlign=top width="83%"><A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#COLONS">Defines
a label</A></TD></TR>
<TR>
<TD vAlign=top width="17%"><CODE>,</CODE></TD>
<TD vAlign=top width="83%"><A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#COMMAS">Separates
elements of a list</A></TD></TR>
<TR>
<TD vAlign=top width="17%"><CODE>( )</CODE></TD>
<TD vAlign=top width="83%"><A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#PARENTHESES">Start
and end of a parameter list</A></TD></TR>
<TR>
<TD vAlign=top width="17%"><CODE>{ }</CODE></TD>
<TD vAlign=top width="83%"><A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#BRACES">Start
and stop of a compound statement</A></TD></TR>
<TR>
<TD vAlign=top width="17%"><CODE>[ ]</CODE></TD>
<TD vAlign=top width="83%"><A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#BRACKETS">Start
and stop of a array index</A></TD></TR>
<TR>
<TD vAlign=top width="17%"><CODE>" "</CODE></TD>
<TD vAlign=top width="83%"><A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#QUOTATIONS">Start
and stop of a string</A></TD></TR>
<TR>
<TD vAlign=top width="17%"><CODE>' '</CODE></TD>
<TD vAlign=top width="83%"><A
href="http://www.ece.utexas.edu/~valvano/embed/chap2/chap2.htm#APOSTROPHES">Start
and stop of a character constant</A></TD></TR></TBODY></TABLE></P>
<P><I>Table 1-1: Special characters can be punctuation marks</I></P>
<P>The next table shows the single character operators. For a description of
these operations, see <A
href="http://www.ece.utexas.edu/~valvano/embed/chap5/chap5.htm">Chapter
5</A>.</P>
<P>
<TABLE cellSpacing=0 border=0>
<TBODY>
<TR>
<TD vAlign=top width="15%">operation </TD>
<TD vAlign=top width="85%">Meaning</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>=</CODE></TD>
<TD vAlign=top width="85%">assignment statement</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>@</CODE></TD>
<TD vAlign=top width="85%">address of</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>?</CODE></TD>
<TD vAlign=top width="85%">selection</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE><</CODE></TD>
<TD vAlign=top width="85%">less than</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>></CODE></TD>
<TD vAlign=top width="85%">greater than</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>!</CODE></TD>
<TD vAlign=top width="85%">logical not (true to false, false to
true)</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>~</CODE></TD>
<TD vAlign=top width="85%">1's complement</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>+</CODE></TD>
<TD vAlign=top width="85%">addition</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>-</CODE></TD>
<TD vAlign=top width="85%">subtraction</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>*</CODE></TD>
<TD vAlign=top width="85%">multiply or pointer reference</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>/</CODE></TD>
<TD vAlign=top width="85%">divide</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>%</CODE></TD>
<TD vAlign=top width="85%">modulo, division remainder</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>|</CODE></TD>
<TD vAlign=top width="85%">logical or</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>&</CODE></TD>
<TD vAlign=top width="85%">logical and, or address of</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>^</CODE></TD>
<TD vAlign=top width="85%">logical exclusive or</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>.</CODE></TD>
<TD vAlign=top width="85%">used to access parts of a
structure</TD></TR></TBODY></TABLE></P>
<P><I>Table 1-2: Special characters can be operators</I></P>
<P>The next table shows the operators formed with multiple characters. For a
description of these operations, see <A
href="http://www.ece.utexas.edu/~valvano/embed/chap5/chap5.htm">Chapter
5</A>.</P>
<P>
<TABLE cellSpacing=0 border=0>
<TBODY>
<TR>
<TD vAlign=top width="15%">operation </TD>
<TD vAlign=top width="85%">Meaning</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>==</CODE></TD>
<TD vAlign=top width="85%">equal to comparison</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE><=</CODE></TD>
<TD vAlign=top width="85%">less than or equal to</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>>=</CODE></TD>
<TD vAlign=top width="85%">greater than or equal to</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>!=</CODE></TD>
<TD vAlign=top width="85%">not equal to</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE><<</CODE></TD>
<TD vAlign=top width="85%">shift left</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>>></CODE></TD>
<TD vAlign=top width="85%">shift right</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>++</CODE></TD>
<TD vAlign=top width="85%">increment</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>--</CODE></TD>
<TD vAlign=top width="85%">decrement</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>&&</CODE></TD>
<TD vAlign=top width="85%">boolean and</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>||</CODE></TD>
<TD vAlign=top width="85%">boolean or</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>+=</CODE></TD>
<TD vAlign=top width="85%">add value to</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>-=</CODE></TD>
<TD vAlign=top width="85%">subtract value to</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>*=</CODE></TD>
<TD vAlign=top width="85%">multiply value to</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>/=</CODE></TD>
<TD vAlign=top width="85%">divide value to</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>|=</CODE></TD>
<TD vAlign=top width="85%">or value to</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>&=</CODE></TD>
<TD vAlign=top width="85%">and value to</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>^=</CODE></TD>
<TD vAlign=top width="85%">exclusive or value to</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE><<=</CODE></TD>
<TD vAlign=top width="85%">shift value left</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>>>=</CODE></TD>
<TD vAlign=top width="85%">shift value right</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>%=</CODE></TD>
<TD vAlign=top width="85%">modulo divide value to</TD></TR>
<TR>
<TD vAlign=top width="15%"><CODE>-></CODE></TD>
<TD vAlign=top width="85%">pointer to a structure</TD></TR></TBODY></TABLE></P>
<P><I>Table 1-3: Multiple special characters also can be operators</I></P>
<P><FONT face="Times New Roman,Times">Although the operators will be covered in
detail in Chapter 9, the following section illustrates some of the common
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -