Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Microcontrollers: High-Performance Systems and Programming
Nội dung xem thử
Mô tả chi tiết
Microcontrollers
HIGH-PERFORMANCE SYSTEMS
AND PROGRAMMING
K16291_FM.indd 1 9/24/13 11:25 AM
CRC Press is an imprint of the
Taylor & Francis Group, an informa business
Boca Raton London New York
Julio Sanchez
Eastern Florida State College
Maria P. Canton
Brevard Public Schools
Microcontrollers
HIGH-PERFORMANCE SYSTEMS
AND PROGRAMMING
K16291_FM.indd 3 9/24/13 11:25 AM
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
© 2014 by Taylor & Francis Group, LLC
CRC Press is an imprint of Taylor & Francis Group, an Informa business
No claim to original U.S. Government works
Version Date: 20130923
International Standard Book Number-13: 978-1-4665-6668-2 (eBook - PDF)
This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been
made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright
holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this
form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may
rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the
publishers.
For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://
www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923,
978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For
organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for
identification and explanation without intent to infringe.
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
Ta ble of Con tents
Pref ace xx
Chap ter 1 Microcontrollers for Em bed ded Sys tems 1
1.1 Em bed ded Sys tems 1
1.2 Micro chip PIC 1
1.2.1 PIC Ar chi tec ture 2
1.2.2 Pro gram ming the PIC 2
PIC Pro gram mers 3
De vel op ment Boards 4
1.3 PIC Ar chi tec ture 4
1.3.1 Base line PIC Fam ily 5
PIC10 de vices 6
PIC12 De vices 7
1.3.2 Mid-Range Fam ily 9
PIC14 De vices 9
PIC16 De vices 9
1.3.3 High-Per for mance PICs and DSPs 10
Dig i tal Sig nal Pro ces sor 11
Analog-to-Dig i tal 12
Chap ter 2 PIC18 Ar chi tec ture 13
2.1 PIC18 Fam ily Over view 13
2.1.1 PIC18FXX2 Group 14
2.1.2 PIC18FXX2 De vice Group Over view 15
2.1.3 PIC18F4X2 Block Di a gram 16
2.1.4 Cen tral Pro cess ing Unit 17
Sta tus Reg is ter 17
Pro gram Coun ter Reg is ter 17
Hard ware Mul ti plier 18
In ter rupts 18
2.1.5 Spe cial CPU Fea tures 19
Watch dog Timer 20
Wake-Up by In ter rupt 21
Low Volt age De tec tion 21
De vice Con fig u ra tion 21
2.2 Mem ory Or ga ni za tion 22
2.2.1 Pro gram Mem ory 22
v
2.2.2 18FXX2 Stack 23
Stack Op er a tions 23
Fast Reg is ter Stack 24
In struc tions in Mem ory 25
2.2.3 Data Mem ory 25
2.2.4 Data EEPROM Mem ory 27
2.2.5 In di rect Ad dress ing 28
2.3 PIC18FXX2 Os cil la tor 29
2.3.1 Os cil la tor Op tions 29
Crys tal Os cil la tor and Ce ramic Res o na tor 29
RC Os cil la tor 30
Ex ter nal Clock In put 31
Phase Locked Loop Os cil la tor Mode 31
2.4 Sys tem Re set 31
2.4.1 Re set Ac tion 32
Power-On Re set (POR) 33
Power-Up Timer (PWRT) 33
Os cil la tor Start-Up Timer (OST) 33
PLL Lock Time-Out 33
Brown-Out Re set (BOR) 33
Time-Out Se quence 33
2.5 I/O Ports 34
2.5.1 Port Reg is ters 34
2.5.2 Par al lel Slave Port 35
2.6 In ter nal Mod ules 35
2.6.1 PIC18FXX2 Mod ules 35
Chap ter 3 Pro gram ming Tools and Soft ware 37
3.1 En vi ron ment 37
3.1.1 Em bed ded Sys tems 37
3.1.2 High- and Low-Level Lan guages 38
3.1.3 Lan guage-Spe cific Soft ware 40
3.2 Micro chip's MPLAB 40
3.2.1 MPLAB X 40
3.2.2 De vel op ment Cy cle 40
3.3 An In te grated De vel op ment En vi ron ment 41
3.3.1 In stall ing MPLAB 42
3.3.2 Cre at ing the Pro ject 43
3.3.3 Set ting the Pro ject Build Op tions 45
3.3.4 Adding a Source File 47
3.3.5 Build ing the Pro ject 48
3.3.6 .hex File 48
3.3.7 Quickbuild Op tion 50
3.4 MPLAB Sim u la tors and Debuggers 50
3.4.1 MPLAB SIM 51
Us ing Break points 51
Watch Win dow 52
Sim u la tor Trace 52
3.4.2 MPLAB Stim u lus 54
Stim u lus Di a log 54
3.4.3 MPLAB Hard ware Debuggers 55
vi Ta ble of Con tents
3.4.4 An Im pro vised Debugger 56
3.5 De vel op ment Pro gram mers 56
3.5.1 Micro chip PICkit 2 and PICkit 3 58
3.5.2 Micropro USB PIC Pro gram mer 60
3.5.3 MPLAB ICD 2 and ICD 3 In-Cir cuit Debuggers/Pro gram mers 60
3.6 Test Cir cuits and De vel op ment Boards 61
3.6.1 Com mer cial De vel op ment Boards 61
3.6.2 Cir cuit Pro to type 63
3.6.3 Bread board 64
Lim i ta tions of Bread boards 65
Breadboarding Tools and Tech niques 66
3.6.4 Wire Wrap ping 67
3.6.5 Perfboards 67
3.6.6 Printed Cir cuit Boards 68
Chap ter 4 As sem bly Lan guage Pro gram 71
4.1 As sem bly Lan guage Code 71
4.1.1 A Cod ing Tem plate 71
Pro gram Header 73
Pro gram En vi ron ment Di rec tives 73
Con fig u ra tion Bits 73
Er ror Mes sage Level Con trol 74
Vari ables and Con stants 74
Code Area and In ter rupts 74
4.1.2 Pro gram ming Style 74
Source File Com ments 75
4.2 De fin ing Data El e ments 75
4.2.1 equ Di rec tive 76
4.2.2 cblock Di rec tive 76
4.2.3 Ac cess to Banked Mem ory 77
4.3 Nam ing Con ven tions 77
4.3.1 Reg is ter and Bit Names 77
4.4 PIC 18Fxx2 In struc tion Set 79
4.4.1 Byte-Ori ented In struc tions 80
4.4.2 Bit-Ori ented In struc tions 80
4.4.3 Lit eral In struc tions 80
4.4.4 Con trol In struc tions 80
Chap ter 5 PIC18 Pro gram ming in C Lan guage 85
5.1 C Com pil ers 85
5.1.1 C ver sus As sem bly Lan guage 85
5.1.2 MPLAB C18 86
5.2 MPLAB C18 In stal la tion 86
5.2.1 MPLAB Soft ware Com po nents 87
5.2.2 Con fig u ra tion Op tions 88
5.2.3 Sys tem Re quire ments 89
5.2.4 Ex e cu tion Flow 90
5.3 C Com piler Pro ject 91
5.3.1 Cre at ing the Pro ject 91
Ta ble of Con tents vii
Se lect Hard ware De vice 92
Se lect the Lan guage Toolsuite 92
Cre ate a New Pro ject 93
Add Files to the Pro ject 95
5.3.2 Se lect ing the Build Di rec tory 96
5.4 A First Pro gram in C 98
5.4.1 Source Code Anal y sis 99
main() Func tion 100
Lo cal Func tions 101
Chap ter 6 C Lan guage in an Em bed ded En vi ron ment 103
6.1 MPLAB C18 Sys tem 103
6.1.1 PIC18 Ex tended Mode 104
6.2 MPLAB C18 Li brar ies 104
6.2.1 Start-Up Rou tines 104
6.2.2 On line Help for C18 and Li brar ies 105
6.3 Pro ces sor-In de pend ent Li brar ies 106
6.3.1 Gen eral Soft ware Li brary 106
Char ac ter Clas si fi ca tion Func tions 107
Data Con ver sion Func tions 107
Mem ory and String Ma nip u la tion Func tions 108
De lay Func tions 110
Re set Func tions 111
Char ac ter Out put Func tions 112
6.4 Pro ces sor-Spe cific Li brar ies 115
6.4.1 Hard ware Pe riph eral Li brary Func tions 115
6.4.2 Soft ware Pe riph er als Li brary Func tions 116
6.4.3 Mac ros for Inline As sem bly 116
6.4.4 Pro ces sor-Spe cific Header Files 117
6.5 Math Li brar ies 118
6.5.1 ANSI-IEEE 754 Bi nary Float ing-Point Stan dard 118
Encodings 119
Round ing 119
6.5.2 Stan dard Math Li brary Func tions 120
6.5.3 Float ing-Point Math Sam ple Pro gram 120
6.6 C18 Lan guage Spe cif ics 122
6.6.1 C18 In te ger Data Types 122
6.6.2 C18 Float ing-Point Data Types 122
6.6.3 Endianness 123
6.6.4 Stor age Classes 123
6.6.5 Static Func tion Ar gu ment 123
6.6.6 Stor age Qual i fi ers 123
far and near Qual i fi ers 123
rom and ram Qual i fi ers 124
Chap ter 7 Pro gram ming Sim ple In put and Out put 125
7.1 Port-Con nected I/O 125
7.1.1 A Sim ple Cir cuit and Code 125
7.1.2 Cir cuit Sche mat ics 125
7.1.3 As sem bler Sim ple I/O Pro gram 126
viii Ta ble of Con tents
7.1.4 As sem bler Source Code Anal y sis 129
Com mand Mon i tor ing Loop 129
Ac tion on the LEDs 130
A De lay Rou tine 130
7.2 C Lan guage Sim ple I/O Pro gram 131
7.2.1 C Source Code Anal y sis 132
main() Func tion 133
7.3 Seven-Seg ment LED Pro gram ming 134
7.3.1 Com puted Goto 135
7.3.2 As sem bler Seven-Seg ment LED Pro gram 136
Ac cess Bank Op er a tion 136
Port A for Dig i tal Op er a tion 137
DIP Switch Pro cess ing 138
Seven-Seg ment Code with Com puted Goto 139
7.3.3 As sem bler Ta ble Lookup Sam ple Pro gram 140
7.4 C Lan guage Seven-Seg ment LED Pro grams 141
7.4.1 Code Se lec tion by Switch Con struct 142
7.4.2 Code Se lec tion by Ta ble Lookup 142
7.5 A Dem on stra tion Board 143
7.6.1 Power Sup ply 145
Volt age Reg u la tor 145
Chap ter 8 In ter rupts 147
8.1 In ter rupt Mech a nism 147
8.2 PIC18 In ter rupt Sys tem 147
8.2.1 Hard ware Sources 148
8.2.2 In ter rupt Con trol and Sta tus Reg is ters 148
INTCON Reg is ters 149
PIE Reg is ters 151
PIR Reg is ters 152
IPR Reg is ters 152
8.2.3 In ter rupt Pri or i ties 154
High-Pri or ity In ter rupts 154
Low-Pri or ity In ter rupts 155
An In ter rupt In ter rupt ing An other One 155
8.2.4 Con text Sav ing Op er a tions 155
Con text Sav ing during Low-Pri or ity In ter rupts 156
8.3 Port B In ter rupts 157
8.3.1 Port B Ex ter nal In ter rupt 158
8.3.2 INT0 In ter rupt Demo Pro gram 158
cblock Di rec tive 158
Vectoring the In ter rupt 159
Ini tial iza tion 160
Setup INT0 160
Pro gram Fore ground 161
In ter rupt Ser vice Rou tine 161
Switch Debouncing 162
In ter rupt Ac tion 162
8.3.3 Port B Line Change In ter rupt 163
Reentrant In ter rupts 164
Mul ti ple Ex ter nal In ter rupts 165
Ta ble of Con tents ix
8.3.4 Port B Line Change In ter rupt Demo Pro gram 165
Set ting Up the Line Change In ter rupt 165
In ter rupt Ser vice Rou tine 166
8.4 Sleep Mode and In ter rupts 168
8.4.1 Wake-Up from SLEEP 169
8.4.2 Sleep_Demo Pro gram 170
8.5 In ter rupt Pro gram ming in C Lan guage 171
8.5.1 In ter rupt Ac tion 171
Con text in the Stack 172
In ter rupt Data 172
8.5.2 In ter rupt Pro gram ming in C18 173
Sleep Mode and RB0 In ter rupt Demo Pro gram 174
Port B In ter rupt on Change Demo Pro gram 176
Chap ter 9 De lays, Coun ters, and Tim ers 179
9.1 PIC18 Fam ily Tim ers 179
9.2 De lay Tim ers 179
9.2.1 Power-Up Timer (PWRT) 179
9.2.2 Os cil la tor Start-Up Timer (OST) 180
9.2.3 Phase Locked Loop (PLL) 180
Power-Up De lay Sum mary 181
9.2.4 Watch dog Timer 181
Watch dog Timer Uses 181
9.3 Hard ware Timer-Coun ters 182
9.4 Timer0 Mod ule 182
9.4.1 Timer0 Ar chi tec ture 184
16-bit Mode Op er a tion 184
Timer and Coun ter Modes 185
Timer0 In ter rupt 185
Ex ter nal Clock Source 185
Timer0 Prescaler 186
9.4.2 Timer0 as a De lay Timer 186
Long De lay Loops 187
De lay Ac cu racy Is sues 188
Black–Ammerman Method 188
De lays with 16-Bit Timer0 189
9.4.3 Coun ter and Timer Pro gram ming 189
Pro gram ming a Coun ter 190
Timer0_as_Coun ter.asm Pro gram 190
A Timer/Coun ter Test Cir cuit 191
Timer0 _De lay.asm Pro gram 191
A Vari able Time-Lapse Rou tine 193
Timer0_VarDelay.asm Pro gram 193
In ter rupt-Driven Timer 196
9.5 Other Timer Mod ules 199
9.5.1 Timer1 Mod ule 199
Timer1 in Timer Mode 200
Timer1 in Syn chro nized Coun ter Mode 201
Ex ter nal Clock In put Tim ing in Syn chro nized Mode 201
Timer1 Read and Write Op er a tions 201
16-bit Mode Timer1 Write 201
x Ta ble of Con tents
16-Bit Read-Mod ify-Write 202
Read ing and Writ ing Timer1 in Two 8-bit Op er a tions 202
9.5.2 Timer2 Mod ule 203
Timer Clock Source 204
TMR2 and PR2 Reg is ters 204
Prescaler and Postscaler 205
Timer2 Ini tial iza tion 205
9.5.3 Timer3 Mod ule 205
Timer3 in Timer Mode 207
Timer3 in Syn chro nized Coun ter Mode 207
Ex ter nal Clock In put Tim ing 208
Timer3 in Asyn chron ous Coun ter Mode 208
Ex ter nal Clock In put Tim ing with Unsynchronized Clock 208
Timer3 Read ing and Writ ing 208
Writ ing in 16-Bit Mode 208
16-bit Read-Mod ify-Write Op er a tion 209
Read ing in Asyn chron ous Coun ter Mode 209
Timer1 Os cil la tor in Timer3 210
9.6 C-18 Timer Func tions 210
9.6.1 CloseTimerx Func tion 210
9.6.2 OpenTimerx Func tion 211
9.6.3 ReadTimerx Func tion 211
9.6.4 WriteTimerx Func tion 212
9.7 Sam ple Pro grams 212
9.7.1 Timer0_as_Coun ter pro gram 212
9.7.2 Timer0_De lay Pro gram 215
9.7.3 Timer0_VarDelay Pro gram 216
9.7.4 Timer0_VarInt Pro gram 220
9.7.5 C_Timer_Show Pro gram 224
Chap ter 10 Data EEPROM 227
10.1 EEPROM on the PIC18 Microcontrollers 227
10.1.2 On-Board Data EEPROM 227
10.2 EEPROM Pro gram ming 228
10.2.1 Read ing EEPROM Data 228
10.2.2 Writ ing EEPROM Data 230
10.3 Data EEPROM Pro gram ming in C Lan guage 231
10.3.1 EEPROM Li brary Func tions 232
10.3.2 Sam ple Code 232
10.4 EEPROM Dem on stra tion Pro grams 233
10.4.1 EEPROM_to_7Seg Pro gram 233
10.4.2 C_EEPROM_Demo Pro gram 237
Chap ter 11 Liq uid Crys tal Dis plays 239
11.1 LCD 239
11.1.1 LCD Fea tures and Ar chi tec ture 239
11.1.2 LCD Func tions and Com po nents 240
In ter nal Reg is ters 240
Busy Flag 240
Ad dress Coun ter 240
Ta ble of Con tents xi
Dis play Data RAM (DDRAM) 240
Char ac ter Gen er a tor ROM (CGROM) 241
Char ac ter Gen er a tor RAM (CGRAM) 241
Tim ing Gen er a tion Cir cuit 241
Liq uid Crys tal Dis play Driver Cir cuit 242
Cur sor/Blink Con trol Cir cuit 242
11.1.3 Con nec tiv ity and Pin Out 242
11.2 In ter fac ing with the HD44780 243
11.2.1 Busy Flag and Timed De lay Op tions 244
11.2.2 Con trast Con trol 245
11.2.3 Dis play Backlight 245
11.2.4 Dis play Mem ory Map ping 245
11.3 The HD44780 In struc tion Set 247
11.3.1 In struc tion Set Over view 247
Clear ing the Dis play 248
Re turn Home 248
En try Mode Set 248
Dis play and Cur sor ON/OFF 248
Cur sor/Dis play Shift 248
Func tion Set 248
Set CGRAM Ad dress 249
Set DDRAM Ad dress 249
Read Busy Flag and Ad dress Reg is ter 249
Write data 249
Read data 250
11.3.2 18F452 8-Bit Data Mode Cir cuit 250
11.4 LCD Pro gram ming 251
11.4.1 De fin ing Con stants and Vari ables 252
Con stants 252
11.4.2 Us ing MPLAB Data Di rec tives 253
Data Def i ni tion in Ab so lute Mode 253
Relocatable Code 254
Is sues with In i tial ized Data 254
11.4.3 LCD Ini tial iza tion 255
Re set Func tion 255
Ini tial iza tion Com mands 256
Func tion Pre set Com mand 256
Func tion Set Com mand 256
Dis play Off 257
Dis play and Cur sor On 257
Set En try Mode 258
Cur sor and Dis play Shift 258
Clear Dis play 258
11.4.4 Aux il iary Op er a tions 259
Time De lay Rou tine 259
Puls ing the E Line 260
Read ing the Busy Flag 261
Bit Merg ing Op er a tions 262
11.4.5 Text Data Stor age and Dis play 264
Gen er at ing and Stor ing a Text String 265
Data in Pro gram Mem ory 265
Dis play ing the Text String 266
Sam ple Pro gram LCD_18F_MsgFlag 268
xii Ta ble of Con tents
11.5 Data Com pres sion Tech niques 278
11.5.1 4-Bit Data Trans fer Mode 279
11.5.2 Pre serv ing Port Data 279
11.5.3 Mas ter/Slave Sys tems 280
11.5.4 4-Bit LCD In ter face Sam ple Pro grams 281
11.6 LCD Pro gram ming in C18 291
11.6.1 Ed it ing xlcd.h 292
De fin ing the In ter face 292
De fin ing the Data Port and Tris Reg is ter 293
11.6.2 Tim ing Rou tines 294
11.6.3 XLCD Li brary Func tions 295
BusyXLCD 295
OpenXLCD 296
putrXLCD 296
putsXLCD 296
ReadAddr 296
ReadDataXLCD 297
SetDDRamAddr 297
SetCGRamAddr 297
WriteCmdXLCD 298
WriteDataXLCD 298
11.7 LCD Ap pli ca tion De vel op ment in C18 299
11.7.1 Us ing the Pro ject Wiz ard 299
Main Pro gram File 300
Chap ter 12 Real-Time Clocks 303
12.1 Mea sur ing Time 303
12.1.1 Clock Sig nal Source 303
32 kHz Crys tal Cir cuit 304
12.1.2 Pro gram ming the Timer1 Clock 305
Set ting Up Timer1 Hard ware 305
Cod ing the In ter rupt Han dler 306
Sam ple Pro gram RTC_18F_Timer1.asm 306
12.2 Real-Time Clock ICs 309
12.2.1 NJU6355 310
12.2.2 6355 Data For mat ting 310
12.2.3 Ini tial iza tion and Clock Prim i tives 311
Read ing and Writ ing Clock Data 311
Ini tial ize RTC 314
12.2.4 BCD Con ver sions 316
12.3 RTC Dem on stra tion Cir cuit and Pro gram 318
12.3.1 RTC_F18_6355.asm Pro gram 318
Code De tails 319
Code List ing 319
12.4 Real-Time Clocks in C18 336
12.4.1 Timer1-Based RTC in C18 336
Ta ble of Con tents xiii
Chap ter 13 An a log Data and De vices 343
13.1 Op er a tions on Com puter Data 343
13.2 18F452 A/D Hard ware 343
13.2.1 A/D Mod ule on the 18F452 344
ADCON0 Reg is ter 345
ADCON1 Reg is ter 347
SLEEP Mode Op er a tion 348
13.2.2 A/D Mod ule Sam ple Cir cuit and Pro gram 349
Ini tial ize A/D Mod ule 350
A/D Con ver sion 351
13.2.3 A2D_Pot2LCD Pro gram 352
13.3 A/D Con ver sion in C18 365
13.3.1 Con ver sion Prim i tives 365
Busy ADC 365
CloseADC 365
ConvertADC 366
OpenADC 366
ReadADC 367
SetChan ADC 367
13.3.2 C_ADConvert.c Pro gram 368
C_ADConvert.c Code List ing 368
13.4 In ter fac ing with An a log De vices 371
13.4.1 LM 34 Tem per a ture Sen sor 371
13.4.2 LM135 Cir cuits 372
Cal i brat ing the Sen sor 372
13.4.3 C_ADC_LM35.c Pro gram 373
Chap ter 14 Op er at ing Sys tems 377
14.1 Time-Crit i cal Sys tems 377
14.1.2 Multitasking in Real-Time 378
14.2 RTOS Scope 378
14.2.1 Tasks, Pri or i ties, and Dead lines 379
14.2.2 Ex e cut ing in Real-Time 381
14.3 RTOS Pro gram ming 381
14.3.1 Fore ground and Back ground Tasks 382
In ter rupts in Task ing 382
14.3.2 Task Loops 383
14.3.3 Clock-Tick In ter rupt 383
14.3.4 In ter rupts in Pre emp tive Multitasking 383
14.4 Con struct ing the Sched uler 384
14.4.1 Cy clic Sched ul ing 384
14.4.2 Round-Robin Sched ul ing 385
14.4.3 Task States and Pri or i tIzed Sched ul ing 385
14.5 A Small Sys tem Ex am ple 386
14.5.1 Task Struc ture 386
14.5.2 Sema phore 387
14.6 Sam ple OS Ap pli ca tion 388
xiv Ta ble of Con tents
Ap pen dix A MPLAB C18 Lan guage Tu to rial 413
A.1 In This Ap pen dix 413
A.1.1 About Pro gram ming 413
A.1.2 Com mu ni cat ing with an Alien In tel li gence 414
A.1.3 Flowcharting 415
A.1.4 C Lan guage Rules 417
Com ments 418
Pro gram Header 418
Pro gram ming Tem plates 419
A.2 Struc ture of a C Pro gram 419
A.2.1 Sample Pro gram C_LEDs_ON 420
Iden ti fi ers 420
Re served Words 421
main() Func tion 421
A.2.2 Sam ple Pro gram C_LEDs_Flash 422
Ex pres sions and State ments 423
Vari ables 423
Scope and Life time of a Vari able 425
Con stants 426
Lo cal Func tions 427
A.2.3 Cod ing Style 428
A.3 C Lan guage Data 428
A.3.1 Nu meric Data 429
A.3.2 Al pha nu meric Data 430
A.3.3 Ar rays of Al pha nu meric Data 430
A.3.4 Ar rays of Nu meric Data 431
A.4 In di rec tion 431
A.4.1 Stor age of C Lan guage Vari ables 432
A.4.2 Ad dress of Op er a tor 432
A.4.3 In di rec tion Op er a tor 433
A.4.4 Point ers to Ar ray Vari ables 434
A.4.5 Pointer Arith me tic 435
A.5 C Lan guage Op er a tors 436
A.5.1 Op er a tor Ac tion 436
A.5 2 As sign ment Op er a tor 437
A.5.3 Arith me tic Op er a tors 438
Re main der Op er a tor 439
A.5.4 Con cat e na tion 439
A.5.5 In cre ment and Dec re ment 440
A.5.6 Re la tional Op er a tors 441
A.5.7 Log i cal Op er a tors 442
A.5.8 Bitwise Op er a tors 443
AND Op er a tor 445
OR Op er a tor 446
XOR Op er a tor 447
NOT Op er a tor 447
Shift-Left and Shift-Right Op er a tors 448
A.5.9 Com pound As sign ment Op er a tors 449
A.5.10 Op er a tor Hi er ar chy 449
As so cia tiv ity Rules 450
A.6 Di rect ing Pro gram Flow 451
Ta ble of Con tents xv