Download:Download free Atmel Studio 6 and install it on your computer. Fire it up and you’ll see something like this:
Click New Project. A new window will be opened, where we have to name our project and choose the directory. Then, select GCC C Executable Project.
In the next step select the microcontroller you want to use – there’s ATxmega128A3U in the X3-DIL64 module from Leon Instruments. Here you can also download the newest version of the datasheet.
After clicking OK a new project is created and Atmel Studio automatically copies code template. Delete it and copy the following code.
#define F_CPU 2000000UL #include <avr/io.h> #include <util/delay.h> int main(void) { PORTE.DIR = 0; // port E as input PORTF.DIR = 0b11111111; // port F as output uint8_t counter = 0; // variable while(1) { counter ++; PORTF.OUT = counter; if(PORTE.IN & (1<<5)) { // if FLIP button released _delay_ms(100); } else { // if FLIP button pressed _delay_ms(50); } } }To compile the program just press F7 key. A console in the bottom of the screen is displayed and you should see Build Succeeded. To check how much memory does out program need, scroll up the text or enlarge the console window.
Programming with FLIP
The processor installed in X3-DIL64 prototyping board is pre-programmed with USB bootloader to let you program the memory with a usual USB cable. Download Atmel Flip and install it.
After connecting the USB cable to the computer, nothing should happen. That’s why because a demonstration program is running. To run the bootloader, please follow this sequence:
- Press RESET and FLIP at the same time
- Release RESET while holding FLIP
- You computer should recognize new USB device
- Release FLIP
- The processor is ready for downloading a new program
Let’s fire up Atmel FLIP. Then, click the icon in the left upper corner and select ATxmega128A3U. Click Select Communication Medium and choice USB, a then open the connection. All program’s features should activate.
Select Load Hex File, with red arrow pointing the book. The HEX file we need to upload is stored in /Debug/xmega-demo.hex location. Important! The path and filename you’ll use should not be excessive complicated and avoid fancy characters. When you’re ready, chlick RUN. The program is loaded to the microcontroller’s memory and it should take less than one second. The last action you need to do, is to click Start Application, to turn off the bootloader and run the downloaded file.
Test
The test program generates various rectangular-shaped signals on port F pins. To see then, just connect a LED diode with 100R serial resistor and the diode should be blinking. When pressing FLIP button, the LED blinks twice faster.
Below you can download the source code:
Download:
0 comments :
Post a Comment
Post a comment