Subversion Repositories Projects

Rev

Rev 66 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
45 dhylands 1
/****************************************************************************
2
*
3
*   Copyright (c) 2006 Dave Hylands     <dhylands@gmail.com>
4
*
5
*   This program is free software; you can redistribute it and/or modify
6
*   it under the terms of the GNU General Public License version 2 as
7
*   published by the Free Software Foundation.
8
*
9
*   Alternatively, this software may be distributed under the terms of BSD
10
*   license.
11
*
12
*   See README and COPYING for more details.
13
*
14
****************************************************************************/
15
/**
16
*
17
*   @file   flasher.c
18
*
19
*   @brief  Simple LED flasher for the Baby Orangatang board from Pololu
20
*
21
****************************************************************************/
22
 
23
/* ---- Include Files ---------------------------------------------------- */
24
 
25
#include <avr/io.h>
26
#include <avr/interrupt.h>
27
 
28
/* ---- Public Variables ------------------------------------------------- */
29
 
30
/* ---- Private Constants and Types -------------------------------------- */
31
 
213 dhylands 32
#define LED_DDR        DDRC
33
#define LED_PORT       PORTC
34
#define LED_MASK       ( 1 << 5  )
45 dhylands 35
 
36
/* ---- Private Variables ------------------------------------------------ */
37
 
38
/* ---- Functions -------------------------------------------------------- */
39
 
40
//***************************************************************************
41
/**
42
*   Spin for ms milliseconds
43
*/
44
 
45
#define LOOPS_PER_MS ( CFG_CPU_CLOCK / 1000 / 4)
46
 
47
static void ms_spin( unsigned short ms )
48
{
66 dhylands 49
   if (!ms)
50
           return;
45 dhylands 51
 
66 dhylands 52
   /* the inner loop takes 4 cycles per iteration */
53
   __asm__ __volatile__ (
54
           "1:                     \n"
55
           "       ldi r26, %3     \n"
56
           "       ldi r27, %2     \n"
57
           "2:     sbiw r26, 1     \n"
58
           "       brne 2b         \n"
59
           "       sbiw %1, 1      \n"
60
           "       brne 1b         \n"
61
           : "+w" (ms)
62
           : "w" (ms), "i" (LOOPS_PER_MS >> 8), "i" (0xff & LOOPS_PER_MS)
63
           : "r26", "r27"
64
           );
45 dhylands 65
 
66 dhylands 66
} // ms_spin
67
 
45 dhylands 68
//***************************************************************************
69
/**
70
*   Simple LED flasher
71
*/
72
 
73
int main( void )
74
{
75
    // Initialize the two LED pins
76
 
77
    LED_DDR |= LED_MASK;
78
 
79
    while ( 1 )
80
    {
81
        LED_PORT &= ~LED_MASK;
82
 
83
        ms_spin( 100 );
84
 
85
        LED_PORT |=  LED_MASK;
86
 
87
        ms_spin( 100 );
88
    }
89
}