- •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
Appendix 4: ASCII Table
Appendix 4: ASCII Table
Table 9: ASCII Table
Char Dec Hex | Char Dec Hex | Char Dec Hex | Char Dec Hex
---------------------------------------------------------------------
(nul) |
0 |
0x00 |
| |
(sp) |
32 |
0x20 |
| @ |
64 |
0x40 |
| |
` |
96 |
0x60 |
(soh) |
1 |
0x01 |
| |
! |
33 |
0x21 |
| A |
65 |
0x41 |
| |
a |
97 |
0x61 |
(stx) |
2 |
0x02 |
| |
" |
34 |
0x22 |
| B |
66 |
0x42 |
| |
b |
98 |
0x62 |
(etx) |
3 |
0x03 |
| |
# |
35 |
0x23 |
| C |
67 |
0x43 |
| |
c |
99 |
0x63 |
(eot) |
4 |
0x04 |
| |
$ |
36 |
0x24 |
| D |
68 |
0x44 |
| |
d |
100 |
0x64 |
(enq) |
5 |
0x05 |
| |
% |
37 |
0x25 |
| E |
69 |
0x45 |
| |
e |
101 |
0x65 |
(ack) |
6 |
0x06 |
| |
& |
38 |
0x26 |
| F |
70 |
0x46 |
| |
f |
102 |
0x66 |
(bel) |
7 |
0x07 |
| |
' |
39 |
0x27 |
| G |
71 |
0x47 |
| |
g |
103 |
0x67 |
(bs) |
8 |
0x08 |
| |
( |
40 |
0x28 |
| H |
72 |
0x48 |
| |
h |
104 |
0x68 |
(ht) |
9 |
0x09 |
| |
) |
41 |
0x29 |
| I |
73 |
0x49 |
| |
i |
105 |
0x69 |
(nl) |
10 |
0x0a | |
* |
42 |
0x2a | J |
74 |
0x4a | |
j |
106 |
0x6a |
|||
(vt) |
11 |
0x0b | |
+ |
43 |
0x2b | K |
75 |
0x4b | |
k |
107 |
0x6b |
|||
(np) |
12 |
0x0c | |
, |
44 |
0x2c | L |
76 |
0x4c | |
l |
108 |
0x6c |
|||
(cr) |
13 |
0x0d | |
- |
45 |
0x2d | M |
77 |
0x4d | |
m |
109 |
0x6d |
|||
(so) |
14 |
0x0e | . |
46 |
0x2e | N |
78 |
0x4e | |
n |
110 |
0x6e |
||||
(si) |
15 |
0x0f | |
/ |
47 |
0x2f | O |
79 |
0x4f | |
o |
111 |
0x6f |
|||
(dle) |
16 |
0x10 |
| |
0 |
48 |
0x30 |
| P |
80 |
0x50 |
| |
p |
112 |
0x70 |
(dc1) |
17 |
0x11 |
| |
1 |
49 |
0x31 |
| Q |
81 |
0x51 |
| |
q |
113 |
0x71 |
(dc2) |
18 |
0x12 |
| |
2 |
50 |
0x32 |
| R |
82 |
0x52 |
| |
r |
114 |
0x72 |
(dc3) |
19 |
0x13 |
| |
3 |
51 |
0x33 |
| S |
83 |
0x53 |
| |
s |
115 |
0x73 |
(dc4) |
20 |
0x14 |
| |
4 |
52 |
0x34 |
| T |
84 |
0x54 |
| |
t |
116 |
0x74 |
(nak) |
21 |
0x15 |
| |
5 |
53 |
0x35 |
| U |
85 |
0x55 |
| |
u |
117 |
0x75 |
(syn) |
22 |
0x16 |
| |
6 |
54 |
0x36 |
| V |
86 |
0x56 |
| |
v |
118 |
0x76 |
(etb) |
23 |
0x17 |
| |
7 |
55 |
0x37 |
| W |
87 |
0x57 |
| |
w |
119 |
0x77 |
(can) |
24 |
0x18 |
| |
8 |
56 |
0x38 |
| X |
88 |
0x58 |
| |
x |
120 |
0x78 |
(em) |
25 |
0x19 |
| |
9 |
57 |
0x39 |
| Y |
89 |
0x59 |
| |
y |
121 |
0x79 |
(sub) |
26 |
0x1a | |
: |
58 |
0x3a | Z |
90 |
0x5a | |
z |
122 |
0x7a |
|||
(esc) |
27 |
0x1b | |
; |
59 |
0x3b | [ |
91 |
0x5b | |
{ |
123 |
0x7b |
|||
(fs) |
28 |
0x1c | |
< |
60 |
0x3c | \ |
92 |
0x5c | |
| |
124 |
0x7c |
|||
(gs) |
29 |
0x1d | |
= |
61 |
0x3d | ] |
93 |
0x5d | |
} |
125 |
0x7d |
|||
(rs) |
30 |
0x1e | |
> |
62 |
0x3e | ^ |
94 |
0x5e | |
~ |
126 |
0x7e |
|||
(us) |
31 |
0x1f | |
? |
63 |
0x3f | _ |
95 |
0x5f | |
(del) 127 |
0x7f |
||||
ASCII Name Description |
C Escape Sequence |
|
nul |
null byte |
\0 |
bel |
bell character |
\a |
bs |
backspace |
\b |
ht |
horizontal tab |
\t |
np |
formfeed |
\f |
nl |
newline |
\n |
cr |
carriage return |
\r |
vt |
vertical tab |
|
esc |
escape |
|
sp |
space |
|
283
Appendix 5: Decimal, Hexadecimal, and Binary
Appendix |
5: |
Decimal, |
|
Hexadecimal, |
and |
||||||
Binary |
|
|
|
|
|
|
|
|
|
|
|
Table 10: Decimal, Hexadecimal, and Binary Conversion |
|
|
|
|
|||||||
Dec |
Hex Bin |
Dec Hex Bin |
Dec Hex Bin |
Dec Hex Bin |
|
||||||
0 |
0 00000000 |
64 |
40 |
01000000 |
128 |
80 |
10000000 |
192 |
c0 |
11000000 |
|
1 |
1 00000001 |
65 |
41 |
01000001 |
129 |
81 |
10000001 |
193 |
c1 |
11000001 |
|
2 |
2 00000010 |
66 |
42 |
01000010 |
130 |
82 |
10000010 |
194 |
c2 |
11000010 |
|
3 |
3 00000011 |
67 |
43 |
01000011 |
131 |
83 |
10000011 |
195 |
c3 |
11000011 |
|
4 |
4 00000100 |
68 |
44 |
01000100 |
132 |
84 |
10000100 |
196 |
c4 |
11000100 |
|
5 |
5 00000101 |
69 |
45 |
01000101 |
133 |
85 |
10000101 |
197 |
c5 |
11000101 |
|
6 |
6 00000110 |
70 |
46 |
01000110 |
134 |
86 |
10000110 |
198 |
c6 |
11000110 |
|
7 |
7 00000111 |
71 |
47 |
01000111 |
135 |
87 |
10000111 |
199 |
c7 |
11000111 |
|
8 |
8 00001000 |
72 |
48 |
01001000 |
136 |
88 |
10001000 |
200 |
c8 |
11001000 |
|
9 |
9 00001001 |
73 |
49 |
01001001 |
137 |
89 |
10001001 |
201 |
c9 |
11001001 |
|
10 |
a 00001010 |
74 |
4a 01001010 |
138 |
8a |
10001010 |
202 |
ca 11001010 |
|||
11 |
b 00001011 |
75 |
4b 01001011 |
139 |
8b |
10001011 |
203 |
cb 11001011 |
|||
12 |
c 00001100 |
76 |
4c 01001100 |
140 |
8c |
10001100 |
204 |
cc 11001100 |
|||
13 |
d 00001101 |
77 |
4d 01001101 |
141 |
8d |
10001101 |
205 |
cd 11001101 |
|||
14 |
e 00001110 |
78 |
4e 01001110 |
142 |
8e |
10001110 |
206 |
ce 11001110 |
|||
15 |
f 00001111 |
79 |
4f 01001111 |
143 |
8f |
10001111 |
207 |
cf 11001111 |
|||
16 |
10 00010000 |
80 |
50 |
01010000 |
144 |
90 |
10010000 |
208 |
d0 |
11010000 |
|
17 |
11 00010001 |
81 |
51 |
01010001 |
145 |
91 |
10010001 |
209 |
d1 |
11010001 |
|
18 |
12 00010010 |
82 |
52 |
01010010 |
146 |
92 |
10010010 |
210 |
d2 |
11010010 |
|
19 |
13 00010011 |
83 |
53 |
01010011 |
147 |
93 |
10010011 |
211 |
d3 |
11010011 |
|
20 |
14 00010100 |
84 |
54 |
01010100 |
148 |
94 |
10010100 |
212 |
d4 |
11010100 |
|
21 |
15 00010101 |
85 |
55 |
01010101 |
149 |
95 |
10010101 |
213 |
d5 |
11010101 |
|
22 |
16 00010110 |
86 |
56 |
01010110 |
150 |
96 |
10010110 |
214 |
d6 |
11010110 |
|
23 |
17 00010111 |
87 |
57 |
01010111 |
151 |
97 |
10010111 |
215 |
d7 |
11010111 |
|
24 |
18 00011000 |
88 |
58 |
01011000 |
152 |
98 |
10011000 |
216 |
d8 |
11011000 |
|
25 |
19 00011001 |
89 |
59 |
01011001 |
153 |
99 |
10011001 |
217 |
d9 |
11011001 |
|
26 |
1a 00011010 |
90 |
5a 01011010 |
154 |
9a |
10011010 |
218 |
da 11011010 |
|||
27 |
1b 00011011 |
91 |
5b 01011011 |
155 |
9b |
10011011 |
219 |
db 11011011 |
|||
28 |
1c 00011100 |
92 |
5c 01011100 |
156 |
9c |
10011100 |
220 |
dc 11011100 |
|||
29 |
1d 00011101 |
93 |
5d 01011101 |
157 |
9d |
10011101 |
221 |
dd 11011101 |
|||
30 |
1e 00011110 |
94 |
5e 01011110 |
158 |
9e |
10011110 |
222 |
de 11011110 |
|||
31 |
1f 00011111 |
95 |
5f 01011111 |
159 |
9f |
10011111 |
223 |
df 11011111 |
|||
32 |
20 00100000 |
96 |
60 |
01100000 |
160 |
a0 |
10100000 |
224 |
e0 |
11100000 |
|
33 |
21 00100001 |
97 |
61 |
01100001 |
161 |
a1 |
10100001 |
225 |
e1 |
11100001 |
|
34 |
22 00100010 |
98 |
62 |
01100010 |
162 |
a2 |
10100010 |
226 |
e2 |
11100010 |
|
35 |
23 00100011 |
99 |
63 |
01100011 |
163 |
a3 |
10100011 |
227 |
e3 |
11100011 |
|
36 |
24 00100100 |
100 |
64 |
01100100 |
164 |
a4 |
10100100 |
228 |
e4 |
11100100 |
|
37 |
25 00100101 |
101 |
65 |
01100101 |
165 |
a5 |
10100101 |
229 |
e5 |
11100101 |
|
38 |
26 00100110 |
102 |
66 |
01100110 |
166 |
a6 |
10100110 |
230 |
e6 |
11100110 |
|
39 |
27 00100111 |
103 |
67 |
01100111 |
167 |
a7 |
10100111 |
231 |
e7 |
11100111 |
|
40 |
28 00101000 |
104 |
68 |
01101000 |
168 |
a8 |
10101000 |
232 |
e8 |
11101000 |
|
41 |
29 00101001 |
105 |
69 |
01101001 |
169 |
a9 |
10101001 |
233 |
e9 |
11101001 |
|
42 |
2a 00101010 |
106 |
6a 01101010 |
170 |
aa 10101010 |
234 |
ea 11101010 |
||||
285
Appendix 5: Decimal, Hexadecimal, and Binary
43 |
2b |
00101011 |
107 |
6b |
01101011 |
171 |
ab 10101011 |
235 |
eb 11101011 |
||
44 |
2c |
00101100 |
108 |
6c |
01101100 |
172 |
ac 10101100 |
236 |
ec 11101100 |
||
45 |
2d |
00101101 |
109 |
6d |
01101101 |
173 |
ad 10101101 |
237 |
ed 11101101 |
||
46 |
2e |
00101110 |
110 |
6e |
01101110 |
174 |
ae 10101110 |
238 |
ee 11101110 |
||
47 |
2f |
00101111 |
111 |
6f |
01101111 |
175 |
af 10101111 |
239 |
ef 11101111 |
||
48 |
30 |
00110000 |
112 |
70 |
01110000 |
176 |
b0 |
10110000 |
240 |
f0 |
11110000 |
49 |
31 |
00110001 |
113 |
71 |
01110001 |
177 |
b1 |
10110001 |
241 |
f1 |
11110001 |
50 |
32 |
00110010 |
114 |
72 |
01110010 |
178 |
b2 |
10110010 |
242 |
f2 |
11110010 |
51 |
33 |
00110011 |
115 |
73 |
01110011 |
179 |
b3 |
10110011 |
243 |
f3 |
11110011 |
52 |
34 |
00110100 |
116 |
74 |
01110100 |
180 |
b4 |
10110100 |
244 |
f4 |
11110100 |
53 |
35 |
00110101 |
117 |
75 |
01110101 |
181 |
b5 |
10110101 |
245 |
f5 |
11110101 |
54 |
36 |
00110110 |
118 |
76 |
01110110 |
182 |
b6 |
10110110 |
246 |
f6 |
11110110 |
55 |
37 |
00110111 |
119 |
77 |
01110111 |
183 |
b7 |
10110111 |
247 |
f7 |
11110111 |
56 |
38 |
00111000 |
120 |
78 |
01111000 |
184 |
b8 |
10111000 |
248 |
f8 |
11111000 |
57 |
39 |
00111001 |
121 |
79 |
01111001 |
185 |
b9 |
10111001 |
249 |
f9 |
11111001 |
58 |
3a |
00111010 |
122 |
7a |
01111010 |
186 |
ba 10111010 |
250 |
fa 11111010 |
||
59 |
3b |
00111011 |
123 |
7b |
01111011 |
187 |
bb 10111011 |
251 |
fb 11111011 |
||
60 |
3c |
00111100 |
124 |
7c |
01111100 |
188 |
bc 10111100 |
252 |
fc 11111100 |
||
61 |
3d |
00111101 |
125 |
7d |
01111101 |
189 |
bd 10111101 |
253 |
fd 11111101 |
||
62 |
3e |
00111110 |
126 |
7e |
01111110 |
190 |
be 10111110 |
254 |
fe 11111110 |
||
63 |
3f |
00111111 |
127 |
7f |
01111111 |
191 |
bf 10111111 |
255 |
ff 11111111 |
||
286
