An AVR is a type of microcontroller, and not just any microcontroller - AVRs are some of the fastest around. I like to think of a microcontroller as a useless lump of silicon with amazing potential. It will do nothing without but almost anything with the program that you write. | .s Comp. À AVR An Introductory Course John Morton Newnes OXFORD AMSTERDAM BOSTON LONDON NEW YORK PARIS SAN DIEGO SAN FRANCISCO SINGAPORE SYDNEY TOKYO HIB Newnes An imprint of Elsevier Science Linacre House Jordan Hill Oxford 0X2 8DP 225 Wildwood Avenue Woburn MA 01801-2041 First published 2002 Copyright 2002. John Morton. All rights reserved The right of John Morton to be identified as the author of this work has been asserted in accordance with the Copyright. Designs and Patent Act 1988 No pan of this publication may be reproduced in any material form including photocopying or storing in any medium by electronic means and whether or not transiently or incidentally to some other use of this publication without the written permission of the copyright holder except in accordance with the provisions of the Copyright. Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licensing Agency Ltd. 90 Tottenham Court Road. London. England WIT 4LP. Applications for the copyright holder s written permission to reproduce any part of this publication should be addressed to the publishers British Library Cataloguing in Publication Data Morton. John. 1980- AVR an introductory course 1. Programmable controllers 2. Integrated circuits - Design and construction Microelectronics I. Title 9 ISBN 0 7506 56352 For information on all Newnes publications visit our website at Typeset by Avocet Typeset Brill Aylesbury Bucks Printed in Great Britain by Biddles Ltd. Guildford and King s Lynn Contents Acknowledgements ix Preface xi 1 Introduction 1 Short bit for PIC users 2 Number systems 3 Adding in binary 5 Negative numbers 6 An 8-bii Flash microcontroller 7 Initial steps 8 Choosing vour model 8 Flowchart 10 Writing 12 Assembling 13 Registers 13 Instructions 17 Program template 18 i 2 Basic Operations with AT90S1200 and Tinyl2 24 Program A LED on 24 AVR Studio - Assembling 25 AVR Studio - Simulating 26 j Emulating 27 i Hardware 27 J .