The AVR Microcontroller

Total Page:16

File Type:pdf, Size:1020Kb

The AVR Microcontroller An Introduction to Microcontrollers and Software Design Name _____________________ MRGS Technology Electronics Available online from www.techideas.co.nz B. Collis - Mount Roskill Grammar School 2003-2009 This work is licensed under the Creative Commons Attribution-Non-commercial-Share Alike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0 . The licensor permits others to copy, distribute and transmit the work. In return, licensees may not use the work for commercial purposes — unless they get the licensor's permission. The licensor permits others to distribute derivative works only under a license identical to the one that governs the licensor's work. Table of Contents Introduction to Microcontroller Electronics .......................................................................4 Computers and Microcontrollers ..............................................................................5 What exactly is a Microcontroller .............................................................................6 What you do when learning to program ...........................................................................7 Achievement Objectives from the NZ Curriculum ....................................................8 Hardware - The AVR Microcontroller ...............................................................................9 Power Supplies........................................................................................................9 AVR Programming.................................................................................................10 Breadboard ............................................................................................................10 Simple AVR circuit .................................................................................................11 Circuit description ..................................................................................................12 AVR programming cable........................................................................................12 Introduction to writing programs using Bascom-AVR IDE..............................................13 Reading and Writing using flowcharts....................................................................14 Input and Output Control........................................................................................15 Sending Morse code..............................................................................................16 Microcontroller ports: write a Knightrider program using 8 LED’s ..........................17 Multiple LEDs - Traffic lights exercise ....................................................................18 Multiple LEDs - 7 Segment Displays......................................................................19 Different types of switches .....................................................................................20 First input device – a single push button switch.....................................................21 BASCOM and AVR Assignment ............................................................................23 Words you need to be able to use correctly when talking about programming ......24 A Bit about Numbers..............................................................................................25 Programming Codes of Practice ....................................................................................26 Programming Template .........................................................................................27 Variables................................................................................................................28 The BASCOM-AVR Simulator................................................................................29 Control statements – IF THEN.......................................................................................31 Connecting and programming multiple switches....................................................31 Reading multiple switches in software ...................................................................32 Using flowcharts to help solve problems................................................................33 Using IF-THEN to control which parts of a program happen..................................37 Debounce ..............................................................................................................36 More Interfacing.............................................................................................................38 Analogue to Digital Conversion..............................................................................39 Reading an LDR’s values in Bascom.....................................................................41 Temperature measurement using the LM35 ..........................................................43 Keypad Interfacing.................................................................................................44 Alternative keypad interface...................................................................................44 Controlling high power loads (outputs)...................................................................45 Parallel Data Communications...............................................................................46 LCDs (Liquid Crystal Displays) ..............................................................................47 Connecting an LCD to a 40pin AVR.......................................................................48 Don’t delay.............................................................................................................51 Programs as solutions: understanding algorithms and flowcharts .................................54 Planning Sequence for an AVR project..................................................................54 One Page Brief ......................................................................................................55 One Page Brief ......................................................................................................56 Algorithm Development Worksheet........................................................................57 Example Brief.........................................................................................................58 Algorithm Planning Example..................................................................................59 Example Brief.........................................................................................................60 ii Algorithm Development Example...........................................................................61 Glue Gun Timer Flowchart.....................................................................................62 Multiplication Algorithms ........................................................................................64 Algorithm exercises................................................................................................68 LCD programming exercises..................................................................................69 LCD programming exercises..................................................................................69 Scrolling Message Assignment..............................................................................70 Strings Assignment................................................................................................71 ASCII Character Table...........................................................................................73 ASCII Assignment..................................................................................................74 Time.......................................................................................................................77 Sounding Off..........................................................................................................81 System and Software Design.........................................................................................84 Understanding how simple systems work ..............................................................84 Problem Decomposition Example..........................................................................85 Statecharts.............................................................................................................87 Token Game – Statechart Design Example...........................................................90 Serial Communications ..................................................................................................95 RS 232 Serial Communications .............................................................................97 Serial IO using Inkey() .........................................................................................102 Introduction to I2C................................................................................................103 Real Time Clocks.................................................................................................105 DS1307 RTC........................................................................................................107 Arrays ..........................................................................................................................112 Computer Programming detail .....................................................................................115 AVR Internals – how the microcontroller works....................................................116
Recommended publications
  • Converting a Microcontroller Lab from the Freescale S12 to the Atmel Atmega32 Processor
    ASEE-NMWSC2013-0025 Converting a Microcontroller Lab From The Freescale S12 to the Atmel ATmega32 Processor Christopher R. Carroll University of Minnesota Duluth [email protected] Abstract During the summer of 2013, the laboratory supporting the microcontroller course at the University of Minnesota Duluth was completely re-implemented. For the last several years, the processor that has been used was the Freescale S12, a popular 16-bit microcontroller with a long ancestral history 1. The recent popularity of the Atmel AVR series of microcontrollers, as used in the Arduino microcomputers, for example, has prompted a change in the lab to use Atmel’s ATmega32 microcontroller, an 8-bit member of the AVR family of microcontrollers 2,3 . The new processor has a fundamentally different architecture than that used in the past, but the input/output resources available are much the same. This paper addresses issues that will be faced in the conversion when the course is taught with the new lab hardware for the first time in the Fall. At the very fundamental level, the S12 and ATmega32 differ in architecture. The S12 is a Princeton architecture computer (single memory for both program and data), while the ATmega32 is a Harvard architecture computer (separate program and data memories). The S12 is clearly a CISC machine (Complex Instruction Set Computer) while the ATmega32 is clearly a RISC machine (Reduced Instruction Set Computer). These differences will affect how the microcontroller course is taught when it is offered in the Fall using this new lab. Fortunately, however, the collection of input/output devices in the AVR microcontrollers mimics closely what is found in the S12, so that many of the existing lab exercises will be used again with only minor tweaking.
    [Show full text]
  • 8051 Programmer
    T51prog2 MCS51 series and Atmel AVR microcontrollers ISP capable fast programmer Short description: 10692 supported devices from 149 manufacturers by 2.75 version of SW (21. Dec. 2010) small, very fast and powerful portable programmer of MCS51 series and Atmel AVR microcontrollers in-circuit serial programming (ISP) capability included program also serial EEPROMs DIL40 ZIF socket, all MCS51/AVR chips in DIL package up to 40 pins are supported without adapters connection to PC: USB port USB 2.0 full speed and USB 1.1 compatible upgradeable to SmartProg2 programmer. comfortable and easy to use control program, work with all versions of MS Windows from Windows 98 to Window 7 64-bit free SW update, download from Internet power supply, cable and software included approved by CE laboratory to meet CE requirements made in Slovakia Available accessories: Programming Adapters (Socket Converters) Diagnostic POD for ISP connector upgrade kit Xprog2 to SmartProg2 Features GENERAL T51prog2 is the next member of new generation MS Windows (from Windows 98 to Window 7 64-bit) based ELNEC specialized programmers . Programmer is capable to support all currently available microcontrollers of the MCS51 series (up to 40 pins) and the AVR microcontrollers (8-40 pins) using parallel and serial algorithms. T51prog2 has been developed in close cooperation with Atmel W&M. , therefore programmer's hardware is focused to support all current and future microcontrollers of Atmel W&M MCS51 family. T51prog2 is a small, very fast and powerful portable programmer for MCS51 series and Atmel AVR microcontrollers. T51prog also programs serial EEPROM with IIC (24Cxx), Microwire (93Cxx) and SPI (25Cxx) interface types.
    [Show full text]
  • 8-Bit Microcontrollers 32-Bit Microcontrollers and Application
    8-bit Microcontrollers 32-bit Microcontrollers and Application Processors QUICK REFE R ENCE GUIDE February 2009 Everywhere You Are® AVR Introduction Atmel® offers both 8-bit and 32-bit AVR®s. AVR microcontrollers and application processors deliver unmatched flexibility. AVR combines the most code-efficient architecture for C and assembly programming with the ability to tune system parameters throughout the entire life cycle of your key products. Not only do you get to market faster, but once there, you can easily and cost-effectively refine and improve your product offering. The AVR XMEGA gives you 16-bit performance and leading low-power features at 8-bit price. It’s simple: AVR works across the entire range of applications you’re working on... or want to work on. & Introduction QUICK REFERENCE GUIDE AVR Key Benefits AVR32 Key Benefits High performance High CPU performance picoPower™ technology Low power consumption High code density High data throughput High integration and scalability Low system cost Complete tool offering High reliability Atmel’s AVR is addressing the 8-bit and 16-bit market Easy to use Environment Friendly Packages For AVR and AVR32 microcontrollers and application processors, all the lead free packages are RoHS compliant, lead free, halide free and fully green. All parts are offered in fully green packaging only. Product Range Atmel microcontrollers - success through innovation Atmel offers both 8-bit and 32-bit AVR’s, and since day one the AVR philosophy has always been clear: Highest performance with no power penalty. tinyAVR 1-16 KBytes Flash, 8-32 pin packages megaAVR 4-256 KBytes Flash, 28-100 pin packages AVR XMEGA 16-384 KBytes Flash, 44-100 pin packages AVR32 UC3 16-512 KBytes Flash, 48-144 pin packages AVR32 AP7 Up to 32 KBytes On-chip SRAM, 196-256 pin packages & QUICK REFERENCE GUIDE Product Range Product Product Range Range Product Families tinyAVR® General purpose microcontrollers with up to 16K Bytes Flash program memory, 512 Bytes SRAM and EEPROM.
    [Show full text]
  • 2 XII December 2014
    2 XII December 2014 www.ijraset.com Volume 2 Issue XII, December 2014 ISSN: 2321-9653 International Journal for Research in Applied Science & Engineering Technology (IJRASET) Overview and Comparative Study of Different Microcontrollers Rajratna Khadse1, Nitin Gawai2, Bagwan M. Faruk3 1Assist.Professor, Electronics Engineering Department, RCOEM, Nagpur 2,3Assist.Professor, E & Tc Engineering Department, JDIET, Yavatmal Abstract—A microcontroller is a small and low-cost computer built for the purpose of dealing with specific tasks, such as displaying information on seven segment display at railway platform or receiving information from a television’s remote control. Microcontrollers are mainly used in products that require a degree of control to be exerted by the user. Today various types of microcontrollers are available in market with different word lengths such as 8bit, 16bit, 32bit, and microcontrollers. Microcontroller is a compressed microcomputer manufactured to control the functions of embedded systems in office machines, robots, home appliances, motor vehicles, and a number of other gadgets. Therefore in today’s technological world lot of things done with the help of Microcontroller. Depending upon the applications we have to choose particular types of Microcontroller. The aim of this paper to give the basic information of microcontroller and comparative study of 8051 Microcontroller, ARM Microcontroller, PIC Microcontroller and AVR Microcontroller Keywords— Microcontroller, Memory, Instruction, cycle, bit, architecture I. INTRODUCTION Microcontrollers have directly or indirectly impact on our daily life. Usually, But their presence is unnoticed at most of the places like: At supermarkets in Cash Registers, Weighing Scales, Video games ,security system , etc. At home in Ovens, Washing Machines, Alarm Clocks, paging, VCR, LASER Printers, color printers etc.
    [Show full text]
  • An Overview of Atmega AVR Microcontrollers Used in Scientific Research and Industrial Applications
    Pomiary Automatyka Robotyka, R. 19, Nr 1/2015, 15–20, DOI: 10.14313/PAR_215/15 An Overview of ATmega AVR Microcontrollers Used in Scientific Research and Industrial Applications Wojciech Kunikowski, Ernest Czerwiński, Paweł Olejnik, Jan Awrejcewicz Department of Automation, Biomechanics and Mechatronics, Lodz University of Technology, 90–924 Łódź, 1/15 Stefanowski str. Abstract: Nowadays, microcontrollers are commonly used in many fields of industrial applications previously dominated by other devices. Their strengths such as: processing power, low cost, and small sizes enable them to become substitutes for industrial PLC controllers, analog electronic circuits, and many more. In first part of this article an overview of the Atmel AVR microprocessor family can be found, alongside with many scientific and industrial applications. Second part of this article contains a detailed description of two implementations of ATmega644PA microprocessor. First one is a controller with PID regulation that supports a DC motor driver. Second one is a differential equation solver with 4-th order Runge-Kutta method implemented. It is used for solving a torsion pendulum dynamics. Finally, some general conclusions regarding the two presented implementations are made. Keywords: Atmel, AVR, ATmega, microcontroller, torsion pendulum, PID control, DC motor, PWM control 1. Introduction the performance and compact dimensions of control units are the most important requirements. The described micropro- 1.1. Overview of some Atmel microcontrollers cessor characterizes also with very low power consumption. AVR ATmega is a family of 8-bit microprocessors from Atmel. It is the only processor in AVR family that works with 0.7 V Their features vary across models, but mostly, the following power supply.
    [Show full text]
  • Single-Board Microcontrollers
    Embedded Systems Design (0630414) Lecture 15 Single-Board Microcontrollers Prof. Kasim M. Al-Aubidy Philadelphia University Single-Board Microcontrollers: • There is a wide variety of single-board microcontrollers available from different manufacturers and suppliers of microcontrollers. • The most common microcontroller boards are: – Intel Boards: based on Intel microcontrollers. – ARM Boards: based on ARM7 microcontrollers. – Cortex Boards: based on Cortex microcontrollers. – AVR Boards: based on Atmel AVR microcontrollers. – MSP430 Boards: based on Texas Instruments microcontrollers. – PIC Boards: based on the Microchip PIC microcontrollers. – Motorola Boards: based on Motorola microcontrollers. – ARDUNIO Boards: based on Atmel AVR microcontrollers. •It is not easy to decide on which microcontroller to use in a certain application. However, Arduino is becoming one of the most popular microcontrollers used in industrial applications and robotics. •There are different types of Arduino microcontrollers which differ in their design and specifications. The following table shows comparison between the Arduino microcontrollers. Ref: http://www.robotshop.com/arduino-microcontroller-comparison.html The Arduino Uno board: Hardware design of the Arduino Uno board: Single-Board Microcontroller + ZigBee Example: Mobile Robot control using Zigbee Technology Single-Board Microcontroller Selection: The selection guide for using the suitable microcontroller includes: 1. Meeting the hardware needs for the project design; - number of digital and analog i/o lines. - size of flash memory, RAM, and EPROM. - power consumption. - clock speed. - communication with other devices. 2. Availability of software development tools required to design and test the proposed prototype. 3. Availability of the microcontroller..
    [Show full text]
  • Atmel AVR Microcontrollers for Automotive
    Atmel AVR Microcontrollers for Automotive +150°C Qualified Innovative Atmel AVR Several AVR microcontrollers are qualified for operation up to +150°C ambient Microcontroller Solutions for temperature (AEC-Q100 Grade0). These devices enable designers to distribute Automotive intelligence and control functions directly into or near, transfer cases, engine sensors Increasing consumer demands for comfort, safety and reduced actuators, turbochargers and exhaust fuel consumption are driving rapid growth in the market for systems. automotive electronics. All the new functions designed to meet Automotive AVR microcontrollers available these demands require local intelligence and control, which can as Grade0 versions are the Atmel ATtiny45, be optimized by the use of small, powerful microcontrollers. ATtiny87/167, ATtiny261/461/861, ATmega88/168, ATmega16M1, Atmel® leverages its unsurpassed experience in embedded ATmega32M1, ATmega32C1, Flash memory microcontrollers to bring innovative solutions ATmega64M1, and ATmega64C1. for automotive applications. These include a wide range of Atmel AVR® 8- and 32-bit microcontrollers for everything from Automotive AVR microcontrollers are sensor or actuator control to more sophisticated networking available in two different temperature ranges applications. Atmel microcontrollers are fully engineered to to serve various applications: fulfill the quality requirements of OEMs in their drive towards AEC-Q100 Grade1 Z: -40°C to +125°C zero defects. AEC-Q100 Grade0 D, T2: -40°C to +150°C Typical Applications Atmel
    [Show full text]
  • Rutronik MCHP Solution
    Presented by: Lucio Di Jasio MCU8 Business Development Manager This presentation will give you an overview of Microchip as a company Our Analog portfolio Our MCUs in general MCU8 in particular 2 Corporate Overview Leading provider of: • High-performance, field-programmable RISC Microcontrollers and Digital Signal Controllers • Mixed-Signal, Analog, Interface and Security products • Wireless and RF products • Non-volatile EEPROM and Flash Memory products • Flash IP solutions • Clock and Timing solutions ~ $3.3 Billion revenue run rate ~14,000 employees Headquartered near Phoenix in Chandler, AZ 3 Worldwide Technical Support Centers Bucharest St. Petersburg Copenhagen Kaohsiung Dublin Manila Haan Nanjing Karlsruhe Osaka London Qingdao Madrid Seoul Milan Daegu Munich Dongguan Atlanta Tel Aviv Austin Padova Shanghai Boston Paris Shenyang Chicago Vienna Shenzhen Cleveland Warsaw Singapore Bangalore Dallas Wels Taipei Bangkok Detroit Tokyo Beijing Kokomo Wuhan Chengdu Los Angeles Xiamen Chongqing New York Xian Guangzhou Phoenix Zhuhai Hangzhou San Jose Sao Paulo Hong Kong Toronto Johannesburg Sydney Hsinchu Melbourne Kuala Lumpur New Delhi Penang Pune The only non-commissioned sales team in the semiconductor industry 4 Annual Net Sales Growth 2500 2400 2300 • 102 consecutive quarters of profitability! 2200 2100 2000 1900 1800 1700 1600 1500 1400 1300 $ Million 1200 1100 1000 900 800 700 600 500 400 300 200 100 0 FY93 FY94 FY95 FY96 FY97 FY98 FY99 FY00 FY01 FY02 FY03 FY04 FY05 FY06 FY07 FY08 FY09 FY10 FY11 FY12 FY13 FY14 FY15 FY16 5 Broadening
    [Show full text]
  • Avr-Microcontrollers-In-Linux-Howto
    Avr-Microcontrollers-in-Linux-Howto Revision History Revision 44 2009-04-20 17:13:07 Revised by: jdd obfuscate e-mail at the author demand Revision 43 2009-03-29 20:49:12 Revised by: ranjeeth Revision 42 2009-03-29 20:45:09 Revised by: jdd reverting after publication Revision 41 2009-03-29 20:41:59 Revised by: jdd edit to export docbook Revision 40 2009-03-28 21:07:57 Revised by: RickMoen Adjust style of mailto link to author's original preference. Revision 39 2009-03-28 21:05:45 Revised by: RickMoen Revert e-mail obfuscation, supply some missing punctuation, [re-]fix capitalisation, fix and clarify new run-on sentence. Revision 38 2009-03-23 18:21:24 Revised by: ranjeeth Revision 37 2009-03-23 18:19:51 Revised by: ranjeeth Revision 36 2009-03-23 17:20:32 Revised by: ranjeeth Revision 35 2009-03-23 17:19:47 Revised by: ranjeeth Revision 34 2009-03-23 10:26:00 Revised by: jdd publishing tests Revision 33 2009-03-23 10:25:06 Revised by: jdd Revision 32 2009-03-23 10:24:24 Revised by: jdd use of macro to obfuscate e-mail Revision 31 2009-03-23 10:11:47 Revised by: jdd change was only to export docbook without admonitions Revision 30 2009-03-23 10:09:15 Revised by: jdd Revision 29 2009-03-23 10:05:07 Revised by: jdd Revision 28 2009-03-23 09:58:40 Revised by: jdd adding the wiki as link Revision 27 2009-03-23 09:53:28 Revised by: RickMoen Insert needed space characters into "pin9", "pin10", "pin25" constructs Revision 26 2009-03-23 09:49:05 Revised by: RickMoen Make markup of all the software items mentioned be consistent Revision 25 2009-03-23 09:43:40 Revised by: RickMoen Remove a couple of stray commas.
    [Show full text]
  • UNIT-I - OVERVIEW of EMBEDDED SYSTEMS Embedded System
    UNIT-I - OVERVIEW OF EMBEDDED SYSTEMS Embedded System . An embedded system can be thought of as a computer hardware system having software embedded in it. An embedded system can be an independent system or it can be a part of a large system. An embedded system is a microcontroller or microprocessor based system which is designed to perform a specific task. For example, a fire alarm is an embedded system; it will sense only smoke. An embedded system has three components − It has hardware. It has application software. It has Real Time Operating system (RTOS) that supervises the application software and provide mechanism to let the processor run a process as per scheduling by following a plan to control the latencies. RTOS defines the way the system works. It sets the rules during the execution of application program. A small scale embedded system may not have RTOS. So we can define an embedded system as a Microcontroller based, software driven, reliable, real-time control system. Characteristics of an Embedded System Single-functioned − An embedded system usually performs a specialized operation and does the same repeatedly. For example: A pager always functions as a pager. Tightly constrained − All computing systems have constraints on design metrics, but those on an embedded system can be especially tight. Design metrics is a measure of an implementation's features such as its cost, size, power, and performance. It must be of a size to fit on a single chip, must perform fast enough to process data in real time and consume minimum power to extend battery life.
    [Show full text]
  • Controlling Home Appliances Using Internet
    CONTROLLING HOME APPLIANCES USING INTERNET Project Report submitted in partial fulfillment of the requirement for the degree of Bachelor of Technology In Information Technology Under the Supervision of Mr. Amol Vasudeva Assistant Professor By ANIRUDH KAUSHIK (111478) Jaypee University of Information and Technology Waknaghat, Solan– 173234, Himachal Pradesh i Certificate This is to certify that project report entitled “Controlling Home Appliances Using Internet”, submitted by Anirudh Kaushik in partial fulfillment for the award of degree of Bachelor of Technology in Information Technology in Jaypee University of Information Technology, Waknaghat, Solan has been carried out under my supervision. This work has not been submitted partially or fully to any other University or Institute for the award of this or any other degree or diploma. Date: 8th May 2015 Mr. Amol Vasudeva (Assistant Professor) ii Acknowledgement No venture can be completed without the blessings of the Almighty. I consider it my bounded duty to bow to Almighty whose kindness has always inspired me on the right path. I would like to take the opportunity to thank all the people who helped us in any form in the completion of my project “Controlling Home Appliances using Internet”. It would not have been possible to see through the project without the guidance and constant support of my project guide Mr. Amol Vasudeva. For his coherent guidance, careful supervision, critical suggestions and encouragement I feel fortunate to be taught by him. I would like to express my gratitude towards Brig. (Retd) Balbir Singh, Director JUIT, for having trust in me. I owe my heartiest thanks to Prof.
    [Show full text]
  • Beginners Introduction to the Assembly Language of ATMEL-AVR-Microprocessors
    Beginners Introduction to the Assembly Language of ATMEL-AVR-Microprocessors by Gerhard Schmidt http://www.avr-asm-tutorial.net September 2021 History: Added chapters on binary floating points and on memory access in September 2021 Added chapter on code structures in April 2009 Additional corrections and updates as of January 2008 Corrected version as of July 2006 Original version of December 2003 Avr-Asm-Tutorial 2 http://www.avr-asm-tutorial.net Content Why learning Assembler?..........................................................................................................................1 Short and easy.......................................................................................................................................1 Fast and quick........................................................................................................................................1 Assembler is easy to learn.....................................................................................................................1 AVRs are ideal for learning assembler..................................................................................................1 Test it!....................................................................................................................................................2 Hardware for AVR-Assembler-Programming...........................................................................................3 The ISP-Interface of the AVR-processor family...................................................................................3
    [Show full text]