1 | #ifndef __INIT_H__
|
2 | #define __INIT_H__
|
3 |
|
4 | #include <avr/io.h>
|
5 |
|
6 | #define RPO_CS_I PORTB
|
7 | #define PIN_CS_I PB0
|
8 | #define RPO_CS_U PORTB
|
9 | #define PIN_CS_U PB1
|
10 | #define RPO_LED_R PORTC
|
11 | #define PIN_LED_R PC0
|
12 | #define RPO_LED_G PORTC
|
13 | #define PIN_LED_G PC1
|
14 | #define RPO_REG_EN PORTD
|
15 | #define PIN_REG_EN PD2
|
16 | #define RPO_U_I PORTD
|
17 | #define PIN_U_I PD4
|
18 | #define RPO_P_LOAD PORTD
|
19 | #define PIN_P_LOAD PD5
|
20 | #define ADC_V_TEMP 2
|
21 | #define ADC_V_CUR 6
|
22 | #define ADC_U_REG 7
|
23 |
|
24 | #define ADMUX_U_REG _BV(REFS0) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0)
|
25 | #define ADMUX_V_CUR _BV(REFS0) | _BV(MUX2) | _BV(MUX1)
|
26 | #define ADMUX_V_TEMP _BV(REFS0) | _BV(MUX1)
|
27 | #define ADMUX_2V5 _BV(REFS0) | _BV(MUX1) | _BV(MUX0)
|
28 | #define ADCSRA_ON _BV(ADEN) | _BV(ADIE) | _BV(ADPS2) | _BV(ADPS0)
|
29 | #define ADCSRA_OFF 0
|
30 | #define ADCSRA_RUNNING _BV(ADSC)
|
31 |
|
32 |
|
33 | #define REDLED_ON(); RPO_LED_R &= ~_BV(PIN_LED_R);
|
34 | #define REDLED_OFF(); RPO_LED_R |= _BV(PIN_LED_R);
|
35 | #define GREENLED_ON(); RPO_LED_G &= ~_BV(PIN_LED_G);
|
36 | #define GREENLED_OFF(); RPO_LED_G |= _BV(PIN_LED_G);
|
37 |
|
38 | #define LOAD_ON(); RPO_P_LOAD |= _BV(PIN_P_LOAD);
|
39 | #define LOAD_OFF(); RPO_P_LOAD &= ~_BV(PIN_P_LOAD);
|
40 |
|
41 | #define SELECT_REG_U(); RPO_U_I |= _BV(PIN_U_I);
|
42 | #define SELECT_REG_I(); RPO_U_I &= ~_BV(PIN_U_I);
|
43 | #define REG_U_SELECTED ((RPO_U_I & _BV(PIN_U_I)) != 0)
|
44 | #define REG_I_SELECTED ((RPO_U_I & _BV(PIN_U_I)) == 0)
|
45 | #define SELECT_DAC_U(); RPO_CS_U &= ~_BV(PIN_CS_U);
|
46 | #define UNSELECT_DAC_U(); RPO_CS_U |= _BV(PIN_CS_U);
|
47 | #define SELECT_DAC_I(); RPO_CS_I &= ~_BV(PIN_CS_I);
|
48 | #define UNSELECT_DAC_I(); RPO_CS_I |= _BV(PIN_CS_I);
|
49 |
|
50 | #define REG_ENABLE(); RPO_REG_EN |= _BV(PIN_REG_EN);
|
51 | #define REG_DISABLE(); RPO_REG_EN &= ~_BV(PIN_REG_EN);
|
52 |
|
53 |
|
54 |
|
55 | void init_ports(void);
|
56 | void init_spi(void);
|
57 | void init_timebase(void);
|
58 | void init_usart(void);
|
59 |
|
60 | #endif //__INIT_H__
|