Home
Lab Course ``Microcontroller Programming
Contents
1. Do not change the folder structure as you will submit your solutions via Subversion Familiarize yourself with the AVRStudio environment Create a new project and add the file blinky c located in svn exercise01 and printed in listing 1 for reference to your project Compile the code into a firmware image hex and upload it to the device Some LEDs on the board should start blinking Analyze the program you have just compiled Why is the avr io h header file required What is the effect of the following instruction DDRB 0x2A According to the introduction what would be a better way to write the instruction so that it is more human readable In the function wait we used the type int32_t What is the meaning of this data type Which other similar data types are defined in lt WinAVRPath gt avr include stdint h What is the advantage of using int32_t instead of int 8URL https svnknoll informatik tu muenchen de mcp ws1112 gNN with group number NN Listing 1 Simple example program blinky c Requires LEDs to be connected to PORTB include lt avr io h gt void wait int32_t counter while counter gt 0 counter asm volatile nop Prevent optimization int main DDRB 0x2A while 1 Wait some time wait Ox8FFFF Toggle LEDs PORTB 0x2A return 0 15 16 Lab Course Microcontroller Programming PCINT
2. We will cover this topic in subsequent lab course exercises Firmware Microcontrollers are usually used to perform predefined tasks in a periodic manner In this case the program running on a microcontroller is commonly called firmware representing a feature that it is somehow fixed There is no strict or well defined boundary between firmware and software both are quite loose descriptive terms However firmware is typically involved with very basic low level operations in a device without which the device would be completely non functional Because of its periodical behavior the firmware is usually implemented as an endless loop int main x Initialize the system do_init while 1 The periodic task x do_my_task x If we get here the device will halt until being reset af x We usually do not want this to happen hence the while loop return 0 9 16 Lab Course Microcontroller Programming The ATmegal168 Microcontroller We will use the ATmegal68 microcontroller in this lab course It is an 8 bit controller i e 8 bits are being processed per execution cycle The controller can be driven at up to 20 MHz The program memory is 16 KB large and it has 1KB SRAM for variables and 512 bytes EEPROM for configuration storage Furthermore it offers 3 I O interface ports each consisting of multiple physical pins Ports The 3 available ports of ATmegal68 are named port
3. 6 16 Lab Course Microcontroller Programming Basic Elements of a Microcontroller A microcontroller is more than just a Central Processing Unit CPU It is typically a CPU integrated with memory and many other peripherals This integration drastically reduces the number of chips and the amount of pins and wirings required on a printed circuit board and thus reduces the cost Hence the term Microcontroller Unit MCU is also commonly used MCUs have proven to be highly popular in embedded control systems since their introduction in the 1970s MCUs commonly incorporate the following features e CPU typically 8 bit to 32 bit e Clock generator often a crystal or real time clock RC oscillator e ROM EEPROM and flash memory for program and configuration storage e RAM for temporary data storage e General purpose input output pins configurable by software e Timers and Pulse Width Modulation PWM generators e Communication ports like Universal Asynchronous Receiver Transmitter UART Universal Serial Bus USB Controller Area Network CAN etc e Analog Digital Converters ADC and Digital Analog Converters DAC e In System Programming ISP and debugging facilities e g JTAG port Since the MCU offers flash memory we can put the whole program into the controller itself The program will stay there until being overwritten by a different program even if system power is disconnected The memory is similar to the one fou
4. control New files and folders must be manually added to version control for Subversion to consider them If you want to add a file or folder to version control right click on it and choose SVN Add Until committed new files and folders will be marked with the plus overlay see above Removing files from version control If you accidentally added a file or folder that you do not want to be under version control right click on the file or folder and select SVN Delete if the file or folder has already been committed or SVN Undo Add if the file or folder has not yet been committed Until committed deleted files and folders will be marked with the cross overlay see above Note that you can not permanently delete a file from the repository it can always be restored at a later point in time So be careful not to accidentally upload files with passwords or other sensitive information in them Copying moving and renaming files and folders Copying moving and renaming files and folders within a working copy requires some special attention When you rename copy or move a file or folder directly within Windows Explorer Subversion will not notice that the original item and the new item are actually related However for being able to go back to older versions of the file at a later point in time Subversion will need this information Hence you should never copy move or rename a file directly using Windows Explore
5. list Ignored files and folders will be marked with the ignored overlay see above There are two types of ignore lists e The folder based ignore list is a property that can be assigned a different value on each folder in a working copy It will then only affect items within that specific folder To add a file or folder to the folder based ignore list right click on the respective item and choose TortoiseSVN Add to ignore list and choose a matching item Remember that you need to commit the change on the parent folder for it to become effective on other developer s working copies To inspect the list of ignored files right click on the respective folder choose Properties and click the Properties button on the Subversion tab If an ignore pattern has been defined for that folder you should see an item of type svn ignore that you can edit manually from within that dialog Again do not forget to commit your changes on the parent folder for them to become effective e The global ignore list is specific to a user account on the computer and specifies files and folders that should be ignored in any working copy on that computer You can see and edit it from the TortoiseSVN settings dialog right click in Windows Explorer TortoiseSVN Settings General Global ignore pattern Looking up the history of changes Subversion retains a history of all changes to the files at the granularity of commits to the server To take a look
6. result for a specific bit is 1 if both original bits were 1 Example unsigned char x 0b10110011 amp 0b01101001 y 60 amp 13 x is now 0b00100001 y is now 12 b OR operator The OR operator combines two bit patterns numbers The bits on each position are combined individually The result for a specific bit is 1 if either of the original bits was 1 Example unsigned char x 0b10110011 0b01101001 y 60 13 x is now 0b11111011 y is now 61 c XOR operator The XOR operator combines two bit patterns numbers The bits on each position are combined individually The result for a specific bit is 1 if exactly one of the original bits was 1 The symbol to type is a circumflex Example unsigned char x 0b10110011 0b01101001 y 60 13 x is now 0b11011010 y is now 49 d One s complement The one s complement negates each bit of a bit pattern number individually The symbol to type is a tilde AltGr Example unsigned char x 0b10110011 y 60 x is now 0b01001100 y is now 195 1 16 Lab Course Microcontroller Programming e f Shift left lt lt The shift left operator shifts bits of a bit pattern to the left most significant bit adding zero bits on the right and dropping excessive bits on the left Mathematically if only zeros are dropped on the left this corresponds to a multiplication by 2 where n is the number of times to shift Example unsigned char
7. the host PC e 8 LEDs for visualizing the current state of the microcontroller e 8 push buttons switches for interacting with the program on the microcontroller Important note STK500 only supports 6 of the 8 LEDs on the board if used with ATmegal168 and LEDs are connected to port B LED6 and LED7 will not work in this configuration Please make sure that the following cable connections are set up on the development board see also figure 3 This is the initial configuration for all subsequent lab course exercises 3 syn generic atmega168 pdf http atmel com dyn resources prod_documents doc2545 pdf 4 nttp www atmel com 5 syn generic atmega168 pdf http atmel com dyn resources prod_documents doc2545 pdf 6 syn generic stk500 pdf http atmel com dyn resources prod_documents doc1925 pdf T To be precise PB6 and PB7 are not connected to the PORTB header on the STK500 board The reason for this is that an alternative function of these pins is to attach an external clock and STK500 rather uses these pins for that purpose 11 16 Lab Course Microcontroller Programming Figure 3 Initial Setup of STK500 Development Board Programming Connect the primary serial interface of the PC COM1 to the RS232 CTRL interface of the board Use the six wire pin to connect the ISP6PIN header to SPROG2 be sure to connect pin 1 on one connector to the respective pin 1 on the other connector LEDs Connec
8. x 0b10110011 y x lt lt 3 y is now 0b10011000 Shift right gt gt The shift right operator shifts bits of a bit pattern to the right least significant bit adding zero bits on the left and dropping excessive bits on the right Mathe matically this corresponds to a division by 2 and rounding the result down where n is the number of times to shift Example unsigned char x 0b10110011 y x gt gt 3 y is now 0b00010110 All binary operators defined above also allow the assignment of the operation result to the first operator For this purpose use the following notations amp lt lt gt gt Examples a amp 0x02 b 0b00000100 c lt lt 3 Bit Operations A very common task is to modify individual bits Here is how to do it in an efficient way a Building bit masks Many operations require a certain bit mask to be applied to a register or variable A bit mask can be built using many different techniques and the most efficient way to do it depends on the operation to perform e Direct notation of bit masks Bit masks may be directly notated in the source code This is the easiest but also most obfuscated way because there is no chance for the reader to know why the bit mask has been built in this way and there is no easy way to check its correctness Hence it should be avoided if possible Example SPCR 0b01010000 very hard to understand e Direct notation with bit shift
9. 14 RESET PC6 PCINT16 RXD PDO PCINT17 TXD PD1 PC5 ADC5 SCL PCINT13 PCINT18 INTO PD2 PC4 ADC4 SDA PCINT12 PC3 ADC3 PCINT11 PC2 ADC2 PCINT10 PCINT19 OC2B INT1 PD3 PCINT20 XCK T0 PD4 PC1 ADC1 PCINT9 PCO ADCO PCINT8 1 2 3 4 5 6 7 8 vcc GND GND AREF PCINT6 XTAL1 TOSC1 PB6 AVCC PCINT7 XTAL2 TOSC2 PB7 PB5 SCK PCINTS PCINT21 OCOB T1 PDS PB4 MISO PCINT4 PCINT22 OCOA AINO PDE PB3 MOSI OC2A PCINT3 PCINT23 AIN1 PCINTO CLKO ICP1 PD7 PBO PB2 PB1 SS OC1B PCINT2 OC1A PCINT1 Figure 4 Pin Configuration of ATmegal68 f Why is the asm volatile nop instruction required g On which factors does the blinking frequency of the LED depend In which situations might using a wait function like the one defined above be of disadvantage GPIO on ATmegal68 Figure 4 shows the pin configuration of ATmega168 Exercise 1 2 a How many general purpose pins does ATmegal168 have and how are they associated to ports b Develop an application to count the number of times that a button is pressed and display the current count using the LEDs For each button press switch one more LED on up to 6 since PB6 and PB7 are not usable Reset the count to zero if it is larger than 6 c Do you see any problems with the current button press counter implementation How ac curate is it d Try to handle a continuously pressed button like what happens w
10. B C and D The reason why A is left out is that other devices from the AVR family support more ports with different functionality and to keep the naming consistent across all devices the identifier A is not used here Each port has up to 8 pins A pin is a physical digital or analog input or output of the micro controller Now let s see an example We would like to programmatically retrieve the value of the pins of port B of ATmegal68 an 8 bit general purpose I O port First we need to know the address of the respective register This value is of course defined in a header file named lt avr io h gt which we will include later on For reference here is what is defined in that header file for port B define PINB 0x03 Port Input Pin Register define DDRB 0x04 Data Direction Register define PORTB 0x05 Data Register Output Each 8 bit general purpose I O port has three registers associated to it the PINx the DDRx and the PORTx register where x is to be replaced by the respective uppercase letter of the port a Data Direction Register The DDRx registers define which pins of a port should be used as an output and which should be used as an input This can be defined individually for each pin A zero at the respective bit location means that the pin is an input a one means that it is an output pin When powering the device on the DDR registers are set to 0x00
11. Compilers for general purpose languages like C which we will be using will typically have some restrictions as well as enhancements to better support the unique characteristics of microcontrollers Some microcontroller families ship with special development environments to aid developing certain types of applications e g AVRStudio in this lab course 7 16 Lab Course Microcontroller Programming fal Q z fe gt A debugWIRE Supervision POR BOD amp Oscillator Circuits Clock Generation AVCC AREF GND DATABUS RESET XTAL 1 2 PD O 7 PB O 7 PCjO 6 ADC 6 7 Figure 1 ATmegal68 block diagram Data Bus 8 bit Program Counter and Control Memory Interrupt 32x8 Unit Instruction General Register Purpose SPI Instruction Watchdog Decoder a 2 Timer Control Lines 3 2 Comparator pe z oO K D 2 nol a I O Module1 Data VO Module 2 VO Module n V O Lines Figure 2 AVR CPU architecture 8 16 OA Nao KR WN PR RP w Ne Oo Lab Course Microcontroller Programming Input and Output Input and output can either be digital or analog e Digital inputs A typical application for a digital input is attaching a switch or another digital sensor to it Whether the value on the pin is considered O or 1 depends on the input voltage at that pin Since our microcontroller operates at 5V values higher than 3V are considered as high e Digita
12. Lab Course Microcontroller Programming Exercise 1 Introduction and Digital 1 O As this is the first exercise sheet of the lab course it provides a lot of informational prologue to make your life with microcontrollers easier Find the exercises for this session on page 15 Overview on C Notation Bit Manipulation and Operations Throughout this lab course we will program microcontrollers at a quite low level using the C programming language To be able to efficiently program the registers of the microcontroller the following sections will give you some useful hints Notation In the following we will use binary and hexadecimal numbers in the C language e To define a binary number prepend it with Ob e g 0b01010011 83 e To define a hexadecimal number prepend it with Ox e g OxFF Ob11111111 255 Individual bits of a register or variable are always numbered from right to left e g 0 to 7 for an 8 bit number which means that the 1 in the following binary number is located at position 1 not 2 000000010 Bit Manipulation When programming microcontrollers a common task is to modify the values of individual bits of a certain register or variable without changing the value of the other bits Make sure you understand why following bit manipulations yield the given results a AND operator amp The AND operator combines two bit patterns numbers The bits on each position are combined individually The
13. Target 1 In the menu select Tools gt Program AVR gt Connect Select STK500 and the COM port the device is attached to usually COM1 or COM2 If you can t find the correct port use the Windows Device Manager or a program like HyperTerminal to enumerate all available ports 2 In the Main tab select the correct device ATmegal68 as well as ISP mode ISP Frequency can be set to 1 843 MHz maximum value for faster programming 3 Choose the compiled Input HEX file at the Flash area under the Program tab You can use the button to select the file on disk When building a project from within WinAVR the hex file should be located in the default subdirectory of your project Click the Program button to upload it to the controller Warning Do not modify the settings in the other tabs especially not the Fuses or LockBits You could irrevocably lock the microcontroller so that it can not be programmed any more 13 16 Lab Course Microcontroller Programming Exercises start on the next page 14 16 OA Naan AUNE ON NNN NY NN NY FP KF KP BP BP FP KB KF eK eB o Nn ant wNrovUvAa Nt aaet WnNrR OO Lab Course Microcontroller Programming Exercises Digital O A Simple Example Program Exercise 1 1 a b Check out the Subversion repository corresponding to your group to drive Z Ask the tutor for setting up the password for your group Inspect the files you find in your working copy
14. at all changes right click on a working copy folder for which you would like to see the changes and choose TortoiseSVN Show log The dialog shows a list of revisions individual committs at the top When you select a revision you can inspect the associated log message in the middle and the list of affected files at the bottom More Information about Subversion and TortoiseSVN If you need more information about version control the following references are recommended e TortoiseSVN TortoiseSVN A Subversion client for Windows user manual available on line at http tortoisesvn net docs release TortoiseSVN_en or by right clicking on a folder in Windows Explorer and choosing TortoiseSVN Help if TortoiseSVN is in stalled e Subversion Version Control with Subversion e book available online at http svnbook red bean com Microcontrollers Overview of Microcontrollers Over the last decades microcontrollers became ubiquitous in everyday life Microcontrollers play a key role in performing control and signal processing tasks Applications range from from small consumer electronic products like MP3 players and digital cameras over industrial products like cars and aircrafts to power plants In contrast to microprocessors used in standard PCs and servers microcontrollers are designed for dedicated applications Special purpose computer systems con structed with microcontrollers are also known as embedded systems
15. e to time During this procedure the server will send you all files that have been modified on the server since your last update In case other developers modified the same files that you modified Subversion might report during commit that you have to update your working copy first This is necessary to ensure that no comflicting changes are committed to the server since then the code on the server would probably be broken During the update Subversion tries to resolve any pending merge conflicts This is possible as long as no two developers modified the same lines in the same files Only if Subversion is not able to automatically resolve a conflict you will have to manually resolve it Software Requirements For using Subversion from Windows the usage of the TortoiseSVN client is recommended It integrates nicely into Windows Explorer and indicates the status of files e g normal modified added by colored icon overlays TortoiseSVN is preinstalled on the machines in the lab course room Operations in TortoiseSVN Checkout Within Windows Explorer create a new empty folder where you would like to store the working copy Right click onto the folder name and choose SVN Checkout In the dialog specify the following URL of repository https svnknoll informatik tu muenchen de mcp ws1112 gNN where NN corresponds to the two digit number of your group e g 01 Remove the trailing gNN from the Checkout directory path Leave the remaini
16. hen you press a key on the keyboard for a few seconds e Develop a fancy application to toggle one or more LEDs on off Use at least two push buttons on the board You might want to make the blinking frequency adjustable switch LEDs on an off by a press of a button or similar Document your program so that it becomes clear what it does Hints e Note that the LED switch logic of the development board s LEDs and switches might not meet your assumptions To light up an LED you have to write a zero to the corresponding pin The same logic applies to the buttons the corresponding pin is low when a button is pressed Remember Save each of the solutions to the exercises in this lab course as a separate AVRStudio project and commit your solutions together with the answers to the questions to the Subversion repository Do not forget to document your code 16 16
17. ing Instead of directly notating each bit the relevant information can be presented by shifting ones into the respective bits This makes the whole expression a little bit more readable because the bit position numbers are encoded in the operation The _BV macro should be used in this case which has the following definition define _BV bit 1 lt lt bit Note that the result of the shift is calculated by the compiler so there is no runtime overhead involved Example SPCR _BV 6 _BV 4 a little bit better e Naming of bit positions The notation can be further improved if the bit positions have individual names This is true for most special purpose register bits Example SPCR _BV SPE _BV MSTR even better Now it s quite easy to find out that this command enables SPI in master mode at least if you know what the SPCR register is used for This is why this notation is the preferred notation If you can t use this notation for some reason document the bit mask by introducing a comment b Setting individual bits With the technique of bit masks it s now easy to set an individual bit in a register or variable just logically OR it with a bit mask with just that bit set to one Example SPCR _BV SPE enable SPI The above command actually evaluates to SPCR SPCR 0b01000000 2 16 Lab Course Microcontroller Programming c Clearing individual bits Clearing a bit value is a
18. l outputs Digital outputs can be directly attached to LEDs Light Emitting Diodes an energy saving and long living replacement for a small lamp and indirectly to stepper mo tors electromagnetic valves relays and many other components Note that directly attaching some of these components to the microcontroller might destroy the controller because the current flow might be too high If devices that drain a lot of current should be operated by a microcontroller driver circuits e g transistors have to be added in addition e Analog inputs Analog voltage values at a certain physical pin are converted into a digi tal representation by the microcontroller s ADCs Typical applications are potentiometers temperature sensors or light sensors e Analog outputs Some microcontrollers also support generation of different voltages A digital representation of the voltage to generate is then input into a DAC The result can be used to drive components that support a range of operation voltage A simple example would be an LED that should be driven at different levels of brightness However we will later see that using DACs is not the only way to achieve this The same restrictions for current flow mentioned above also apply to analog outputs Digital interfaces can also be used for communication with other devices by physically connecting the two devices and implementing a common protocol on the I O lines Typical examples are RS232 SPI I C or CAN
19. little bit more complicated we have to AND the value with a bit mask set to all ones except the respective bit This is achieved by an additional one s complement Example SPCR amp _BV SPE disable SPI The above command actually evaluates to SPCR SPCR amp 0b10111111 d Toggling individual bits Toggling of bits can be achieved with the XOR operator Example SPCR _BV SPE toggle SPI The above command actually evaluates to SPCR SPCR 0b01000000 Overview on Version Control with Subversion This lab course not only targets to teach you how to program microcontrollers but also how to manage your source code in a reasonable way For this reason we will use version control mechanisms to manage the source code Version control basically means that every incremental change you make to your source code can be individually stored on a server You can go back to older versions of your source code and restored them if necessary We are using the version control system Subversion short SVN in combination with the TortoiseSVN client for this purpose The following sections will provide a quick overview over the features of Subversion and how to use them from TortoiseSVN If you are familiar with these concepts you may skip this section Fi Throughout the lab course when we say svn we mean the path to your local working cop 8 y y 8 y root Advantages of Version Control The na ve approach to ma
20. nage source code is to store it in a single directory and directly modify it when it needs to be adapted This approach has some fundamental drawbacks a You source code is only stored at a single location In case the hard disk drive fails your code will be lost b If you make modifications to the code e g remove an unused function and realize later that you actually needed the old code in a different context you have to rewrite it There is no easy way to get the old code back c Ifyou are not the only one who modifies the code you can quickly get inconsistencies between multiple copies of the code that are hard to merge Of course you could create manual copies of your source code folder from time to time name them such that they remind you of which date the code belongs to distribute copies to other computers to avoid the single point of failure scenario and talk very often with the other developers to avoide merge conflicts However this is cumbersome and involves quite a lot of overhead Version control can help you to ensure safe storage of your code with the ability to go back to older versions while making merging of changes between among developers almost an automatic process Let s have a look at how this works Repository Working Copy and Typical Operations The basic workflow of Subversion is that when you begin to work you first download an appropriate portion of the required files from a server These files are
21. nd in USB sticks or memory cards Figure 1 shows a diagram of the ATmegal168 microcontroller which we will use in this lab course Figure 2 shows the AVR CPU architecture which is common to all controllers of that family Programming Model The programming model represents the programmer s view of the device It typically includes the set of accessible registers and the instruction set In microcontrollers each register has a predefined and unique address usually associated with a meaningful name Reading writing to this address will result in accessing the corresponding register Most registers can be very much used like normal program variables Registers can be divided into two categories a Special purpose registers These registers are used to store the configuration or status of the device For example the 8 bit microcontroller ATmegal168 has a register called CKSEL clock selection that allows to define the frequency at which the MUC operates The meaning of the bit fields in the configuration registers is predefined and needs to be looked up in the MCU s manual b General purpose registers These registers are used to store temporary values AT megal68 includes 32 8 bit general purpose registers RO to R31 The set of general purpose registers is often referred to as register file Microcontrollers were originally programmed only in assembly language but various high level programming languages are nowadays also available
22. ng settings intact and click OK Update Within Windows Explorer right click on your working copy folder and choose SVN Update This will download any updates from the server Commit Within Windows Explorer right click on your working copy folder and choose SVN Commit In the dialog enter a log message describing what you have done since the last update You might want to review the list of changed files in the area below the message text box You can inspect the individual changes by double clicking on an item in that list Remove the check marks from the files that you do not want to upload to the server if any Then click OK tnhttp tortoisesvn net 4 16 Lab Course Microcontroller Programming Understanding icon overlays TortoiseSVN automatically highlights every file in a working copy to reflect its current state The following list explains the most important icon overlays Normal the file or folder is under version control and has not been modified locally Q Modified the file or folder is under version control and has been modified locally Ignored the file or folder is not considered for version control should not be uploaded Unversioned the file is not yet under version control and also not ignored ea Added the file or folder has been added to version control but not yet committed x Deleted the file or folder has been removed from version control but not yet committed Adding files to version
23. r commands if the source and the destination is inside the same working copy You should rather use the appropriate SVN commands e Renaming a file or folder Right click onto the respective file or folder choose TortoiseSVN Rename and enter the new name for the item e Copying a file or folder Right click onto the respective file or folder and drag it to its new location In the popup menu choose SVN copy versioned item s here This will only work if the destination folder is already a working copy folder If it is not yet first add the folder to version control see above You do not have to perform a commit in between e Moving a file or folder Follow the same steps as indicated above but select SVN move versioned item s here from the popup menu e Renaming items during copy or move Follow the same steps as indicated above but select the respective operation from the popup menu There is a way to do this but it requires recreation of the repository on the server 5 16 Lab Course Microcontroller Programming Preventing files from being version controlled Some files and folders should not be version controlled For example compilation artifacts object files executables etc should never be version controlled because they will change with every build and can be easily recreated by a developer on demand To prevent such files and folders from being accidentally committed you should add them to the ignore
24. spective pins will read as 1 c Port Input Pin Register The PINx registers allow to read the current status of the pins regardless of how the respective pins are currently configured Example DDRB 0b00000000 unsigned char b PINB This example defines all pins of port B to be inputs and then stores the current value at the pins in the variable b For a more in depth description of these registers please refer to the ATmegal68 manual With this definition a simple albeit not very meaningful program could look like this Make all pins of port B outputs DDRB OxFF Make all pins of port C inputs x DDRC 0x00 Wait for pin 1 on port C to become high x while 0 PINC amp _BV PC1 Set the value of pin 2 on port B to high x PORTB BV PB2 Development Board and IDE STK500 Development Board ATmegal68 is a low power 8 bit microcontroller developed by Atmel For the key features of this product see the first page of the manual For easy interaction with the microcontroller we are using the STK500 development board which allows us to directly access all relevant signals of the microcontroller The development board features the following components e A socket for the microcontroller already mounted e Connectors for all general purpose input output I O pins of the microcontroller e Serial interfaces for communication with
25. stored on the server in a so called 3 16 Lab Course Microcontroller Programming repository The downloaded copy of the files is called working copy The process of downloading files from a repository to create a new working copyis called checking out the repository A repository can have an arbitrary amount of associated working copies Typically every developer has a single working copy but it is also possible to have multiple of them After checkout every developer works on the files locally i e on their own hard disk drive That means that while working on the files you will not need a connection to the server Modifications include editing of existing files addition deletion renaming copying and moving of files and folders After you have applied and tested your changes you might want to upload them to the server for backup purposes and for being able to go back to this version of the files at a later point in time This will also make the changes available to other developers who work on the same files The process of uploading a set of changes to the server is called commiting the changes Subversion will only upload the files that have actually been modified As multiple members can work in parallel using this system others might as well have committed changes they have made to their local copies of the files In order to obtain the most recent versions of these files you need to update your local repository from tim
26. t PORTB to LEDS using a ten wire cable Switches Connect PORTC to SWITCHES using another ten wire cable Power supply Connect the power supply to the respective connector on the board AVRStudio IDE AVRStudio is a Integrated Development Environment IDE provided by Atmel for writing and debugging applications AVRStudio itself is not shipped with a tool chain for ATmegal68 com piler assembler linker etc rather it relies on external packages to provide those tools to compile a C program In our case we use Win AVR which is a free GCC based tool set Setting up an AVRStudio Project 1 Run AVRStudio by selecting Atmel AVR Tools gt AVR Studio 4 in the start menu You might want to copy the shortcut to your desktop Create a new AVR GCC project Let AVRStudio create the project directory for you but without an initial file Choose AVR Simulator as Debug Platform and ATmega168 as Device Adapt the project settings right click on the project name Edit Configuration Options e General Frequency 16000000 Hz e General Optimization Os 12 16 Lab Course Microcontroller Programming e Custom Options External Tools Make sure the Use WinAVR checkbox is checked 5 Copy your source and header files to the directory you just created or write them 6 Use drag amp drop from Windows Explorer to add the source and header files in the project directory to the project Uploading a Program to the
27. which means that all pins are inputs by default Example DDRB 0b01101000 Pins 0 1 2 4 and 7 of port B are defined as inputs pins 3 6 and 7 as outputs According to the above lecture on bit manipulation a better way to write this would be DDRB _BV DDB7 _BV DDB6 _BV DDB3 b Data Register Output The PORTx registers define which physical pins should be high 5 V when the respective pin is defined as an output according to DDRx Example DDRB 0b11111111 PORTB 0b00001111 All pins of port B are defined as outputs the first four ones are at a level of 5 V the other ones are at a level of 0 V If a pin has been defined as an input the PORTx registers are used to switch on so called pull up resistors They are used to discharge parasitic induction that appears because the open non connected pins of the controller act as an antenna The pull up resistors allow for the input signal to be at a clearly defined level However the pull up resistors resistance is high enough to allow an external circuit to drive the pins to the respective value if needed so there is in general no need to switch the pull up resistors off Note that as the name suggests the pull up resistors pull the level of a pin to high 5 V if the pin is not driven 10 16 OoOmANAtT FR WN Poe H O Lab Course Microcontroller Programming low by the circuit attached to the physical pin This means that the re
Download Pdf Manuals
Related Search
Related Contents
Broan-NuTone 192 Heater この度は、「四輪・ロッキング ヴィクトリー ホース 型式:AQ 取扱説明書 PCA2 User Manual - Bacharach, Inc. MD Bassoon Reed Profiler Instruction and User Manual Bionaire BRH840 Electric Heater User Manual Copyright © All rights reserved.
Failed to retrieve file