Revision 861
homing works and is added to library
branches/autonomous_recharging/code/projects/libbayboard/bayboard_lib.c | ||
---|---|---|
67 | 67 |
orb_init(); |
68 | 68 |
} |
69 | 69 |
|
70 |
if(config & IR) |
|
71 |
{ |
|
72 |
IR_init(); |
|
73 |
} |
|
74 |
|
|
70 | 75 |
sei(); |
71 | 76 |
// delay a bit for stability |
72 | 77 |
_delay_ms(1); |
branches/autonomous_recharging/code/projects/libbayboard/bayboard_lib.h | ||
---|---|---|
48 | 48 |
#define ORB 0x04 |
49 | 49 |
/** @brief Initialize I2C **/ |
50 | 50 |
#define I2C 0x20 |
51 |
/** @brief Initialize homing **/ |
|
52 |
#define IR 0x40 |
|
51 | 53 |
/** @brief Initialize everything **/ |
52 | 54 |
#define ALL_ON 0xFF |
53 | 55 |
|
... | ... | |
72 | 74 |
#include "reset.h" |
73 | 75 |
#include "orb.h" |
74 | 76 |
#include "time.h" |
77 |
#include "homing.h" |
|
75 | 78 |
|
76 | 79 |
#endif |
77 | 80 |
|
branches/autonomous_recharging/code/projects/libbayboard/homing.c | ||
---|---|---|
42 | 42 |
#include "serial.h" |
43 | 43 |
|
44 | 44 |
volatile int state = 0; |
45 |
volatile int on = 0; |
|
45 | 46 |
|
46 | 47 |
void IR_init(void){ |
47 | 48 |
|
... | ... | |
61 | 62 |
TCCR1A |= _BV(COM1B1)|_BV(COM1B0)|_BV(WGM11); |
62 | 63 |
TCCR1B |= _BV(WGM13)|_BV(WGM12)|_BV(CS10); |
63 | 64 |
ICR1 = 0x9C40; |
65 |
on = 0; |
|
64 | 66 |
|
65 |
|
|
66 | 67 |
} |
67 | 68 |
|
69 |
void IR_on(void){ |
|
70 |
on = 1; |
|
71 |
} |
|
72 |
|
|
73 |
void IR_off(void){ |
|
74 |
on = 0; |
|
75 |
} |
|
76 |
|
|
77 |
|
|
68 | 78 |
ISR(TIMER1_OVF_vect){ |
69 |
state = (state+1)%4; |
|
70 |
PORTA |= state; |
|
71 |
PORTC &= state + 0xFC; |
|
79 |
if(on){ |
|
80 |
if(state == 7) |
|
81 |
state = 0; |
|
82 |
else |
|
83 |
state++; |
|
84 |
|
|
72 | 85 |
|
86 |
if (state<4) |
|
87 |
PORTA ++; |
|
88 |
else |
|
89 |
PORTA &= 0xFC; |
|
90 |
} |
|
91 |
else{ |
|
92 |
PORTA &= 0xFC; |
|
93 |
} |
|
94 |
|
|
73 | 95 |
} |
branches/autonomous_recharging/code/projects/libbayboard/homing.h | ||
---|---|---|
33 | 33 |
**/ |
34 | 34 |
|
35 | 35 |
void IR_init(void); |
36 |
void IR_on(void); |
|
37 |
void IR_off(void); |
Also available in: Unified diff