-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperifery.c
134 lines (103 loc) · 2.19 KB
/
perifery.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*************************************************
* Firmware for SKVA-03 IVM
* Shendrik Andrey
* 2016 (c)
*
*************************************************/
/* ----------------------- Platform includes ----------------------------------*/
#include "avr/io.h"
#include "porting.h"
/* -------------------------- Own includes ------------------------------------*/
#include "defines_my.h"
#include "perifery.h"
void vInit_Clock()
{
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
}
/* Initialization of the Timer 0 */
void vInit_Timer0()
{
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 62,500 kHz
// Mode: Normal top=0xFF
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x03;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;
TIMSK0=0x01;
}
/* Stop the Timer 0 */
void vDeInit_Timer0()
{
TCCR0A=0x00;
TCCR0B=0x00;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;
TIMSK0=0x00;
}
/* Initialization of the Timer 2 */
void vInit_RTC_Timer2()
{
// Timer/Counter 2 initialization
// Clock source: Crystal on TOSC1 pin
// Clock value: PCK2/128
// Mode: Normal top=0xFF
// OC2A output: Disconnected
// OC2B output: Disconnected
ASSR=0x20;
TCCR2A=0x00;
TCCR2B=0x05;
TCNT2=0x00;
OCR2A=0x00;
OCR2B=0x00;
while (ASSR & ((1 << TCN2UB)|(1 << OCR2AUB)|(1 << OCR2BUB)|(1 << TCR2AUB)|(1 << TCR2BUB)));
TIMSK2=0x01;
}
/* Initialization of the external interrupt INT2 */
void vInit_ExtInt2()
{
// INT2 Mode: Falling Edge
EICRA=0x20;
EIMSK=0x04;
EIFR=0x04;
PCICR=0x00;
}
void vInit_InternalRelais()
{
RELAY_INIT;
}
void vSet_InternalRelais(UCHAR on)
{
if(on)
{
RELAY_HIGH;
}
else
{
RELAY_LOW;
}
}
void vSetError(UCHAR error)
{
ERROR_INIT();
if(error)
{
ERROR_PORT |= _BV( ERROR_PIN );
}
else
{
ERROR_PORT &= ~_BV( ERROR_PIN );
}
}