Transcription of AVR1000b: Getting Started with Writing C-Code for AVR® …
1 TB3262 avr1000b : Getting Started with Writing C-Code for AVR MCUsIntroductionAuthors: Cristina Ionescu, Cristian S biu , Microchip Technology technical brief provides the recommended steps to successfully program the AVR microcontrollers (MCUs) andto define coding guidelines to help Writing more readable and reusable programming languages have become a necessity due to the imposed short development time and high-quality requirements. They make it easier to maintain and reuse code due to better portability and readability than thelow-level instructions specific for each microcontroller language alone does not ensure high readability and reusability, but good coding style does.
2 Therefore,the AVR MCU peripherals, header files and drivers are designed according to this most widely used high-level language for AVR microcontrollers is C, so this document will focus on Cprogramming. To ensure compatibility with most AVR C compilers, the code examples in this document are writtenusing ANSI C coding document contains code examples developed with the Atmel Studio Integrated Development Environment (IDE).Most code examples are compatible with other IDEs, presented in Section 5: Further Steps. 2020 Microchip Technology Inc. Technical BriefDS90003262B-page 1 Table of Sheet Module Structure and Naming to Find the Data Change Protection (CCP) Representation in Header Location in Masks, Bit Group Masks and Group Configuration Bare Metal C-Code for AVR.
3 , Clear and Read Register Register Bit Field of Using Bit Masks and Group Configuration to Configuration Change Protection (CCP) Calls Using Module Example Showing Alternative Ways of Writing Notes and Technical Briefs Videos for Bare Metal AVR XC8 (MPLAB X, Atmel Studio, IAR) Getting 35 The Microchip Change Notification 36 Microchip Devices Code Protection TB3262 2020 Microchip Technology Inc. Technical BriefDS90003262B-page 2 Legal 37 Quality Management 37 Worldwide Sales and TB3262 2020 Microchip Technology Inc.
4 Technical BriefDS90003262B-page 31. Data Sheet Module Structure and Naming ConventionsThe first step in Writing C-Code for a microcontroller is to know and understand what type of information can be foundin the data sheet of the device used for programming. The data sheet contains information about the features, thememories, the core and the peripheral modules of the microcontroller, the functional description of the peripheralmodules, the peripherals base addresses, the names and addresses of the registers, and other functional andelectrical How to Find the Data SheetAny documentation related to Microchip products can be found at: Microchip Data SheetsThe device data sheets, for the device families of interest in this document, can be found at.
5 ATtiny416 Overview ATtiny212 Overview ATtiny3217 Overview ATtiny1634 Overview ATmega4809 Overview ATmega808 Overview AVR128DA28 Pin DescriptionThe pin description can be found in any device data sheet. The pinout is contained in the Pinout, Pin Configurationssection, or any other name convention, depending on the device. The pinout of the ATmega809/1609/3209/4809 48-pin devices is presented in Figure 1-1. TB3262 Data Sheet Module Structure and Naming .. 2020 Microchip Technology Inc. Technical BriefDS90003262B-page 4 Figure 1-1. ATmega809/1609/3209/4809 48-Pin Pinout(1)1234444342414039385678910113332 3130292827262524233736353412131415161718 1920212245464748 GNDVDDPA5PA6PA7PC0PC1PC4PC5PD2PD3PD6PD7P B0PD0PD1PC3PA2PA3PB1PB2PB3PE1PE2PE0PE3PC 2 GNDVDDPF2PF3PF0(TOSC1)PF1(TOSC2)PF4PD5PC 6PC7 UPDIPF5PF6PA1PA4PD4PB4PB5 GNDAVDDPA0(EXTCLK)
6 GPIO on VDD power domainGPIO on AVDD power domainClock, crystalProgramming, debugInput supplyGroundTWIA nalog functionsDigital functions onlyPowerFunctionalityThe configurable functionalities for each I/O pin are described in the I/O Multiplexing and Considerations section, orthe Alternate Port Functions subsection of the I/O Ports section, depending on the device. If an evaluation board isused, such as AVR128DA48 Curiosity Nano, the user needs to know how the microcontroller s pins are allocated onthe specific board. The information is available on the AVR128DA48 Curiosity Nano webpage, in the AVR128DA48 Curiosity Nano Schematics document.
7 Other documents that describe the AVR128DA48 Curiosity Nano board andmicrocontroller characteristics are available on the same webpage. TB3262 Data Sheet Module Structure and Naming .. 2020 Microchip Technology Inc. Technical BriefDS90003262B-page Modules DescriptionAn AVR microcontroller is comprised of several building blocks: AVR CPU, SRAM, Flash, EEPROM and severalperipheral modules called module types. Throughout this document, all peripheral modules will be referred to AVR microcontroller families can have one or more instances of a given module type.
8 All instances have thesame features and functions. Some module types are a subset of others and inherit some of their features. Theinherited features are fully compatible with the respective module type. For example, the subset module for a timercan have fewer compare and capture channels than a full timer 1-2. Modules Types, Instances, Registers and BitsMODULE0 MODULEnRegisterBit 0 Module TypeRegisterRegisterRegisterRegisterRegi sterRegisterRegisterBit 7 Bit 0 Bit 7A module type can be the Universal Synchronous-Asynchronous Receiver Transmitter (USART), while the moduleinstance is, , USART0, where the 0 suffix indicates the instance is USART number 0.
9 For simplicity, a moduleinstance will be referred to as a module throughout this document, unless there is a need to module has a fixed base address in the I/O memory map, and all registers contained in the module have fixedoffset addresses relative to the module base address. This way, each register will not only have an absolute addressin the I/O memory space, but also a relative address defined by its offset. The register offset addresses are equal forall instances of a module type, simplifying the task of Writing drivers that can be used for all modules of a specifictype.
10 The peripheral module address map can be found in the data sheet and shows the base address for module has several registers that contain control or status bits. All modules of a given type contain the sameset (or subset) of registers, and all these registers contain the same set (or subset) of control and status 1-1 presents the base address of some of the ATtiny804/1604 1-1. Peripheral Module Address Map (section)(1)Base AddressNameDescription0x0000 VPORTAV irtual Port A0x0004 VPORTBV irtual Port B0x001 CGPIOG eneral Purpose I/O registers0x0030 CPUCPU0x0040 RSTCTRLR eset Controller TB3262 Data Sheet Module Structure and Naming.