aboutsummaryrefslogtreecommitdiff
path: root/ATmega48/Source/d_power.r
blob: de229a3e84f96be0073fead8632b3e329abd25c8 (plain)
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
//
// Programmer      
//
// Date init       14.12.2004
//
// Reviser         $Author:: Dktochpe                                        $
//
// Revision date   $Date:: 2-09-05 14:37                                     $
//
// Filename        $Workfile:: d_power.r                                     $
//
// Version         $Revision:: 8                                             $
//
// Archive         $Archive:: /LMS2006/Sys01/Ioctrl/Firmware/Source/d_power. $
//
// Platform        C
//

#ifdef    ATMEGAX8

#define   POWERInit                     {\
                                          PORTC      &= ~0x04;\
                                          DDRC       &= ~0x04;\
                                          DIDR0      |=  0x04;\
                                        }

#define   POWEROff                      {\
                                          PORTD &= ~0x10;\
                                          DDRD  |=  0x10;\
                                        }
                                        
#define   POWEROn                       {\
                                          PORTD |=  0x10;\
                                          DDRD  |=  0x10;\
                                        }

#define   POWERSelect                   {\
                                          PORTD |=  0x04;\
                                          DDRD  |=  0x04;\
                                        }

#define   POWERConvert(V)               {\
                                          ADMUX    =  0x42;\
                                          ADCSRA  &= ~0x07;\
                                          ADCSRA  |=  0x05;\
                                          ADCSRA  |=  0x40;\
                                          while ((ADCSRA & 0x40));\
                                          ADCSRA  |=  0x40;\
                                          while ((ADCSRA & 0x40));\
                                          V        = ADC;\
                                          V       &= 0x7FFF;\
                                          IoFromAvr.Battery &= 0x8000;\
                                          IoFromAvr.Battery |= V;\
                                        }

#define   POWERDeselect                 {\
                                          PORTD &= ~0x04;\
                                          DDRD  |=  0x04;\
                                        }

#define   POWERHigh                     {\
                                          PORTC |=  0x04;\
                                          DDRC  |=  0x04;\
                                        }

#define   POWERFloat                    {\
                                          PORTC &= ~0x04;\
                                          DDRC  &= ~0x04;\
                                        }



#define   POWERExit                     {\
                                          POWEROff;\
                                          POWERDeselect;\
                                          POWERConvert(ADC);\
                                        }

#endif