Project

General

Profile

Statistics
| Revision:

root / branches / autonomous_recharging / code / projects / autonomous_recharging / archs / test / main.c @ 802

History | View | Annotate | Download (2.03 KB)

1
#include <avr/io.h>
2
#include <avr/interrupt.h>
3
#include <avr/sleep.h>
4

    
5

    
6
#define LED_GREEN PB4 //Green
7
#define LED_RED PB5 //Red
8
#define INT_COUNT 8
9

    
10
#define LED1 PB4 //Green
11
#define LED2 PB5 //Red
12

    
13

    
14
//The following times are in seconds
15
#define MAX_FAST_TIME 5400
16
#define MAX_TRICKLE_TIME 600
17

    
18
//debug pins
19
#define debug_time PA3
20
#define debug_curr PA4
21
#define debug_volt PA5
22
#define debug_temp PA6
23
#define debug_12in PA7
24

    
25
//be sure admux also sets the MUX5 bit which is in ADCSRB
26
#define ADMUX_I
27
#define ADMUX_V
28
#define ADMUX_T
29

    
30
#define ROBOT_TX PB1
31
#define ROBOT_RX PB2
32
#define PWM PB3
33
#define DETECT_12V PB6
34

    
35

    
36
int interrupt_count=INT_COUNT;
37
volatile int red=0;
38
volatile int green=0;
39
volatile char blink=0;
40

    
41
//copied from Charging.c
42
void setup(void)
43
{
44
  DDRA = (_BV(debug_time)|_BV(debug_curr)|_BV(debug_volt)|_BV(debug_temp)|_BV(debug_12in));
45
  PORTA = 0x00;
46
  DDRB = (_BV(ROBOT_TX)|_BV(PWM)|_BV(LED1)|_BV(LED2)); //confiure output pins
47
  PORTB = 0x00;
48
  
49
  ADCSRA = (_BV(ADEN)|_BV(ADPS2)|_BV(ADPS1)); //start ADC with a division factor of 64
50
  
51
  TCCR0B = (_BV(CS01)); //set timer 0 for realtime mode
52
  TCCR0A = (_BV(TCW0));
53
  TIMSK = (_BV(TOIE0)); //enable overflow interrupts
54
  
55
  TCCR1A = (_BV(COM1B1)|_BV(PWM1B)|_BV(COM1A1)|_BV(PWM1A)); //clear timer 1 on compare, set at 0x00. Fast PWM mode
56
  TCCR1B |= _BV(CS12)|_BV(CS10); //leave timer on and set compare to 0 to make output off        
57
  OCR1B = 0;
58
  OCR1A = 0;
59
  
60
  sei();
61
}
62

    
63

    
64
void blink_red(void) {
65
  red=2;
66
  while(red>0);
67
}
68

    
69
void blink_green(void) {
70
  green=2;
71
  while(green>0);
72
}
73

    
74
void blink_long(void) {
75
  blink=1;
76
  while(red || green);
77
}
78

    
79

    
80
int main(void) {
81
  setup();
82
  
83
  blink_red();
84
  blink_green();
85
  blink_long();
86

    
87
  while(1);
88

    
89
  return 0;
90
}
91

    
92

    
93
ISR(TIMER0_OVF_vect)
94
{
95
        interrupt_count--;
96
        if(interrupt_count==0)
97
        {
98

    
99
          if(blink)
100
            PORTB ^= _BV(LED_RED) | _BV(LED_GREEN);
101

    
102
          if(red>0) {
103
            PORTB ^= _BV(LED_RED);
104
            red--;
105
          }
106
          if(green>0) {
107
            PORTB ^= _BV(LED_GREEN);
108
            green--;
109
          }
110
                        
111
          interrupt_count=INT_COUNT;
112
        }
113
}
114

    
115
ISR(PCINT_vect){;} //so the interrupt doesnt go to the reset vector