Flying Electron Inc. Logo Flying Electron Inc.
My Account  Cart Contents  Checkout  
  Top » Catalog » Shipping & Returns My Account  |  Cart Contents  |  Checkout   
Categories
Home
Software (1)
NanoComputer (6)
Cables (3)
Crimps, Connectors, and Wire (16)
Development PCBs (9)
Spare Parts
Application Notes



Shopping Cart more
0 items
Bestsellers
01.RS232 Level Shifter Adapter Board [FE_RS232 rev. a]
02.Wiring Harness Connector 2 Position Single Row
03.Wiring Harness Connector 6 Position Single Row
04.* Wire Assembly, Crimps on Both Ends (10 Pack)
05.Atmel AtMega 168 Development Board [FE_M168 rev. b]
06.Extra Long 12" 6 Pin ISP Programming Cable
What's New? more
NanoComputer NC1 Front Case White (Spare Part)
NanoComputer NC1 Front Case White (Spare Part)
$4.99
Quick Find
 
Use keywords to find the product you are looking for.
Advanced Search
Information
Shipping & Returns
Privacy Notice
Conditions of Use
Contact Us
Flying Electron Application Note 1003
LED Simple Example
Background
This application note will demonstrate simple LED control techniques to light LEDs in a very simple animated sequence. This application note uses the Flying Electron FE_M168 Development Board and the Flying Electron FE_LED8 LED Indicator Adapter Board 8 Channel. This application note can also be used as a reference for any AVR microcontroller development board driving LEDs.
Parts Needed
  1. Flying Electron FE_M168
  2. Flying Electron FE_LED8
         
Flying Electron FE_M168
Click to Enlarge
    
Flying Electron FE_LED8
Click to Enlarge
    
Software Needed
  1. Atmel AVR Studio 4
  2. WinAVR
Hardware Setup
Note: Please use the figure below labeled "Flying Electron Application Note 1003 Hardware Setup" as a reference when following the hardware setup steps.
  1. Connect the FE_M168 PORTB HEADER to the FE_LED8 IO PORT HEADER as shown in the diagram below.
    Note: Either of the FE_LED8's two IO PORT HEADERs can be used, however, each pin of the FE_M168 PORTB HEADER should be connected to the corresping pin of the FE_LED8 IO PORT HEADER. i.e. pin 0 to pin 0, pin 1 to pin 1, etc.
  2. Plug the FE_M168's Power Adapter into the FE_M168 POWER JACK



Sample Code

A new project should be created in AVR Studio 4 using the following parameters:
Project Type:AVR GCC
Project Name:FE_AN1003
Project Location:C:\FE_AN1003

After the project has been created, the code below should be placed in the "C:\FE_AN1003\FE_AN1003.c" file created by the AVR Studio 4 project wizard.

The sample code below begins by initializing PORTB to be an output port and setting the initial value of PORTB to be 0x01. After initialization there is a loop which will run forever. Inside the loop, the value of PORTB is left shifted by 1 bit, then a check is made to reset the value of PORTB if no bits are set after the left shifting operation, and finally a delay is added to make the shifting of the bits slow enough to be seen by the human eye.

Because the FE_LED8 board is connected to the FE_M168 PORTB HEADER, the LEDs on the FE_LED8 will show the current value of PORTB. The leds on the FE_LED8 are numbered from 0 to 7 which correspond to the bits 0 to 7 of PORTB. Bits that are high in the value of PORTB will cause the corresponding LED to be lit. Bits that are low in the value of PORTB will cause the corresponding LED to be dark.

Note: The sample code and sample project are available for download in the Download section of this application note.

/****************************************************************************
 *  Flying Electron Inc. Application Note 1003
 *  LED Simple Example
 *  Copyright 2007 Flying Electron Inc.
 ****************************************************************************/

// --------------------------------------------------------------------------
//  Includes
// --------------------------------------------------------------------------
    #include <avr/io.h>         // Include the standard AVR IO definitions
    #include <stdio.h>          // Include the standard IO library

// --------------------------------------------------------------------------
//  Main    
// --------------------------------------------------------------------------
    int main(void) {
        // Set PORTB to be output
            DDRB = 0xFF;

        // Initialize PORTB with starting value
            PORTB = 0x01;

        // Loop Forever
        while (1) {
            // Variables
                uint32_t i;

            // Left Shift PORTB by 1 bit
                PORTB = PORTB << 1;

            // Load PORTB with initial value if bit has been left shifted
            //  out of PORTB
                if (PORTB == 0x00) PORTB = 0x01;

            // Delay by looping and wasting cycles
                for (i = 0; i < 10000; i++) {
                }
        }
    }
The AtMega168 fuses listed in the table below should be set in order for the sample code to run properly. Fuses other then those listed in the table below should be cleared.
Boot Flash section size=1024 words, Boot start address=$1C00
Brown-out detection disabled
Int. RC Osc. 8Mhz; Start-up time PWRDWN/RESET: 6 CK / 14CK + 65ms
For more information on how to set the fuses and perform an ISP programming operation on the FE_M168 to run the sample code, please see the following application notes:
FE_AN1000In System Programming (ISP) using the Atmel STK500
FE_AN1001In System Programming (ISP) using the Atmel AVRISP mkII
Downloads
FE_AN1003.ZIPAVR Studio 4 Project and Source Code
FE_AN1003.HEXFirmware HEX file
This is the end of this Application Note.
For other Application Notes, please see the Application Note Index.

Questions, Comments, Suggestions? We want to here them!
Email sales@flyingelectron.com

Copyright © 2012 Flying Electron Inc.
Powered by osCommerce