Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | /*! \file avrcore.c \brief AVR-Core Board Driver Functions. */ |
2 | //***************************************************************************** |
||
3 | // |
||
4 | // File Name : 'avrcore.c' |
||
5 | // Title : AVR-Core Board Driver Functions |
||
6 | // Author : Pascal Stang - Copyright (C) 2004 |
||
7 | // Created : 2004.10.1 |
||
8 | // Revised : 2004.10.1 |
||
9 | // Version : 0.1 |
||
10 | // Target MCU : Atmel AVR series |
||
11 | // Editor Tabs : 4 |
||
12 | // |
||
13 | // This code is distributed under the GNU Public License |
||
14 | // which can be found at http://www.gnu.org/licenses/gpl.txt |
||
15 | // |
||
16 | //***************************************************************************** |
||
17 | |||
18 | //----- Include Files --------------------------------------------------------- |
||
19 | #include <avr/io.h> // include I/O definitions (port names, pin names, etc) |
||
20 | #include <avr/interrupt.h> // include interrupt support |
||
21 | |||
22 | #include "global.h" // include our global settings |
||
23 | #include "avrcore.h" |
||
24 | |||
25 | // globals |
||
26 | u08 AvrcoreLatch; |
||
27 | |||
28 | // functions |
||
29 | void avrcoreInit(void) |
||
30 | { |
||
31 | // initialize ports to input with pullup |
||
32 | // (this is done to avoid contentions and input-pin oscillation) |
||
33 | outb(DDRA, 0x00); |
||
34 | outb(DDRB, 0x00); |
||
35 | outb(DDRC, 0x00); |
||
36 | outb(DDRD, 0x00); |
||
37 | outb(DDRE, 0x00); |
||
38 | outb(DDRF, 0x00); |
||
39 | outb(PORTA, 0xFF); |
||
40 | outb(PORTB, 0xFF); |
||
41 | outb(PORTC, 0xFF); |
||
42 | outb(PORTD, 0xFF); |
||
43 | outb(PORTE, 0xFF); |
||
44 | outb(PORTF, 0xFF); |
||
45 | // turn on RAM interface |
||
46 | sbi(MCUCR, SRE); |
||
47 | // initialize RAM page |
||
48 | avrcoreSetRamPage(0); |
||
49 | // initialize LEDs |
||
50 | avrcoreSetLeds(0); |
||
51 | // set serial power to on by default |
||
52 | avrcoreSetSerialPortPower(1); |
||
53 | } |
||
54 | |||
55 | void avrcoreSetRamPage(u08 page) |
||
56 | { |
||
57 | // update latch state |
||
58 | AvrcoreLatch &= ~AVRCORELATCH_ADDRMASK; |
||
59 | AvrcoreLatch |= page & AVRCORELATCH_ADDRMASK; |
||
60 | // write new latch state to latch |
||
61 | AVRCORELATCH = AvrcoreLatch; |
||
62 | } |
||
63 | |||
64 | void avrcoreSetLeds(u08 leds) |
||
65 | { |
||
66 | // NOTE: LEDs are negative-logic (active-low) |
||
67 | // update latch state |
||
68 | AvrcoreLatch |= AVRCORELATCH_LEDMASK; |
||
69 | AvrcoreLatch &= ~(leds<<4); |
||
70 | // write new latch state to latch |
||
71 | AVRCORELATCH = AvrcoreLatch; |
||
72 | } |
||
73 | |||
74 | void avrcoreSetLedsOn(u08 leds) |
||
75 | { |
||
76 | // NOTE: LEDs are negative-logic (active-low) |
||
77 | // update latch state to turn on inidicated leds |
||
78 | AvrcoreLatch &= ~(leds<<4); |
||
79 | // write new latch state to latch |
||
80 | AVRCORELATCH = AvrcoreLatch; |
||
81 | } |
||
82 | |||
83 | void avrcoreSetLedsOff(u08 leds) |
||
84 | { |
||
85 | // NOTE: LEDs are negative-logic (active-low) |
||
86 | // update latch state to turn off inidicated leds |
||
87 | AvrcoreLatch |= (leds<<4); |
||
88 | // write new latch state to latch |
||
89 | AVRCORELATCH = AvrcoreLatch; |
||
90 | } |
||
91 | |||
92 | void avrcoreSetSerialPortPower(u08 on) |
||
93 | { |
||
94 | // this function simply manipulates LED3/power control |
||
95 | if(on) |
||
96 | AvrcoreLatch &= ~(0x80); |
||
97 | else |
||
98 | AvrcoreLatch |= (0x80); |
||
99 | // write new latch state to latch |
||
100 | AVRCORELATCH = AvrcoreLatch; |
||
101 | } |
Powered by WebSVN v2.8.3