Objective
This article assumes that you've already created a project for the ATtiny817 Xplained Pro. If you haven't yet done so, please go through the steps in the Creating a Project in Atmel Studio 7 page.
In this lab, you will write code to make LED0 change state when button SW0 is pressed, compile it, and verify the setup.
Materials
Hardware Tools
Software Tools
Tool | About | Installers |
Installation
Instructions |
||
---|---|---|---|---|---|
Windows | Linux | Mac OSX | |||
Atmel® Studio
Integrated Development Environment |
| | | | |
Procedure
The LED and button are connected to the pins as per Table 1, as outlined in the "ATtiny817 Xplained Pro User Guide".
Silkscreen Text | ATtiny817 GPIO pin |
---|---|
LED0 | PB4 |
SW0 | PB5 |
1
Open main.c
Update main() with the following code:
Warning: Be sure to keep the #include <avr/io.h> line at the top of main.c. This header file will include the correct register map for the selected device. Without this statement, the compiler will not recognize any of the macros referenced in the code above.
2
Atmel Studio buttons for programming
Locate the key buttons for programming devices and launching debug sessions in Atmel Studio. They are highlighted in Figure 2. Their associated functionality, as well as corresponding keyboard shortcuts, are outlined in Table 2. All options are also available in the 'Debug' menu.
Button | Functionality | Keyboard Shortcut |
---|---|---|
Start Debugging and Break | Alt + F5 | |
Attach to Target | ||
Start Debugging | F5 | |
Break All | Ctrl + Alt + Break | |
Start Without Debugging | Ctrl + F5 |
3
Start Debug Session
Start a debug session by clicking the Start Debugging button or pressing F5.
Starting the debug session will:
- Compile any changes that have been made to the project since the last compilation
- Program the resulting binary to the ATtiny817
- Launch a debug session
Both the title bar and the bottom status bar of Atmel Studio will be updated to reflect the status of the ongoing debug session.
If the build fails due to an error in the code, an error list will be presented. Double-clicking on an entry will open the file containing the problematic code and position the cursor at, or close to the relevant line of code. After the errors have been corrected, the debug session can be started again by clicking the Start Debugging button.
4
Verify Operation
Push SW0 on the ATtiny 817 Xplained Pro kit and verify that LED0 changes state.
Results
Code has now been written to make the LED change state when the button is pressed, it has been compiled, and the setup has been verified.