OpenCores
URL https://opencores.org/ocsvn/usb_fpga_2_13/usb_fpga_2_13/trunk

Subversion Repositories usb_fpga_2_13

[/] [usb_fpga_2_13/] [trunk/] [examples/] [usb-fpga-1.15/] [1.15d/] [lightshow/] [avr/] [lightshow.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   lightshow -- lightshow on Experimental Board 1.10
3
   Copyright (C) 2009-2014 ZTEX GmbH
4
   http://www.ztex.de
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License version 3 as
8
   published by the Free Software Foundation.
9
 
10
   This program is distributed in the hope that it will be useful, but
11
   WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
   General Public License for more details.
14
 
15
   You should have received a copy of the GNU General Public License
16
   along with this program; if not, see http://www.gnu.org/licenses/.
17
!*/
18
 
19
#include <avr/io.h>
20
 
21
#define F_CPU 32000000UL
22
#include <util/delay.h>
23
 
24
typedef uint8_t byte;
25
 
26
int main(void)
27
{
28
    // enable 32.768 kHz, 32 MHz, 2 Mhz clocks
29
    asm volatile (
30
        "ldi r24,0xd8" "\n\t"
31
        "ldi r23,7" "\n\t"
32
        "out 0x34,r24" "\n\t"
33
        "sts 0x50,r23"
34
        ::: "r24", "r23"
35
    );
36
 
37
    // wait until clocks are ready
38
    while ( (OSC.STATUS & 7) != 7 ) { }
39
 
40
    // enable run time configuration of 32 MHz and 2 MHz clocks; select 32 MHz clock as system clock
41
    asm volatile (
42
        "ldi r24,0xd8" "\n\t"
43
        "ldi r23,1" "\n\t"
44
        "out 0x34,r24" "\n\t"
45
        "sts 0x60,r23" "\n\t"
46
        "out 0x34,r24" "\n\t"
47
        "sts 0x68,r23" "\n\t"
48
        "out 0x34,r24" "\n\t"
49
        "sts 0x40,r23"
50
        ::: "r24", "r23"
51
    );
52
 
53
    // disable JTAG at portb
54
    asm volatile (
55
        "ldi r24,0xd8" "\n\t"
56
        "ldi r23,1" "\n\t"
57
        "out 0x34,r24" "\n\t"
58
        "sts 0x96,r23" "\n\t"
59
        ::: "r24", "r23"
60
    );
61
 
62
    // clock output to PD7
63
    PORTCFG.CLKEVOUT = 2;
64
    PORTD.DIR = 128;
65
 
66
    PORTJ.DIR = 0;       // input: 4 LED's
67
    PORTH.DIR = 0;       // input: 8 LED's
68
    PORTD.DIR |= 15;    // output: 4 LED's
69
    PORTF.DIR = 255;    // output: 8 LED's
70
 
71
    while (1) {
72
        PORTD.OUT = PORTJ.IN;
73
        PORTF.OUT = PORTH.IN;
74
    }
75
}
76
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.