00001 /* ============================================================================= 00002 00003 Copyright (c) 2008 Pieter Conradie [www.piconomic.co.za] 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are met: 00008 00009 * Redistributions of source code must retain the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 00012 * Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in 00014 the documentation and/or other materials provided with the 00015 distribution. 00016 00017 * Neither the name of the copyright holders nor the names of 00018 contributors may be used to endorse or promote products derived 00019 from this software without specific prior written permission. 00020 00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00022 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00025 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00026 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00027 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00028 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00029 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00030 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00031 POSSIBILITY OF SUCH DAMAGE. 00032 00033 Title: Atmel AVR LED Blink example 00034 Author(s): Pieter.Conradie 00035 Creation Date: 2007-04-27 00036 Revision Info: $Id: main.c 123 2010-07-27 20:17:20Z pieterc1973@gmail.com $ 00037 00038 ============================================================================= */ 00039 00040 /** 00041 * @ingroup AVR_EXAMPLES 00042 * @defgroup AVR_LED_BLINK /led_blink 00043 * 00044 * This example outputs a string on the serial port and toggles the LED once a 00045 * second. 00046 * 00047 * Files: 00048 * - arch/avr/examples/led_blink/main.c 00049 * 00050 * The following modules are exercised: 00051 * - @ref AVR_SYSTMR 00052 * - @ref PRINTF_MODULE 00053 * - @ref UART0 00054 * - @ref TMR 00055 * - @ref PICONOMIC_AB111_4 00056 * 00057 */ 00058 00059 /* _____STANDARD INCLUDES____________________________________________________ */ 00060 #include <avr/interrupt.h> 00061 00062 /* _____PROJECT INCLUDES_____________________________________________________ */ 00063 #include "common.h" 00064 #include "systmr.h" 00065 #include "printf.h" 00066 #include "uart0.h" 00067 #include "tmr.h" 00068 00069 /* _____LOCAL DEFINITIONS____________________________________________________ */ 00070 00071 /* _____MACROS_______________________________________________________________ */ 00072 00073 /* _____GLOBAL VARIABLES_____________________________________________________ */ 00074 00075 /* _____LOCAL VARIABLES______________________________________________________ */ 00076 00077 /* _____LOCAL FUNCTION DECLARATIONS__________________________________________ */ 00078 00079 /* _____LOCAL FUNCTIONS______________________________________________________ */ 00080 00081 /* _____PUBLIC FUNCTIONS_____________________________________________________ */ 00082 int main(void) 00083 { 00084 tmr_t tmr; 00085 00086 // Initialise the board 00087 board_lowlevel_init(); 00088 00089 // Enable LED 00090 LED_ON(); 00091 00092 // Initialise modules 00093 uart0_init(115200, 8, UART0_NO_PARITY, 1); 00094 printf_init(); 00095 systmr_init(); 00096 00097 // Enable interrupt 00098 sei(); 00099 00100 PRINTF("Atmel AVR LED Blink example\n"); 00101 00102 // Initialise timer to expire once a second 00103 tmr_start(&tmr, TMR_TICKS_PER_SEC); 00104 00105 for(;;) 00106 { 00107 // Wait until timer has expired 00108 while(!tmr_has_expired(&tmr)) 00109 { 00110 ; 00111 } 00112 // Reset timer 00113 tmr_reset(&tmr); 00114 00115 // Toggle LED pin 00116 LED_TOGGLE(); 00117 } 00118 } 00119 00120 /* _____LOG__________________________________________________________________ */ 00121 /* 00122 00123 2009-02-17 : Pieter.Conradie 00124 - First release 00125 00126 */
1.6.3