
- •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
Chapter 2: Quick Start Guide
Software
We will use three FREE software packages, the WinAVR compiler from sourceforge.net, the AVRStudio 4 from ATMEL, and Br@y++’s Terminal.
WinAVR – Oh, Whenever…
WinAVR is a set of tools for C programming the AVR microcontroller family. A bunch of folks have volunteered their time to write this software and give it away as part of the free software movement (www.sourceforge.net). These folks generously giving there time to help others is almost enough to change my cynical opinion of humanity. You can spend thousands on C compilers for microcontrollers and before WinAVR you had to spend several hundred even for a crappy compiler. This software is FREE, but SourceForge has expenses so send them some money at www.sourceforge.net/donate.
At http://sourceforge.net/projects/winavr/ you see the summary:
“WinAVR (pronounced "whenever") is a suite of executable, open source software development tools for the ATMEL AVR series of RISC microprocessors hosted on the Windows platform. Includes the GNU GCC compiler for C and C++.”
Go to: http://winavr.sourceforge.net/index.html and check out their homepage.
But don’t get too distracted with all that yet, just use the tools as shown here, and once you reach the end of this book, then you’ll have the skills to fully exploit those web sites.
Programmers Notepad
We’ll be writing our software using the most excellent Programmers Notepad, another FREE program available at sourceforge.net and included in the WinAVR distribution package. Imagine what Microsoft would charge for this FREE software. Be a good guy or gal and send them some money at http://www.pnotepad.org.
19
Chapter 2: Quick Start Guide
AVRStudio – FREE and darn well worth it.
AVR Studio is provided free by the good folks at ATMEL Corporation, who seem to understand that the more help they give developers, the more they will sell their microcontrollers. Actually, this too could cost hundreds and still be darn well worth it, but unless you just really like Norway, don’t send them any money, they’ll get theirs on the backend when you start buying thousands of AVRs for your next great invention.
The AVR Studio will be used for two things: first, to download your software to the AVR Butterfly, and second, to simulate the ATMEGA169 running your software.
Br@y++ Terminal:
The original Quick Start Guide chapter used HyperTerminal, which is hard to setup, clunky, and hated by so many folks on the AVRFreaks.net forum that I contacted Br@y++ and he gave me permission to use and distribute his highly recommended and easy to use and understand terminal package. You can get it at http://bray.velenje.cx/avr/terminal or http://www.smileymicros.com. It is shown in Figure 7: Bray's Terminal. The examples in the text still show the HyperTerminal, but it shouldn’t be a problem substituting Bray’s. If you want to use HyperTerminal, the introduction to it is in Appendix 1.
20