Project

General

Profile

Revision 18db4dfa

ID18db4dface609e35bae5973a73ccccaaf36af292
Parent 679f4e26
Child d2acabf3

Added by AnsonLinux about 11 years ago

cliffSensor edited

View differences:

scout_avr/src/cliffSensor.cpp
8 8
#include "cliffSensor.h"
9 9
#include <avr/io.h>
10 10
#include <avr/interrupt.h>
11
#define _PINLEVEL(x) (PIND & (1<<x))
12 11
unsigned char flag_cliff0=0,flag_cliff1=0,flag_cliff2=0; // are these global variables???
13 12

  
14 13
void cliffSensor_init(void)
15 14
{
16 15
  sei();   //set the I-bit of SREG to 1, enabling global interrupters
17
	EIMSK |= 0b00000011;  //enable INT0,INT1,INT6
16
	EIMSK |= 0b01000011; //enable INT0,INT1,INT6
18 17
	EICRA |= 0b00001111; 
19
	EICRB |= 0b00110000;   //The rising edge of INTn triggers an interrupt request.
18
	EICRB |= 0b00110000; //The rising edge of INTn triggers an interrupt request.
19
  DDRD &= ~(0b00000011);
20
  DDRE &= ~(0b01000000); // set PD0, PD1 and PE6 as input pins.
20 21
}
21 22

  
22 23
bool read_cliffSensor_front(void)
23 24
{
24
	if(flag_cliff0 || _PINLEVEL(0)) //either a rising edge or a high logic level will be determined as cliff
25
	if(flag_cliff0 || (PIND & (1<<PD0))) //either a rising edge or a high logic level will be determined as cliff
25 26
	{
26 27
		flag_cliff0 = 0; // reset the flag
27 28
		EIMSK |= (1<<INT0); // re-enable the interrupt
......
32 33

  
33 34
bool read_cliffSensor_left(void)
34 35
{
35
	if(_PINLEVEL(1) || flag_cliff1)
36
	if(flag_cliff1 || (PIND & (1<<PD1)))
36 37
	{
37 38
		flag_cliff1 = 0;
38 39
		EIMSK |= (1<<INT1);
......
43 44

  
44 45
bool read_cliffSensor_right(void)
45 46
{
46
	if(_PINLEVEL(2) || flag_cliff2)
47
	if(flag_cliff2 || (PINE & (1<<PE6)))
47 48
	{
48 49
		flag_cliff2 = 0;
49 50
		EIMSK |= (1<<INT6); // enable INT6
scout_avr/src/cliffSensor.h
9 9
bool read_cliffSensor_left(void);
10 10
bool read_cliffSensor_right(void);
11 11

  
12
/* The returned result is in the form of left_front_right; For example, if both left
13
   and front sensors detect a cliff, the returned value is 0b110 */
12
/* The returned result is in the form of left_front_right; 
13
 * For example, if both left and front sensors detect a cliff, 
14
 * the returned value is 0b110 */
14 15
unsigned char read_cliffSensor_all(void);
15 16

  
16 17
#endif

Also available in: Unified diff