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 797 bneuman
#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 802 bneuman
#define INT_COUNT 8
9 797 bneuman
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 802 bneuman
volatile int red=0;
38
volatile int green=0;
39
volatile char blink=0;
40 797 bneuman
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 802 bneuman
void blink_red(void) {
65 797 bneuman
  red=2;
66 802 bneuman
  while(red>0);
67 797 bneuman
}
68
69 802 bneuman
void blink_green(void) {
70 797 bneuman
  green=2;
71 802 bneuman
  while(green>0);
72 797 bneuman
}
73
74 802 bneuman
void blink_long(void) {
75
  blink=1;
76 797 bneuman
  while(red || green);
77
}
78
79
80
int main(void) {
81 802 bneuman
  setup();
82
83 797 bneuman
  blink_red();
84
  blink_green();
85
  blink_long();
86
87 802 bneuman
  while(1);
88
89 797 bneuman
  return 0;
90
}
91
92
93
ISR(TIMER0_OVF_vect)
94
{
95
        interrupt_count--;
96
        if(interrupt_count==0)
97
        {
98 802 bneuman
99
          if(blink)
100
            PORTB ^= _BV(LED_RED) | _BV(LED_GREEN);
101
102 797 bneuman
          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