[align=left:ea277f54f1]
Contents
1.AtmelAVRArchitectureOverview.................... ...........................1
1.1ATmega16ArchitectureOverview................... .........................1
1.1.1ReducedInstructionSetComputer................ ....................1
1.1.2AssemblyLanguageInstructionSet............... .....................2
1.1.3ATmega16ArchitectureOverview................. ...................3
1.2NonvolatileandDataMemories..................... .........................3
1.2.1In-SystemProgrammableFlashEEPROM..................... .......3
1.2.2Byte-AddressableEEPROM................................. ........5
1.2.3StaticRandomAccessMemory..................... ..................5
1.2.4ProgrammableLockBits......................... ....................5
1.3PortSystem..................................... ...........................6
1.4PeripheralFeatures---InternalSubsystems................................ .....8
1.4.1TimeBase..................................... .....................8
1.4.2TimingSubsystem.............................. .....................9
1.4.3PulseWidthModulationChannels................. ...................9
1.4.4SerialCommunications......................... ......................9
1.4.4.1SerialUSART................................ .............9
1.4.4.2SerialPeripheralInterface.................. ................10
1.4.4.3Two-WireSerialInterface............................... ..10
1.4.5Analog-to-DigitalConverter.................................. ......10
1.4.6Interrupts................................... .......................11
1.5PhysicalandOperatingParameters................. .........................11
1.5.1Packaging.................................... ......................11
1.5.2PowerConsumption............................. ...................11
1.5.3SpeedGrades.................................. ....................13
1.6Application:ATmega16Testbench.................. ........................13
1.6.1HardwareConfiguration........................ ....................13
1.6.2SoftwareConfiguration........................ .....................15
1.7ProgrammingtheATmega16......................... ......................19
1.7.1ProgrammingProcedure......................... ...................20
1.8SoftwarePortability............................ ............................22
1.9Summary........................................ .........................23
1.10ReferencesandFurtherReading................... ..........................23
1.11ChapterProblems............................... ...........................23
2.SerialCommunicationSubsystem.................... ...........................25
2.1SerialCommunications........................... ..........................25
2.2SerialCommunicationTerminology................. ........................25
2.2.1AsynchronousversusSynchronousSerialTransmissi on.................26
2.2.2BaudRate..................................... .....................26
2.2.3FullDuplex................................... .....................26
2.2.4NonreturntoZeroCodingFormat.................. .................26
2.2.5TheRS-232CommunicationProtocol.......................... ......27
2.2.6Parity....................................... .......................27
2.2.7AmericanStandardCodeforInformationInterchange ..................27
2.3SerialUSART.................................... .........................27
2.3.1SystemOverview............................... .....................28
2.3.1.1USARTClockGenerator........................ ..........29
2.3.1.2USARTTransmitter........................... ...........30
2.3.1.3USARTReceiver.............................. ............30
2.3.1.4USARTRegisters............................. ............30
2.3.2SystemOperationandProgramming................ ..................32
2.3.3SerialPeripheralInterface.................... ........................34
2.3.3.1SPIOperation............................... .............34
2.3.3.2Registers.................................. ...............35
2.3.3.3Programming................................ .............37
2.4Two-WireSerialInterface............................... ...................38
2.5Summary........................................ .........................38
2.6ReferencesandFurtherReading.................... .........................38
2.7ChapterProblems................................ ..........................39
3.Analog-to-DigitalConversion................................. .................41
3.1BackgroundTheory............................... .........................41
3.1.1AnalogversusDigitalSignals................... ......................42
3.1.2Sampling,Quantization,andEncoding............ ...................44
3.1.3ResolutionandDataRate........................ ....................48
3.2Analog-To-DigitalConversionProcess.......................... ............50
3.3ADCConversionTechnologies...................... .......................53
3.3.1SuccessiveApproximation...................... .....................53
3.3.2Integration.................................. .......................55
3.3.3Counter-BasedConversion................................... .......55
3.3.4ParallelConversion........................... ......................55
3.4TheAtmelATmega16ADCSystem...................... ..................55
3.4.1BlockDiagram................................. ....................56
3.4.2Registers.................................... .......................58
3.4.2.1ADCMultiplexerSelectionRegister............ ............58
3.4.2.2ADCControlandStatusRegisterA............... .........59
3.4.2.3ADCDataRegisters(ADCHandADCL).............. ....59
3.4.3ProgrammingtheADC............................ .................59
3.4.4Digital-to-AnalogConversion.................................. .....62
3.5Summary........................................ .........................63
3.6ReferencesandFurtherReading.................... .........................63
3.7ChapterProblems................................ ..........................64
InterruptSubsystem................................ ............................65
4.1InterruptTheory................................ ...........................65
4.2ATmega16InterruptSystem........................ ........................65
4.3ProgrammingAnInterrupt......................... ........................66
4.4Application.................................... ...........................68
4.4.1ExternalInterrupts........................... .......................68
4.4.2InternalInterrupt............................ .......................71
4.5Summary........................................ .........................74
4.6ReferencesandFurtherReading.................... .........................74
4.7ChapterProblems................................ ..........................74
TimingSubsystem................................... ..........................75
5.1Overview....................................... ...........................75
5.2Timing-RelatedTerminology................................ ...............76
5.2.1Frequency.................................... ......................76
5.2.2Period....................................... ......................76
5.2.3DutyCycle.................................... .....................76
5.3TimingSystemOverview........................... ........................76
5.4Applications................................... ............................79
5.4.1InputCapture---MeasuringExternalTimingEvent.....................7 9
5.4.2CountingEvents............................... .....................81
5.4.3OutputCompare---GeneratingTimingSignalsto
InterfaceExternalDevices.......................... .................81
5.4.4IndustrialImplementationCaseStudy(PWM)....... .................82
OverviewoftheAtmelTimers.......................... ....................83
Timer0System...................................... ......................84
5.6.1ModesofOperation............................. ....................86
5.6.1.1NormalMode................................. ............87
5.6.1.2ClearTimeronCompareMatch................... .........87
5.6.1.3PhaseCorrectPWMMode........................ ........87
5.6.1.4FastPWM.................................... ...........87
5.6.2Timer0Registers.............................. .....................87
5.6.2.1Timer/CounterControlRegister0..........................8 8
5.6.2.2Timer/CounterRegister................................... 88
5.6.2.3OutputCompareRegister...................... ............88
5.6.2.4Timer/CounterInterruptMaskRegister.....................9 0
5.6.2.5Timer/CounterInterruptFlagRegister...................... 91
Timer1............................................ .......................91
5.7.1Timer1Registers.............................. .....................91
5.7.1.1TCCR1AandTCCR1BRegisters................... .......91
5.7.1.2Timer/CounterRegister1(TCNT1H/TCNT1).............91
5.7.1.3OutputCompareRegister1ChannelA(OCR1AH/
OCR1AL)........................................... ....94
5.7.1.4OutputCompareRegister1ChannelB(OCR1BH/
OCR1BL)........................................... .....94
5.7.1.5InputCaptureRegister1(ICR1H/ICR1L)..................94
5.7.1.6Timer/CounterInterruptMaskRegister(TIMSK)...........94
5.7.1.7Timer/CounterInterruptFlagRegister(TIFR)..............94
Timer2............................................ .......................94
5.8.1Timer/CounterControlRegister2........................... .........94
5.8.2Timer/CounterRegister(TCNT2)............................ .......95
5.8.3OutputCompareRegister(OCR2).................. .................95
5.8.4Timer/CounterInterruptMaskRegister(TIMSK)............... ......96
5.8.5Timer/CounterInterruptFlagRegister...................... ..........96
ProgrammingtheTimerSystem......................... ....................96
5.9.1PrecisionDelay............................... ......................98
5.9.2PulseWidthModulation......................... ...................99
5.9.3InputCaptureMode............................. ..................101
5.10Summary....................................... .........................103
5.11ReferencesandFurtherReading................... .........................103
5.12ChapterProblems............................... .........................104
6.AtmelAVROperatingParametersandInterfacing....... .......................105
6.1OperatingParameters............................ .........................106
6.2InputDevices................................... .........................107
6.2.1Switches..................................... .....................109
6.2.2SwitchDebouncing............................. ...................110
6.2.3Keypads...................................... .....................111
6.2.4Sensors...................................... .....................111
6.2.4.1DigitalSensors............................. ..............111
6.2.4.2AnalogSensors.............................. ............114
6.3OutputDevices.................................. .........................114
6.3.1Light-EmittingDiodes.................................... .........115
6.3.2Seven-SegmentLEDDisplays................................ ......117
6.3.3TristateLEDIndicator......................... ....................117
6.3.4DotMatrixDisplay............................. ...................120
6.3.5LiquidCrystalDisplay......................... ....................120
6.3.6High-PowerDCDevices.................................... .......124
6.4DCMotorSpeedandDirectionControl................ ....................125
6.4.1DCMotorOperatingParameters................... ................126
6.4.2ACDevices.................................... ...................126
6.5Application:FlightSimulatorPanel............... .........................127
6.6Summary........................................ ........................157
6.7ReferencesandFurtherReading.................... ........................158
6.8ChapterProblems................................ ........................158
A.ATmega16RegisterSet............................. ...........................159
B.ATmega16HeaderFile.............................. .........................161
AuthorBiography................................... ..........................177
Index............................................. ............................179
[/align:ea277f54f1]