- •Chapter 1: Introduction
- •Goals
- •Chapter 2: Quick Start Guide
- •Software
- •WinAVR – Oh, Whenever…
- •Programmers Notepad
- •AVRStudio – FREE and darn well worth it.
- •Br@y++ Terminal:
- •Hardware
- •Constructing Your Development Platform
- •Blinking LEDs – Your First C Program
- •Write it in Programmers Notepad
- •Download to the Butterfly with AVRStudio
- •Blinky Goes Live
- •Simulation with AVRStudio
- •GOOD GRIEF!
- •Comments
- •Include Files
- •Expressions, Statements, and Blocks
- •Operators
- •Flow Control
- •Functions
- •The Main() Thing
- •Chapter 4: C Types, Operators, and Expressions
- •Data Types and Sizes
- •Seen on a shirt at a Robothon event:
- •Bits
- •Bytes
- •The long and short of it
- •Variable Names
- •Constants
- •Declarations
- •Arithmetic Operators
- •Relational and Logical Operators
- •Bitwise Operators
- •Testing Bits
- •Assignment Operators and Expressions
- •Conditional Expressions
- •Precedence and Order of Evaluation
- •Projects
- •Port Input and Output
- •Cylon Eye Speed and Polarity Control
- •Chapter 5: C Control Flow
- •Statements and Blocks
- •If-Else and Else-If
- •Switch
- •Loops – While, For and Do-while
- •Break and Continue
- •Goto and Labels
- •A few practical examples: strlen, atoi, itoa, reverse
- •Chapter 6: C Functions and Program Structures
- •Function Basics
- •Returns
- •Variables External, Static, and Register
- •Scope
- •Headers
- •Blocks
- •Initialization
- •Recursion
- •Preprocessor
- •Macro Substitution
- •Conditional Inclusion
- •Projects
- •Is anybody out there? Communicating with a PC
- •Demonstrator
- •PC_Comm
- •Using CommDemo:
- •Chapter 7: Microcontroller Interrupts and Timers
- •Interrupts
- •Projects
- •Grab your joystick – and test your interrupts
- •Using joystick
- •Timers/Counters
- •Calibrating the Butterfly oscillator:
- •OSCCAL_calibration() function – detailed explanation
- •ALL THIS AND WE HAVEN’T EVEN STARTED CALIBRATING YET!
- •Projects
- •Precision Blinking
- •Using Precision Blinking:
- •Pulse Width Modulation – LED Brightness Control
- •Pulse Width Modulation - Motor Speed Control
- •Speedometer
- •Chapter 8: C Pointers and Arrays
- •Addresses of variables
- •Function Arguments
- •Arrays
- •FIFOs and LIFOs: Stacks and Queues (Circular Buffers)
- •Stacks
- •Queues (Circular Buffers)
- •Function Pointers
- •Complex Pointer and Array Algorithms
- •Projects
- •Messenger
- •Arrays in RAM and ROM
- •Does anybody know what time it is? A Real Time Clock.
- •A one second interrupt
- •Converting Computer Time to Human Readable Time
- •The Real Timer Clock Software
- •Music to my ears. “Play it again Sam.”
- •More on pointers to arrays
- •Setting the frequency
- •Setting the duration
- •An example song array – Fur Elise
- •Using the Piezo-element to make sound
- •Initializing the Timer1 for PWM to the piezo-element.
- •Generating the tone using PWM from Timer1
- •Using the Timer0 interrupt to play a tune
- •Chapter 9 – Digital Meets Analog – ADC and DAC
- •But First - A Debugging Tale
- •Analog to Digital Conversion
- •What is Analog to Digital Conversion?
- •Analog to Digital Conversion by Successive Approximation
- •Analog to Digital Conversion with the ATMEGA169
- •Starting a Conversion
- •Conversion Timing
- •Changing Channels
- •Digital Noise Reduction
- •Conditioning the Analog Input Signal
- •Accuracy
- •Projects
- •Initializing the ADC
- •Reading the ADC
- •Light Meter
- •Temperature Meter
- •The @#%#&*#!!!! Volt Meter
- •Using ADC
- •DAC and ADC - Function Generator / Digital Oscilloscope
- •Chapter 10: C Structures
- •Structure Basics
- •Structures and Functions
- •Structure Arrays
- •Typedef
- •Unions
- •Bit-fields
- •Bit-Fields the C-way
- •Bit-fields the masking-way
- •Projects
- •Finite State Machine
- •Chapter 11 The Butterfly LCD
- •PC to LCD test program
- •Conclusion
- •Appendix 1: Project Kits
- •Data I/O
- •PWM Motor Control
- •Appendix 2: Soldering Tutorial
- •Appendix 3: Debugging Tale
- •Appendix 4: ASCII Table
- •Appendix 5: Decimal, Hexadecimal, and Binary
- •Appendix 6: Motor Speed Control Wheel
- •Appendix 7: HyperTerminal
- •Index
Index
Index
- |
................................................... |
51 |
-- |
................................................... |
51 |
! |
................................................... |
52 |
!= |
................................................... |
52 |
#define .......................................... |
94 |
|
#include ........................................ |
94 |
|
% |
................................................... |
51 |
%=.................................................. |
61 |
|
& |
....................................... |
51, 53, 56 |
&& ................................................. |
52 |
|
&=.................................................. |
61 |
|
() |
................................................... |
52 |
* |
................................................... |
51 |
*= |
................................................... |
61 |
, |
................................................... 52 |
|
. |
................................................... 51 |
|
/ |
................................................... |
51 |
/= |
................................................... |
61 |
?: |
................................................... |
52 |
[] |
................................................... |
51 |
^ |
................................................... |
53 |
^= |
................................................... |
61 |
| |
............................................. |
53, 56 |
|| |
................................................... |
52 |
|= |
................................................... |
61 |
~ |
................................................... |
53 |
+ |
................................................... |
51 |
++ |
................................................... |
51 |
+= |
................................................... |
61 |
< |
................................................... |
52 |
<< |
................................................... |
53 |
<<=................................................. |
61 |
|
<= |
................................................... |
52 |
= |
................................................... |
61 |
-= ................................................... |
|
|
|
61 |
==................................................... |
|
|
|
52 |
> ................................................... |
|
|
|
52 |
-> ................................................... |
|
|
|
51 |
>=................................................... |
|
|
|
52 |
>>................................................... |
|
|
|
53 |
>>=................................................. |
|
|
|
61 |
ADC ..... |
21, 207, 208, 212, 213, 214, |
|||
215, 216, 217, 218, 219, 220, 221, |
||||
222, 223, 225, 227, 231, 233, 236, |
||||
237 |
|
|
|
51 |
Addition.......................................... |
|
|
|
|
Address of....................................... |
|
|
51 |
|
Addresses of variables |
................. |
153 |
||
Analog to Digital Conversion ..... |
210 |
|||
Arithmetic Operators..................... |
|
50 |
||
Array element.................................. |
|
|
51 |
|
array of pointers to arrays............ |
172 |
|||
Arrays.................................. |
|
|
153, 159 |
|
Arrays in RAM and ROM........... |
171 |
|||
ASCII ............................ |
|
|
82, 181, 283 |
|
assembly language .......... |
12, 13, 154 |
|||
Assignment Operators................... |
|
61 |
||
Associativity.................................. |
|
|
62 |
|
ATMEGA169 15, 17, 20, 31, 66, 248 |
||||
atoi................................................. |
|
|
|
81 |
AVRStudio..... |
19, 20, 31, 35, 68, 150 |
|||
BCD - Binary Coded ..Decimal |
180 |
binary.. 43, 45, 46, 47, 48, 53, 54, 59,
75, 154, 186, 212, 249 |
|
|
Binary Coded Decimal.............. |
180 |
|
Bit-fields...................................... |
|
247 |
Bits ...................... |
45, 53, 60, 98, 124 |
|
Bits per second ............................ |
|
291 |
295
Index
Bitwise AND................................... |
|
53 |
||
Bitwise complement ........................ |
|
53 |
||
Bitwise OR |
..................................... |
|
53 |
|
Blocks |
.......................... |
|
|
39, 40, 73, 92 |
Break ............................................. |
|
|
|
79 |
Brightness ......................Control |
|
134 |
||
Bytes.............................................. |
|
|
|
45 |
calibration.................................... |
|
|
121 |
|
case............................................... |
|
|
|
76 |
cast ......................................... |
|
|
|
52, 190 |
char............................................... |
|
|
|
48 |
Circular ...................Buffers |
|
167, 168 |
||
CISC........................................ |
|
|
|
12, 13 |
COM.................... |
|
289, 290, 291, 293 |
||
COM0A0................................. |
|
|
57, 58 |
|
COM0A1................................. |
|
|
57, 58 |
|
comments .................................... |
|
|
161 |
|
Comments ..................................... |
|
|
39 |
|
Conditional ................... |
|
|
52, 62, 64, 96 |
|
Conditional ....................Inclusion |
|
96 |
||
Connections ...............Properties |
290 |
|||
Constants....................................... |
|
|
49 |
|
Continue........................................ |
|
|
79 |
|
Control .................................Flow |
|
73 |
||
Counters ...................................... |
|
|
119 |
|
CS00.... |
57, 58, 59, 60, 194, 204, 235 |
|||
CS0157, 58, 128, 129, 133, 135, 143, |
||||
150, 235 |
|
|
|
|
CS02.......................... |
|
|
57, 58, 59, 235 |
|
Cylon......... |
|
34, 35, 39, 46, 70, 94, 96 |
||
CylonEyes.c................................. |
|
70 |
||
DAC ............................................ |
|
|
|
207 |
Data Types..................................... |
|
|
45 |
|
databook........................................ |
|
|
15 |
|
Debugging...... |
51, 73, 110, 207, 210, |
|||
216, 221, 279 |
|
|
||
Declarations .................................. |
|
50 |
Decrement |
....................................... |
|
|
51 |
Demonstrator.c ............................. |
|
99 |
||
Demonstrator.h........................... |
|
99 |
||
Digi-Key.................... |
|
|
17, 18, 66, 273 |
|
Digital Oscilloscope.................... |
|
227 |
||
Digital to Analog .....Conversion |
227 |
|||
Division .......................................... |
|
|
|
51 |
Do-while........................................ |
|
|
|
78 |
duration ....................................... |
|
|
|
192 |
Encapsulation ................................ |
|
|
87 |
|
Equal to .......................................... |
|
|
|
52 |
Escape Sequences ......................... |
|
82 |
||
Expressions ........... |
39, 45, 61, 62, 73 |
|||
External variable ........................... |
|
90 |
||
FIFOs .......................................... |
|
|
|
167 |
Flow Control ........................... |
|
|
40, 98 |
|
FOC0A .......................... |
|
|
58, 143, 150 |
|
FOCA ............................................ |
|
|
|
57 |
For ................................................. |
|
|
|
78 |
frequency..................................... |
|
|
|
190 |
Function... |
52, 87, 122, 157, 166, 169, |
|||
227, 230, 231, 232 |
|
|||
Function Arguments.................... |
|
157 |
||
Function Generator ..................... |
|
227 |
||
Function Pointers ........................ |
|
169 |
||
Functions................. |
|
|
41, 87, 169, 243 |
|
Goals ............................................. |
|
|
|
14 |
Goto............................................... |
|
|
|
80 |
Greater than .................................... |
|
|
52 |
|
Headers.......................................... |
|
|
|
92 |
hexadecimal .. |
43, 46, 47, 48, 82, 180 |
|||
Hyperterminal .... |
103, 118, 133, 136, |
|||
150, 173, 176, 188, 216, 223, 227, |
||||
230, 236, 289, 292, 293 |
|
|||
If-Else and .........................Else-If |
|
74 |
||
Include Files.................................. |
|
|
39 |
|
Increment........................................ |
|
|
|
51 |
296
Index
Indirection....................................... |
51 |
||
int .................................................. |
|
|
49 |
interrupt ....................................... |
178 |
||
Interrupts ..................................... |
109 |
||
itoa................................................. |
|
|
81 |
JAMECO 22, 26, 137, 225, 227, 273, |
|||
275, 276 |
|
||
joystick |
..... 15, 32, 33, 68, 75, 76, 98, |
||
110, 111, 114, 116, 118, 119, 150, |
|||
151, 270, 292 |
|
||
Labels |
............................................ |
|
80 |
LCD............................................... |
|
|
43 |
LED .. |
23, 26, 43, 46, 69, 70, 75, 128, |
||
129, 134, 136, 137 |
|
||
LEDs .. |
|
15, 26, 27, 34, 35, 36, 39, 43, |
|
45, 46, 47, 48, 65, 67, 68, 70, 115, |
|||
134, 135, 147, 154, 273 |
53 |
||
Left shift ......................................... |
|||
Less than......................................... |
52 |
||
LIFOs |
.......................................... |
|
167 |
Light ............................................ |
|
|
219 |
Light Meter.................................. |
219 |
||
Logical..................................... |
|
52, 64 |
|
Logical NOT ................................... |
52 |
||
long................................................ |
|
|
49 |
Loops............................................. |
|
|
78 |
machine language.......................... |
12 |
||
Macro Substitution ........................ |
95 |
||
Main()............................................ |
|
42 |
|
masking ....................................... |
248 |
||
Member selection ............................ |
51 |
||
messenger software ..................... |
174 |
||
Modulo ........................................... |
|
51 |
|
Motor Speed Control................... |
137 |
||
Multiplication.................................. |
51 |
||
Negation ......................................... |
51 |
||
nitialization.................................... |
92 |
NOT ............................................... |
|
|
53 |
Operators .. |
40, 45, 50, 51, 52, 53, 61, |
||
63 |
|
|
|
optoisolator.......................... |
137, 144 |
||
Order of Evaluation....................... |
62 |
||
OSCCAL_calibration.................. |
122 |
||
oscillator... |
99, 104, 105, 115, 121, 123, |
||
124, 125, 127, 128, 130, 132, 140, |
|||
142, 147, 149, 162, 175, 178, 183, |
|||
199, 208, 222, 232, 235 |
102 |
||
PC_Comm.c |
...................................... |
|
|
PC_Comm.h |
...................................... |
|
102 |
Piezo............................................ |
|
|
192 |
play a tune ................................... |
|
194 |
|
Pointers........................................ |
|
|
153 |
pointers to arrays ......................... |
189 |
||
potentiometer............................... |
225 |
||
Precedence..................................... |
|
62 |
preprocessor 39, 94, 95, 97, 112, 246
Preprocessor .................................. |
|
|
94 |
Programmers Notepad...... |
19, 27, 36, |
||
114, 130, 174, 182, 195 |
|
|
|
Pulse Width Modulation...... |
|
134, 137 |
|
PWM ........................................... |
|
|
193 |
Queues................................. |
|
|
167, 168 |
Real Time Clock... |
15, 178, 182, 183, |
||
188 |
|
|
|
Real Timer Clock Software |
......... 182 |
||
Recursion....................................... |
|
|
93 |
Register variable............................ |
|
|
90 |
Returns .......................................... |
|
|
89 |
reverse ........................................... |
|
|
81 |
Right shift ....................................... |
|
|
53 |
RISC.............................................. |
|
|
13 |
RS-232....................... |
21, 22, 26, 289 |
||
RXD .................................. |
|
21, 22, 96 |
|
Sawtooth Wave............................ |
|
|
231 |
297
Index |
|
|
Scope............................................. |
|
91 |
Simulation ..................................... |
|
35 |
simulator............................ |
|
27, 32, 35 |
Sine Wave.................................... |
|
231 |
sourceforge.............. |
19, 35, 172, 189 |
|
Speedometer |
................................ |
144 |
Square Wave................................ |
231 |
|
Stacks .......................................... |
|
167 |
Statements ......................... |
|
39, 40, 73 |
Statements and Blocks .................. |
73 |
|
Static variable................................ |
90 |
|
strlen.............................................. |
|
81 |
Structure Arrays .......................... |
246 |
|
Structures .................................... |
|
241 |
Structures and Functions............. |
243 |
|
Subtraction...................................... |
|
51 |
Successive Approximation.......... |
211 |
|
Switch............................................ |
|
75 |
Tale of a bug................................. |
73 |
|
TCC0RA ................... |
59, 60, 61, 135 |
|
TCCR0A .... |
57, 58, 59, 60, 128, 129, |
|
133, 135, 143, 150, 194, 204, 235 |
||
Temperature |
................................ |
220 |
Temperature Meter |
...................... |
220 |
tempo........................................... |
|
191 |
Testing Bits ................................... |
|
60 |
Timer0 interrupt .......................... |
|
194 |
Timers ................................. |
|
109, 119 |
Triangle Wave ............................. |
|
231 |
TXD .................................. |
21, 22, 96 |
|
Typedef........................................ |
|
246 |
Unary Plus ...................................... |
|
51 |
Unions ......................................... |
|
247 |
unsigned ....................................... |
|
49 |
Variable Names ............................. |
|
49 |
Variables........................................ |
|
90 |
Volt Meter ................................... |
|
221 |
Waveform Generator .........Modes |
60 |
|
WGM00 57, 58, 59, 60, 61, 128, 129, |
||
133, 135, 143, 150, 194, 204, 235 |
||
WGM01 57, 58, 59, 60, 61, 128, 129, |
||
133, 135, 143, 150, 194, 204, 235 |
||
While............................................. |
|
78 |
WinAVR . 15, 18, 19, 27, 31, 35, 113, 171, 177, 182, 189, 195, 198, 220, 221, 247, 270
298
wwwH .SmileyMicros.com.H
299
300