"multiple declaration" error while building in atmel studio6(A

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1474 Views - Last Post: 10 March 2013 - 01:38 PM Rate Topic: -----

#1 pradnesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-March 13

"multiple declaration" error while building in atmel studio6(A

Posted 07 March 2013 - 08:57 AM

// Includes
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//Definitions
#define MAX_LENGTH_RX 			32
#define MAX_LENGTH_TX_PKT 		32 
#define MAX_LENGTH_TX_DATA 		16
#define synch_char 				0b10101010  //170
#define start_char 				0b11001010  //202
#define end_char 				0b11010100  //212

#define PORTLT	PORTD
#define PORTLR	PORTD
#define tx_l	0x80
#define rx_l	0x80

//declarations - general
volatile unsigned char txrx_i;

//declarations - RX
volatile unsigned char rx_, decoded_byte, rx_byte, rx_done, rx_length, buffer, rx_started, max_rx_length, rx_led;
volatile char rx_data[MAX_LENGTH_RX];

//declarations - TX
volatile unsigned char tx_data_length, tx_pkt_length, tx_id, tx_byte, tx_ing, tx_pkt_byte, tx_data_byte, tx_led;         
volatile char tx_data[MAX_LENGTH_TX_PKT];
volatile char in_data[MAX_LENGTH_TX_DATA];

//the encoding...
volatile char code[16] = {0b10001011,0b10001101,0b10010011,0b10010101,0b10010110,
0b10011001,0b10011010,0b10011100,0b10100011,0b10100101,0b10100110,0b10101001,
0b10101100,0b10110001,0b10110010,0b10110100};
 

/****************************************************************************************
 GENERAL FUNCTIONS ********************************************************************
****************************************************************************************/

//**********************************************************
// Used to initialize the baud rate and and the UART0 connection 
void txrx_init(int tx, int rx, int baud_num, char led) //00-none, 10-tx only, 01-rx only, 11-both
{
	tx_byte=MAX_LENGTH_TX_PKT;
	tx_ing=0;
    tx_led=led;
	rx_done=1;
    rx_led=led;

	UCSRB = ((rx<<7)|(tx<<5)|(rx<<4)|(tx<<3));
	UBRRH = baud_num;
 }

//**********************************************************
char decodeOne(char msbyte)
{
	txrx_i=0;
    buffer=start_char;

	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}
		
		txrx_i++;
    }
        
	return buffer;
}

//**********************************************************
char decode(char msbyte, char lsbyte)
{
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}

		txrx_i++;
	}
	
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(lsbyte==code[txrx_i]) 
		{
			buffer = (buffer<<4);
			buffer = buffer | txrx_i; 
		}

		txrx_i++;
	}

	return buffer;
}


/****************************************************************************************
RECEIVE SIDE FUNCTIONS ***************************************************************
****************************************************************************************/

//RX Complete ISR
ISR(USART0_RX_vect)+-
{
        if(rx_done==0)
        {
	        if (rx_byte==0)
        	{
        		rx_data[rx_byte]=UDR;
	        	
		        if(rx_data[0]==synch_char) 
				{	
					rx_started=1;
				}
        		else 
				{	
					rx_started=0;
				}
	        	                        
		        if((rx_data[0]==synch_char) && rx_started)
        		{
	        		rx_byte++;
                    if(rx_led == 1) 
					{
						PORTLR &= ~(rx_l);
					}
        		}				
	        }
        	else if (rx_byte == 1)
	        {
        		rx_data[rx_byte]=UDR;
	        	
				if(rx_data[0]==synch_char && rx_data[1]==start_char)
		        {
        			rx_byte++;
       	        }				
        	}             
	        else
        	{
	        	rx_data[rx_byte]=UDR;                
		        
				if (rx_byte == 4)
        		{
	        	        rx_length = decode(rx_data[3],rx_data[4]);			
		        }		
        		else if(rx_byte>=max_rx_length || rx_data[rx_byte]==212)
	        	{
		        	if(rx_led==1) 
					{
						PORTLR |= (rx_l);
					}

			        rx_done=1;
        		}

	        	rx_byte++;
        	}	
		
			
        } 
		
				 
}

//**********************************************************
// Resets the receiver to receive another packet
void rx_reset(char max_rx)
{
	rx_done=0;
	rx_started=0; 
	rx_length=0;
	rx_byte=0;
	max_rx_length=max_rx;
}

//**********************************************************
// Returns a 1 if the RF is done receiving a packet
char rxdone(void) 
{ 
	return rx_done; 
}

//**********************************************************
// Initializes the read index to 0
void init_getrx(void) 
{ 
	rx_ = 0; 
}
         
// Returns the next byte that was received over RF
char get_next_rx_data(void)
{
	return rx_data[rx_++];
}

// Returns a 1 if there are still empty bytes left in the RX buffer
char rx_empty(void) 
{ 
	return (rx_ < max_rx_length) ? 0 : 1; 
}


/****************************************************************************************
TRANSMIT SIDE FUNCTIONS **************************************************************
****************************************************************************************/

//UDR Empty ISR
ISR(USART0_UDRE_vect)
{      
	if(tx_byte< tx_pkt_length)
	{
		UDR=tx_data[tx_byte];
		tx_byte++;
        
		if(tx_led==1) 
		{	
			PORTLT &= ~(tx_l);
		}
	}				
	if(tx_byte==tx_pkt_length)
	{
        if(tx_led==1) 
		{	
			PORTLT |= (tx_l);
		}
        
		tx_ing=0;
	}
}  

//**********************************************************
// Encodes some of the bytes that need to be sent over RF during transmission
void encode(void)
{
    //sunchronization.
	tx_data[0] = synch_char; //calibration
	tx_data[1] = synch_char; //calibration
	tx_data[2] = synch_char; //synchronization
	tx_data[3] = synch_char; //synchronization

    //start character
	tx_data[4] = start_char; 

    //1-byte of ID
 	tx_data[5] = code[tx_id]; //Channel Id, static 0 for this unit

    //2-bytes of length
	tx_data[6] = code[tx_data_length>>4]; 	   //length of data to expect.
	tx_data[7] = code[(tx_data_length<<4)>>4]; //length of data to expect.

    //Payload
    tx_pkt_byte=8; 
	tx_data_byte=0; 
    
	while(tx_data_byte<tx_data_length)
    {
       	tx_data[tx_pkt_byte] = in_data[tx_data_byte];		
		tx_pkt_byte++;
	    tx_data_byte++;
    }

    //End character
	tx_data[tx_pkt_length-1] = end_char;
}             

//**********************************************************
// Function used to pass a data array from the main program that needs to be sent from transmitter over RF
void tx_me(char tx_data[], int length, int id)
{
        if(tx_ing==0)
        {
                txrx_i=0;
                
				while(txrx_i < length)
                {
                        in_data[txrx_i]=tx_data[txrx_i];
                        txrx_i++;
                }
                
				tx_id=id;
                tx_data_length=length;
                tx_pkt_length=length+9;
                
				encode();               
                
				tx_byte=0;
                tx_ing=1;
        }                
} 

//**********************************************************
// Returns a 1 if done transmitting
char txdone(void) 
{ 
	return tx_ing; 
}





errors



Line No.

Error 4 first defined here 1 1 uhvtransmitter

Error 3 multiple definition of `code' 1 1 uhvtransmitter

Error 1 multiple definition of `txrx_init' 48 1 uhvtransmitter

Error 2 multiple definition of 61 1 uhvtransmitter

Error 5 multiple definition of `decode' 80 1 uhvtransmitter

Error 6 multiple definition of `USART0_RX_vect' 115 1 uhvtransmitter

Error 7 multiple definition of `rx_reset' 180 1 uhvtransmitter

Error 8 multiple definition of `rxdone' 191 1 uhvtransmitter

Error 9 multiple definition of `init_getrx' 198 1 uhvtransmitter

Error 10 multiple definition of `get_next_rx_data' 204 1 uhvtransmitter

[quote name='pradnesh' date='07 March 2013 - 03:56 PM' timestamp='1362671761' post='1815792']
// Includes
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//Definitions
#define MAX_LENGTH_RX 			32
#define MAX_LENGTH_TX_PKT 		32 
#define MAX_LENGTH_TX_DATA 		16
#define synch_char 				0b10101010  //170
#define start_char 				0b11001010  //202
#define end_char 				0b11010100  //212

#define PORTLT	PORTD
#define PORTLR	PORTD
#define tx_l	0x80
#define rx_l	0x80

//declarations - general
volatile unsigned char txrx_i;

//declarations - RX
volatile unsigned char rx_, decoded_byte, rx_byte, rx_done, rx_length, buffer, rx_started, max_rx_length, rx_led;
volatile char rx_data[MAX_LENGTH_RX];

//declarations - TX
volatile unsigned char tx_data_length, tx_pkt_length, tx_id, tx_byte, tx_ing, tx_pkt_byte, tx_data_byte, tx_led;         
volatile char tx_data[MAX_LENGTH_TX_PKT];
volatile char in_data[MAX_LENGTH_TX_DATA];

//the encoding...
volatile char code[16] = {0b10001011,0b10001101,0b10010011,0b10010101,0b10010110,
0b10011001,0b10011010,0b10011100,0b10100011,0b10100101,0b10100110,0b10101001,
0b10101100,0b10110001,0b10110010,0b10110100};
 

/****************************************************************************************
 GENERAL FUNCTIONS ********************************************************************
****************************************************************************************/

//**********************************************************
// Used to initialize the baud rate and and the UART0 connection 
void txrx_init(int tx, int rx, int baud_num, char led) //00-none, 10-tx only, 01-rx only, 11-both
{
	tx_byte=MAX_LENGTH_TX_PKT;
	tx_ing=0;
    tx_led=led;
	rx_done=1;
    rx_led=led;

	UCSRB = ((rx<<7)|(tx<<5)|(rx<<4)|(tx<<3));
	UBRRH = baud_num;
 }

//**********************************************************
char decodeOne(char msbyte)
{
	txrx_i=0;
    buffer=start_char;

	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}
		
		txrx_i++;
    }
        
	return buffer;
}

//**********************************************************
char decode(char msbyte, char lsbyte)
{
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}

		txrx_i++;
	}
	
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(lsbyte==code[txrx_i]) 
		{
			buffer = (buffer<<4);
			buffer = buffer | txrx_i; 
		}

		txrx_i++;
	}

	return buffer;
}


/****************************************************************************************
RECEIVE SIDE FUNCTIONS ***************************************************************
****************************************************************************************/

//RX Complete ISR
ISR(USART0_RX_vect)+-
{
        if(rx_done==0)
        {
	        if (rx_byte==0)
        	{
        		rx_data[rx_byte]=UDR;
	        	
		        if(rx_data[0]==synch_char) 
				{	
					rx_started=1;
				}
        		else 
				{	
					rx_started=0;
				}
	        	                        
		        if((rx_data[0]==synch_char) && rx_started)
        		{
	        		rx_byte++;
                    if(rx_led == 1) 
					{
						PORTLR &= ~(rx_l);
					}
        		}				
	        }
        	else if (rx_byte == 1)
	        {
        		rx_data[rx_byte]=UDR;
	        	
				if(rx_data[0]==synch_char && rx_data[1]==start_char)
		        {
        			rx_byte++;
       	        }				
        	}             
	        else
        	{
	        	rx_data[rx_byte]=UDR;                
		        
				if (rx_byte == 4)
        		{
	        	        rx_length = decode(rx_data[3],rx_data[4]);			
		        }		
        		else if(rx_byte>=max_rx_length || rx_data[rx_byte]==212)
	        	{
		        	if(rx_led==1) 
					{
						PORTLR |= (rx_l);
					}

			        rx_done=1;
        		}

	        	rx_byte++;
        	}	
		
			
        } 
		
				 
}

//**********************************************************
// Resets the receiver to receive another packet
void rx_reset(char max_rx)
{
	rx_done=0;
	rx_started=0; 
	rx_length=0;
	rx_byte=0;
	max_rx_length=max_rx;
}

//**********************************************************
// Returns a 1 if the RF is done receiving a packet
char rxdone(void) 
{ 
	return rx_done; 
}

//**********************************************************
// Initializes the read index to 0
void init_getrx(void) 
{ 
	rx_ = 0; 
}
         
// Returns the next byte that was received over RF
char get_next_rx_data(void)
{
	return rx_data[rx_++];
}

// Returns a 1 if there are still empty bytes left in the RX buffer
char rx_empty(void) 
{ 
	return (rx_ < max_rx_length) ? 0 : 1; 
}


/****************************************************************************************
TRANSMIT SIDE FUNCTIONS **************************************************************
****************************************************************************************/

//UDR Empty ISR
ISR(USART0_UDRE_vect)
{      
	if(tx_byte< tx_pkt_length)
	{
		UDR=tx_data[tx_byte];
		tx_byte++;
        
		if(tx_led==1) 
		{	
			PORTLT &= ~(tx_l);
		}
	}				
	if(tx_byte==tx_pkt_length)
	{
        if(tx_led==1) 
		{	
			PORTLT |= (tx_l);
		}
        
		tx_ing=0;
	}
}  

//**********************************************************
// Encodes some of the bytes that need to be sent over RF during transmission
void encode(void)
{
    //sunchronization.
	tx_data[0] = synch_char; //calibration
	tx_data[1] = synch_char; //calibration
	tx_data[2] = synch_char; //synchronization
	tx_data[3] = synch_char; //synchronization

    //start character
	tx_data[4] = start_char; 

    //1-byte of ID
 	tx_data[5] = code[tx_id]; //Channel Id, static 0 for this unit

    //2-bytes of length
	tx_data[6] = code[tx_data_length>>4]; 	   //length of data to expect.
	tx_data[7] = code[(tx_data_length<<4)>>4]; //length of data to expect.

    //Payload
    tx_pkt_byte=8; 
	tx_data_byte=0; 
    
	while(tx_data_byte<tx_data_length)
    {
       	tx_data[tx_pkt_byte] = in_data[tx_data_byte];		
		tx_pkt_byte++;
	    tx_data_byte++;
    }

    //End character
	tx_data[tx_pkt_length-1] = end_char;
}             

//**********************************************************
// Function used to pass a data array from the main program that needs to be sent from transmitter over RF
void tx_me(char tx_data[], int length, int id)
{
        if(tx_ing==0)
        {
                txrx_i=0;
                
				while(txrx_i < length)
                {
                        in_data[txrx_i]=tx_data[txrx_i];
                        txrx_i++;
                }
                
				tx_id=id;
                tx_data_length=length;
                tx_pkt_length=length+9;
                
				encode();               
                
				tx_byte=0;
                tx_ing=1;
        }                
} 

//**********************************************************
// Returns a 1 if done transmitting
char txdone(void) 
{ 
	return tx_ing; 
}





errors



Line No.

Error 4 first defined here 1 1 uhvtransmitter

Error 3 multiple definition of `code' 1 1 uhvtransmitter

Error 1 multiple definition of `txrx_init' 48 1 uhvtransmitter

Error 2 multiple definition of 61 1 uhvtransmitter

Error 5 multiple definition of `decode' 80 1 uhvtransmitter

Error 6 multiple definition of `USART0_RX_vect' 115 1 uhvtransmitter

Error 7 multiple definition of `rx_reset' 180 1 uhvtransmitter

Error 8 multiple definition of `rxdone' 191 1 uhvtransmitter

Error 9 multiple definition of `init_getrx' 198 1 uhvtransmitter

Error 10 multiple definition of `get_next_rx_data' 204 1 uhvtransmitter

Is This A Good Question/Topic? 0
  • +

Replies To: "multiple declaration" error while building in atmel studio6(A

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4292
  • View blog
  • Posts: 13,458
  • Joined: 25-December 09

Re: "multiple declaration" error while building in atmel studio6(A

Posted 07 March 2013 - 09:04 AM

Your error messages should also be telling you the file name where the errors are detected, and possibly the function names as well.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 pradnesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-March 13

Re: "multiple declaration" error while building in atmel studio6(A

Posted 08 March 2013 - 08:53 AM

View Postjimblumberg, on 07 March 2013 - 04:04 PM, said:

Your error messages should also be telling you the file name where the errors are detected, and possibly the function names as well.

Jim


the code compiles without any error but shows following errors while building:


Error 3 multiple definition of `code' C:\Users\MALGUNKAR\Documents\Atmel Studio\uhvtransmitter\uhvtransmitter\Debug\uhvtransmitter.o 1 1 uhvtransmitter


Error 4 first defined here C:\Users\MALGUNKAR\Documents\Atmel Studio\uhvtransmitter\uhvtransmitter\Debug\txrx.o 1 1 uhvtransmitter


Error 1 multiple definition of `txrx_init' C:\Users\MALGUNKAR\Documents\Atmel Studio\uhvtransmitter\uhvtransmitter\Debug/../././txrx.c 48 1 uhvtransmitter

Error 2 multiple definition of `decodeOne' C:\Users\MALGUNKAR\Documents\Atmel Studio\uhvtransmitter\uhvtransmitter\Debug/../././txrx.c 61 1 uhvtransmitter


Error 5 multiple definition of `decode' C:\Users\MALGUNKAR\Documents\Atmel Studio\uhvtransmitter\uhvtransmitter\Debug/../././txrx.c 80 1 uhvtransmitter


Error 6 multiple definition of `USART0_RX_vect' C:\Users\MALGUNKAR\Documents\Atmel Studio\uhvtransmitter\uhvtransmitter\Debug/../././txrx.c 115 1 uhvtransmitter





and so on....What might be the issue?



And thanks for your help!!!!
Was This Post Helpful? 0
  • +
  • -

#4 pradnesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-March 13

Re: "multiple declaration" error while building in atmel studio6(A

Posted 08 March 2013 - 08:58 AM

The main code is given below in which i am using the previous code.The main code compiles without any error, but when I build the program, it shows "multiple definition" errors.






//************************************************************
// Headers Files and other includes
//************************************************************

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include <util/delay.h>
#include <stdlib.h>
#include <string.h>
#include ".\txrx.c"

//************************************************************
// Defines
//************************************************************

//Timeout values for different segments of the code
#define tinit	3000	// Initialization time for sensor
#define tm 		10		// Time	for setting up a 1 mS counter using the Timer0 100 microSec counter
#define tdemo	300		// Time for executing each stage of the demo sequence

#define tmotor 	25		// Time for controlling the stepper motor
#define tsen	50		// Time for reading the range provided by the sensor
#define tvib	50		// Time for controlling the vibrator motors
#define trf		150		// Time for transmitting RF

//**********************************

// Motor Port defines
#define DDRM	DDRC
#define PORTM	PORTC
#define PINM	PINC

// Ultrasonic Sensor Port defines
#define DDRU	DDRA
#define PORTU	PORTA
#define PINU	PINA
#define p_input	0x01

// Vibrator Motor Port defines
#define DDRV	DDRB
#define PORTV	PORTB
#define PINV	PINB

// RF / Led Port defines
#define DDRL	DDRD
#define PORTL	PORTD
#define PINL	PIND
#define cpu_l	0x04	// Led output for CPU board
#define cal_i	0x10    // Input for Calibration
#define cal_o	0x20    // Output for Calibration

//**********************************

// Demo Defines
#define demoC		0x01
#define demoN		10

// Motor Defines
#define step1	0x0A	// Step 1 representation of stepper motor
#define step2	0x09	// Step 2 representation of stepper motor
#define step3	0x05	// Step 3 representation of stepper motor
#define step4	0x06	// Step 4 representation of stepper motor
#define inh1	0x10	// Enable for Bridge 1 on L298, always set to high
#define inh2	0x20	// Enable for Bridge 2 on L298, always set to high
#define inh		0x30	// Both enables combined together, always set to high
#define numSteps 	36	// Number of steps to take in 1 rotation

// Sensor Defines
#define rangeChoice	1	// 0-Analog, 1-PWM

// RF defines
#define rftx_data_length	6			// Maximum length of the RF payload
#define baudrate			4800		// Bauadrate for sending control signals to RF transmitted chip
#define f_cpu 				16000000UL	// Crystal frequency of the MCU
#define tx_id		 		0x0A		// Transmission ID of the RF packet
#define ccw_id				0x21		// ID for indicating a counter clockwise range packet
#define cw_id				0x12		// ID for indicating a clockwise range packet

// Vibrator motor defines
#define vib1	0			// Range index for vibrator motor 1	angle = -135 degrees
#define vib2	3			// Range index for vibrator motor 2 angle = -90 degrees
#define vib3	6			// Range index for vibrator motor 3 angle = -45 degrees
#define vib4	9			// Range index for vibrator motor 4 angle = 0 degree
#define vib5	12			// Range index for vibrator motor 5 angle = 45 degrees
#define vib6	15			// Range index for vibrator motor 6 angle = 90 degrees
#define vib7	18			// Range index for vibrator motor 7 angle = 135 degrees
#define p5ft		9       // 0.5 feet, used as a reference for calculating other ranges

//************************************************************
// Variable Declarations
//************************************************************

// Timer Counters for different segments/ modules of the program
volatile unsigned int time_init, time_m, time_motor, time_sen, time_rf, time_vib, time_demo; 

// Demo Declarations
unsigned char demoControl;			// Controls whether the program is in demo mode. Program in demo mode during startup for 3 secs
unsigned char demoNum;				// Specifies the number of times demo function needs to be executed 

// Calibration declaration
unsigned char calibrate;			// Calibration Check variable. 2-During initialization, 1-Calibration, 0-Calibrated 

// Motor declarations
unsigned char ccw;					// Rotation Control = 0-CounterClockwise, 1-Clockwise
unsigned char rot;  				// Step Counter. Specifies the step, and thus the angle at which motor is

// RF declarations
char rftx_data[rftx_data_length];	// Data to send over RF
char rf_range[3];					// Last 3 range values that need to be transmitted over RF
unsigned char packet_count; 		// Number of packets sent
unsigned char rf_id;				// Direction dependent ID for the RF packet 
unsigned long baudval;				// baud rate for RF signal transmission from UART0

// Sensor declarations
int  range;							// Range to be used for calculation
char rangeType;						// 0-Analog, 1-PWM
int  a_range; 						// Analog Distance Input from range sensor
int  p_range; 						// PWM Distnace Input from range sensor
char p_valid;						// Check if PWM range is valid or not
int  sen_range[19];					// Storing the range at all the angles
unsigned int senIndex;				// Index for storing the range at a particular angle

// Vibrator Control declarations
int vib_pwm[7];						// PWM width for each of the vibrator motors. This sets the intensity of vibration of motor.
int vib_index[7];					// Contains the angle index for each of the vibrators
int vib_range[7];					// Contains the range values for each of the vibrators
unsigned char vibLed;				// Contains the state of each of the vibrator motors (on/off). Used to control LEDs at receiver
int range1, range2, range3, range4; // Threshold ranges for setting the vibration intensity

//************************************************************
// Function Declarations
//************************************************************

void initialize(void); 		// Initialization for the entire MCU
void demo(void);			// A demo procedure of the vibrators
void rangeCalc(void);  		// Find range based on type of input
void motorControl(void);  	// Executes at time specified by t1
void rfTransmit(void);		// Create RF packet and transmit RF data
void vibControl(void);		// Controls the vibrator motor based on particular angle
void filterRange(void);		// Filter the range appropriately so that range values at angles are represented well

//************************************************************
// Interrupt Service Routines
//************************************************************

//Timer 0 compare A ISR
ISR (TIMER0_COMPA_vect)
{
  time_m++;

  //Decrement the time if not already zero
  if(time_m == tm)
  {
  	  time_m = 0;
	    
	  if (time_demo>0)	--time_demo;
	  if (time_init>0)	--time_init;
	  if (time_motor>0)	--time_motor;
	  if (time_rf>0)	--time_rf;
	  if (time_sen>0)	--time_sen;
	  if (time_vib>0)	--time_vib;	  

	  // Switch on all the motors at the start of the cycle
	  PORTV = 0xFF;	  
  }
  
  // Turn off the PWM for the vibrator motors at appropriate times  
  // If 0, then motor is turned off almost instantaneously
  if(time_m == vib_pwm[0] )		PORTV &= ~(0x01);
  if(time_m == vib_pwm[1] )		PORTV &= ~(0x02);
  if(time_m == vib_pwm[2] )		PORTV &= ~(0x04);
  if(time_m == vib_pwm[3] )		PORTV &= ~(0x08);
  if(time_m == vib_pwm[4] )		PORTV &= ~(0x10);
  if(time_m == vib_pwm[5] )		PORTV &= ~(0x20);
  if(time_m == vib_pwm[6] )		PORTV &= ~(0x40);

  // Calibration input, check when this input goes high and calibrate the motor position
  if((~PINL) & cal_i)
  {  	
	if(calibrate == 1)
	{
		// Set initial values of the motor
		ccw = 1;
		rot = 36;
		senIndex = 18; 

		// Turn motor to next step so that motor does not make contact with the wire in every rotation
		switch(PORTM & 0x0F)
		{
			case step1: PORTM = (inh | step4); break;
			case step2: PORTM = (inh | step1); break;
			case step3: PORTM = (inh | step2); break;
			case step4: PORTM = (inh | step3); break;
			default: PORTM = (inh | step1);
		}

		// Calibration complete indication
		calibrate = 0; 				
	}		
  }

  // Check if the PWM input from Ultrasonic sensor is high and start counting 
  if(PINU & p_input)
  {
  	if(p_valid == 1)
	{
		p_valid = 0;
		p_range = 0;
	}

	p_range++;	
  }
  else
  {
  	p_valid = 1;
	range = p_range;							
  }

}

//************************************************************
// main() function
//************************************************************

int main(void)
{

  // Initialize entire MCU
  initialize();
  
  // Main task scheduler loop
  while(1)
  {
    if((time_demo == 0) && (demoControl == 1))
	{
		// Executing the demo code
		demo();	
		
		demoNum--;

		if(demoNum == 0)
		{
			demoControl = 0;
			time_demo = 0;
		}
		else
		{			
			time_demo = tdemo;
		}		
	}
	
	// If demo executed, execute all other parts of the program
	if((time_init==0) && (demoControl==0))	
	{
		if(calibrate == 2)
		{
			calibrate  = 1;
		}

		if (time_motor==0)
	    {
	    	time_motor = tmotor;
			motorControl();			
	    }

		if(calibrate == 0)
		{
			if (time_sen == 0)
			{
				time_sen = tsen;
				rangeCalc();
			}
		
			if (time_vib == 0)
			{
				time_vib = tvib;
				vibControl();
			}

			if(time_rf == 0)
			{
				time_rf = trf;
				rfTransmit();			
				PORTL ^= (cpu_l);	
			}
		}
	}		
  }
}


//************************************************************
// Local Functions
//************************************************************

// demo() - Initial Demo Function
void demo(void)
{
	// Demo sequence steps. Vibrator motors start vibrating from one end, 
	// vibration progresses to the other end and returns to the first motor
	switch(demoNum)
	{
		case 10: vib_pwm[1] = 8; break;
		case 9:  vib_pwm[1] = 0; vib_pwm[2] = 8; break;
		case 8:  vib_pwm[2] = 0; vib_pwm[3] = 8; break;
		case 7:  vib_pwm[3] = 0; vib_pwm[4] = 8; break;
		case 6:  vib_pwm[4] = 0; vib_pwm[5] = 8; break;
		case 5:  vib_pwm[4] = 8; vib_pwm[5] = 0; break;
		case 4:  vib_pwm[3] = 8; vib_pwm[4] = 0; break;
		case 3:  vib_pwm[2] = 8; vib_pwm[3] = 0; break;
		case 2:  vib_pwm[1] = 8; vib_pwm[2] = 0; break;
		case 1:  vib_pwm[1] = 0; break;
	}
}	

//**************************************************

// filterRange() - Filter the range value at particular angles and the surrounding range values to represent the best 
// approximate vibrator range
void filterRange(void)
{

	int i;

	vib_range[0] = sen_range[vib_index[0]];
	vib_range[6] = sen_range[vib_index[6]];
		
	for(i=1; i<6; i++)
	{	
		vib_range[i] = ((2 * sen_range[vib_index[i]]) + sen_range[vib_index[i]-1] + sen_range[vib_index[i]+1]);
	}

	vib_range[3] = sen_range[vib_index[3]] << 2;

}

//**************************************************

// rangeCalc() - Calculate the range from the sensor depending on type of range
void rangeCalc(void)
{
	
	if(rangeType == 0)
	{
		a_range = ((int)ADCH);	
	  	ADCSRA |= (1<<ADSC); 

		range = a_range;
	}
	else if((rangeType == 1) && (p_valid == 1))
	{		
		range = p_range;						
	}
	
	
	rf_range[0] = rf_range[1]; 	
	rf_range[1] = rf_range[2];
	rf_range[2] = range;

	sen_range[senIndex] = range;

	if(ccw == 0)
	{
		senIndex++;
	}
	else if(ccw == 1)
	{
		senIndex--;
	}
}

//**************************************************

// vibControl() - scheduled by tvib. Used to control the operation of vibrator motors at particular angles
void vibControl(void)
{
	int i;

	vibLed = 0x00;
	
	for(i = 0; i<7; i++)
	{

		filterRange();			

		if(vib_range[i] == 0)
		{
			vib_pwm[i] = 0;
		}
		else if(vib_range[i] <= range1)
		{
			vib_pwm[i] = 9;
		}
		else if((vib_range[i] > range1) && (vib_range[i] <= range2))
		{
			vib_pwm[i] = 7;			
		}
		else if((vib_range[i] > range2) && (vib_range[i] <= range3))
		{
			vib_pwm[i] = 5;			
		}
		else if((vib_range[i] > range3) && (vib_range[i] <= range4))
		{
			vib_pwm[i] = 4;			
		}
		else if(vib_range[i] > range4)
		{
			vib_pwm[i] = 0;			
		}

		if(vib_pwm[i] <= 4)
		{
			vibLed |= (1 << i);
		}

	}

	vibLed = vibLed >> 1;
}


//**************************************************

// motorControl() - scheduled by tmotor, Generates control signals for stepper motor and controls rotation
// and number of steps
void motorControl(void)
{	
	if(ccw == 0)
	{
		// Counter clockwise step sequence
		switch(PORTM & 0x0F)
		{
			case step1: PORTM = (inh | step2); break;
			case step2: PORTM = (inh | step3); break;
			case step3: PORTM = (inh | step4); break;
			case step4: PORTM = (inh | step1); break;
			default: PORTM = (inh | step1);
		}
	}
	else if (ccw == 1)
	{
		// Clockwise step sequence
		switch(PORTM & 0x0F)
		{
			case step1: PORTM = (inh | step4); break;
			case step2: PORTM = (inh | step1); break;
			case step3: PORTM = (inh | step2); break;
			case step4: PORTM = (inh | step3); break;
			default: PORTM = (inh | step1);
		}
	}
	
	if(calibrate == 0)
	{
		if(ccw == 0)
		{ 
			rot++;
			if(rot == numSteps) 
			{
				ccw = 1;				
			}
		}
		else if(ccw == 1)
		{
			rot--;
			if(rot == 0) 
			{
				ccw = 0;					
			}
	    }
	}
}

//**************************************************

// Form and transmit RF data packet
void rfTransmit (void)
{
	// Increment packet count
	packet_count++;

	// Set the RF id according to rotation
	if(ccw == 0)
	{
		rf_id = ccw_id;
	}
	else if (ccw == 1)
	{
		rf_id = cw_id;
	}
	
	// Construct data packet
	rftx_data[0] = vibLed;					
	rftx_data[1] = rf_id;
	rftx_data[2] = rot;
	rftx_data[3] = rf_range[0];
	rftx_data[4] = rf_range[1];
	rftx_data[5] = rf_range[2];

	// Transmit data packet
	tx_me(rftx_data, rftx_data_length, tx_id);
}


//************************************************************
// MCU Initialization Functions
//************************************************************

// Primary Initialization Function
void initialize(void)
{
  // Set the type of the current range input from the sensor
  rangeType = rangeChoice;

  //ADC initialization  
  //Initialize the ADC only if the choice is set to 0
  if(rangeType == 0)	
  {
	  //init the A to D converter, channel zero, left adj, EXTERNAL Aref!
	  ADMUX = (1<<ADLAR) ;  
	  //enable ADC and set prescaler to 1/128*16MHz=125,000, and clear interupt enable, and start a conversion
	  ADCSRA = ((1<<ADEN) | (1<<ADSC)) + 7; 
  }	

//******************************************

  //Timer Initialization
  //Set up timer 0 for 1 mSec timebase
  TIMSK= (1<<OCIE1A);							// turn on timer 0 cmp match ISR
  OCR1A = 24;  									// set the compare to 25 time ticks
  TCCR1B= 3; 									// set prescalar to divide by 64 //0b00000011;
  TCCR1A= (1<<WGM01) ;							// turn on clear-on-match
  
//******************************************

  //RF Initialization
  baudval = (f_cpu / (16UL * baudrate)) - 1; 
  txrx_init(1,0,(int)baudval, 0);				// Transmission initialization. Enable Transmit, Disable Receive, Set Baud Value

//******************************************

  //Port Initialization
  
  // Motor
  DDRM = 0xFF;					// Set all the stepper motor connections to outputs
  PORTM = (inh | step1);		// Set the initial step for the stepper motor

  // Ultrasonic Sensor
  DDRU &= ~(p_input);			// Set the sensor connection on port A as input

  // Vibrating Motor
  DDRV 	= 0xFF;					// Set all vibrator motor connections to outputs
  PORTV = 0x00;					// Turn off all vibrator motors initially

  // Leds
  DDRL  |= (cpu_l | cal_o);		// Set the CPU led and calibration output connections as outputs
  DDRL  &= ~(cal_i);			// Set the calibration input as input
  PORTL |= (cpu_l | cal_i);		// Turn off Led (active low) and pull up cal_i input
  PORTL &= ~(cal_o);			// Set cal_o output to 0

//******************************************

  // Variable Initialization

  // Initial Calibration
  calibrate = 2;
  
  // Timers
  time_init = tinit;
  time_m = 0;
  time_sen = 0;
  time_motor = 0;
  time_rf = 0;
  time_vib = 0;

  // Motors
  ccw = 0;
  rot = 0;
  
  // RF
  rf_id = ccw_id;
  packet_count = 0;

  // Ultrasonic Sensor
  senIndex = 0;
  range = 0;
  a_range = 0;
  p_range = 0;
  p_valid = 0;

  // Vibrator Motors
  vib_index[0] = vib1;
  vib_index[1] = vib2;
  vib_index[2] = vib3;
  vib_index[3] = vib4;
  vib_index[4] = vib5;
  vib_index[5] = vib6;
  vib_index[6] = vib7;

  vibLed = 0x00;

  range1 = (p5ft * 4) << 2;
  range2 = (p5ft * 6) << 2;
  range3 = (p5ft * 8) << 2;
  range4 = (p5ft * 10) << 2;

    // Demo
  demoControl = demoC;

  if(demoControl == 1)
  {
  	time_demo = tdemo;
	demoNum = demoN;
  }
  else
  {
  	time_demo = 0 ;
	demoNum = 0;
  }
  
//******************************************

//Start the ISRs
  sei();

}




Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is offline

  • member icon


Reputation: 4292
  • View blog
  • Posts: 13,458
  • Joined: 25-December 09

Re: "multiple declaration" error while building in atmel studio6(A

Posted 08 March 2013 - 10:45 AM

Please post the contents of txrx.c. And why are you including a .c source file?

Jim
Was This Post Helpful? 0
  • +
  • -

#6 pradnesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-March 13

Re: "multiple declaration" error while building in atmel studio6(A

Posted 10 March 2013 - 12:00 AM

View Postjimblumberg, on 08 March 2013 - 05:45 PM, said:

Please post the contents of txrx.c. And why are you including a .c source file?

Jim


// Includes
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//Definitions
#define MAX_LENGTH_RX 			32
#define MAX_LENGTH_TX_PKT 		32 
#define MAX_LENGTH_TX_DATA 		16
#define synch_char 				0b10101010  //170
#define start_char 				0b11001010  //202
#define end_char 				0b11010100  //212

#define PORTLT	PORTD
#define PORTLR	PORTD
#define tx_l	0x80
#define rx_l	0x80

//declarations - general
volatile unsigned char txrx_i;

//declarations - RX
volatile unsigned char rx_, decoded_byte, rx_byte, rx_done, rx_length, buffer, rx_started, max_rx_length, rx_led;
volatile char rx_data[MAX_LENGTH_RX];

//declarations - TX
volatile unsigned char tx_data_length, tx_pkt_length, tx_id, tx_byte, tx_ing, tx_pkt_byte, tx_data_byte, tx_led;         
volatile char tx_data[MAX_LENGTH_TX_PKT];
volatile char in_data[MAX_LENGTH_TX_DATA];

//the encoding...
volatile char code[16] = {0b10001011,0b10001101,0b10010011,0b10010101,0b10010110,
0b10011001,0b10011010,0b10011100,0b10100011,0b10100101,0b10100110,0b10101001,
0b10101100,0b10110001,0b10110010,0b10110100};
 

/****************************************************************************************
 GENERAL FUNCTIONS ********************************************************************
****************************************************************************************/

//**********************************************************
// Used to initialize the baud rate and and the UART0 connection 
void txrx_init(int tx, int rx, int baud_num, char led) //00-none, 10-tx only, 01-rx only, 11-both
{
	tx_byte=MAX_LENGTH_TX_PKT;
	tx_ing=0;
    tx_led=led;
	rx_done=1;
    rx_led=led;
           	UCSRB = ((rx<<7)|(tx<<5)|(rx<<4)|(tx<<3));

	UBRRL = baud_num;
 }

//**********************************************************
char decodeOne(char msbyte)
{
	txrx_i=0;
    buffer=start_char;

	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}
		
		txrx_i++;
    }
        
	return buffer;
}

//**********************************************************
char decode(char msbyte, char lsbyte)
{
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}

		txrx_i++;
	}
	
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(lsbyte==code[txrx_i]) 
		{
			buffer = (buffer<<4);
			buffer = buffer | txrx_i; 
		}

		txrx_i++;
	}

	return buffer;
}


/****************************************************************************************
RECEIVE SIDE FUNCTIONS ***************************************************************
****************************************************************************************/

//RX Complete ISR
ISR(USART0_RX_vect)
{
        if(rx_done==0)
        {
	        if (rx_byte==0)
        	{
        		rx_data[rx_byte]=UDR0;
	        	
		        if(rx_data[0]==synch_char) 
				{	
					rx_started=1;
				}
        		else 
				{	
					rx_started=0;
				}
	        	                        
		        if((rx_data[0]==synch_char) && rx_started)
        		{
	        		rx_byte++;
                    if(rx_led == 1) 
					{
						PORTLR &= ~(rx_l);
					}
        		}				
	        }
        	else if (rx_byte == 1)
	        {
        		rx_data[rx_byte]=UDR0;
	        	
				if(rx_data[0]==synch_char && rx_data[1]==start_char)
		        {
        			rx_byte++;
       	        }				
        	}             
	        else
        	{
	        	rx_data[rx_byte]=UDR0;                
		        
				if (rx_byte == 4)
        		{
	        	        rx_length = decode(rx_data[3],rx_data[4]);			
		        }		
        		else if(rx_byte>=max_rx_length || rx_data[rx_byte]==212)
	        	{
		        	if(rx_led==1) 
					{
						PORTLR |= (rx_l);
					}

			        rx_done=1;
        		}

	        	rx_byte++;
        	}	
		
			
        } 
		
				 
}

//**********************************************************
// Resets the receiver to receive another packet
void rx_reset(char max_rx)
{
	rx_done=0;
	rx_started=0; 
	rx_length=0;
	rx_byte=0;
	max_rx_length=max_rx;
}

//**********************************************************
// Returns a 1 if the RF is done receiving a packet
char rxdone(void) 
{ 
	return rx_done; 
}

//**********************************************************
// Initializes the read index to 0
void init_getrx(void) 
{ 
	rx_ = 0; 
}
         
// Returns the next byte that was received over RF
char get_next_rx_data(void)
{
	return rx_data[rx_++];
}

// Returns a 1 if there are still empty bytes left in the RX buffer
char rx_empty(void) 
{ 
	return (rx_ < max_rx_length) ? 0 : 1; 
}


/****************************************************************************************
TRANSMIT SIDE FUNCTIONS **************************************************************
****************************************************************************************/

//UDR Empty ISR
ISR(USART0_UDRE_vect)
{      
	if(tx_byte< tx_pkt_length)
	{
		UDR0=tx_data[tx_byte];
		tx_byte++;
        
		if(tx_led==1) 
		{	
			PORTLT &= ~(tx_l);
		}
	}				
	if(tx_byte==tx_pkt_length)
	{
        if(tx_led==1) 
		{	
			PORTLT |= (tx_l);
		}
        
		tx_ing=0;
	}
}  

//**********************************************************
// Encodes some of the bytes that need to be sent over RF during transmission
void encode(void)
{
    //sunchronization.
	tx_data[0] = synch_char; //calibration
	tx_data[1] = synch_char; //calibration
	tx_data[2] = synch_char; //synchronization
	tx_data[3] = synch_char; //synchronization

    //start character
	tx_data[4] = start_char; 

    //1-byte of ID
 	tx_data[5] = code[tx_id]; //Channel Id, static 0 for this unit

    //2-bytes of length
	tx_data[6] = code[tx_data_length>>4]; 	   //length of data to expect.
	tx_data[7] = code[(tx_data_length<<4)>>4]; //length of data to expect.

    //Payload
    tx_pkt_byte=8; 
	tx_data_byte=0; 
    
	while(tx_data_byte<tx_data_length)
    {
       	tx_data[tx_pkt_byte] = in_data[tx_data_byte];		
		tx_pkt_byte++;
	    tx_data_byte++;
    }

    //End character
	tx_data[tx_pkt_length-1] = end_char;
}             

//**********************************************************
// Function used to pass a data array from the main program that needs to be sent from transmitter over RF
void tx_me(char tx_data[], int length, int id)
{
        if(tx_ing==0)
        {
                txrx_i=0;
                
				while(txrx_i < length)
                {
                        in_data[txrx_i]=tx_data[txrx_i];
                        txrx_i++;
                }
                
				tx_id=id;
                tx_data_length=length;
                tx_pkt_length=length+9;
                
				encode();               
                
				tx_byte=0;
                tx_ing=1;
        }                
} 

//**********************************************************
// Returns a 1 if done transmitting
char txdone(void) 
{ 
	return tx_ing; 
}








This is a txrx.c file which i've include in my main code.

View Postpradnesh, on 10 March 2013 - 06:59 AM, said:

View Postjimblumberg, on 08 March 2013 - 05:45 PM, said:

Please post the contents of txrx.c. And why are you including a .c source file?

Jim


// Includes
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//Definitions
#define MAX_LENGTH_RX 			32
#define MAX_LENGTH_TX_PKT 		32 
#define MAX_LENGTH_TX_DATA 		16
#define synch_char 				0b10101010  //170
#define start_char 				0b11001010  //202
#define end_char 				0b11010100  //212

#define PORTLT	PORTD
#define PORTLR	PORTD
#define tx_l	0x80
#define rx_l	0x80

//declarations - general
volatile unsigned char txrx_i;

//declarations - RX
volatile unsigned char rx_, decoded_byte, rx_byte, rx_done, rx_length, buffer, rx_started, max_rx_length, rx_led;
volatile char rx_data[MAX_LENGTH_RX];

//declarations - TX
volatile unsigned char tx_data_length, tx_pkt_length, tx_id, tx_byte, tx_ing, tx_pkt_byte, tx_data_byte, tx_led;         
volatile char tx_data[MAX_LENGTH_TX_PKT];
volatile char in_data[MAX_LENGTH_TX_DATA];

//the encoding...
volatile char code[16] = {0b10001011,0b10001101,0b10010011,0b10010101,0b10010110,
0b10011001,0b10011010,0b10011100,0b10100011,0b10100101,0b10100110,0b10101001,
0b10101100,0b10110001,0b10110010,0b10110100};
 

/****************************************************************************************
 GENERAL FUNCTIONS ********************************************************************
****************************************************************************************/

//**********************************************************
// Used to initialize the baud rate and and the UART0 connection 
void txrx_init(int tx, int rx, int baud_num, char led) //00-none, 10-tx only, 01-rx only, 11-both
{
	tx_byte=MAX_LENGTH_TX_PKT;
	tx_ing=0;
    tx_led=led;
	rx_done=1;
    rx_led=led;
           	UCSRB = ((rx<<7)|(tx<<5)|(rx<<4)|(tx<<3));

	UBRRL = baud_num;
 }

//**********************************************************
char decodeOne(char msbyte)
{
	txrx_i=0;
    buffer=start_char;

	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}
		
		txrx_i++;
    }
        
	return buffer;
}

//**********************************************************
char decode(char msbyte, char lsbyte)
{
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}

		txrx_i++;
	}
	
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(lsbyte==code[txrx_i]) 
		{
			buffer = (buffer<<4);
			buffer = buffer | txrx_i; 
		}

		txrx_i++;
	}

	return buffer;
}


/****************************************************************************************
RECEIVE SIDE FUNCTIONS ***************************************************************
****************************************************************************************/

//RX Complete ISR
ISR(USART0_RX_vect)
{
        if(rx_done==0)
        {
	        if (rx_byte==0)
        	{
        		rx_data[rx_byte]=UDR0;
	        	
		        if(rx_data[0]==synch_char) 
				{	
					rx_started=1;
				}
        		else 
				{	
					rx_started=0;
				}
	        	                        
		        if((rx_data[0]==synch_char) && rx_started)
        		{
	        		rx_byte++;
                    if(rx_led == 1) 
					{
						PORTLR &= ~(rx_l);
					}
        		}				
	        }
        	else if (rx_byte == 1)
	        {
        		rx_data[rx_byte]=UDR0;
	        	
				if(rx_data[0]==synch_char && rx_data[1]==start_char)
		        {
        			rx_byte++;
       	        }				
        	}             
	        else
        	{
	        	rx_data[rx_byte]=UDR0;                
		        
				if (rx_byte == 4)
        		{
	        	        rx_length = decode(rx_data[3],rx_data[4]);			
		        }		
        		else if(rx_byte>=max_rx_length || rx_data[rx_byte]==212)
	        	{
		        	if(rx_led==1) 
					{
						PORTLR |= (rx_l);
					}

			        rx_done=1;
        		}

	        	rx_byte++;
        	}	
		
			
        } 
		
				 
}

//**********************************************************
// Resets the receiver to receive another packet
void rx_reset(char max_rx)
{
	rx_done=0;
	rx_started=0; 
	rx_length=0;
	rx_byte=0;
	max_rx_length=max_rx;
}

//**********************************************************
// Returns a 1 if the RF is done receiving a packet
char rxdone(void) 
{ 
	return rx_done; 
}

//**********************************************************
// Initializes the read index to 0
void init_getrx(void) 
{ 
	rx_ = 0; 
}
         
// Returns the next byte that was received over RF
char get_next_rx_data(void)
{
	return rx_data[rx_++];
}

// Returns a 1 if there are still empty bytes left in the RX buffer
char rx_empty(void) 
{ 
	return (rx_ < max_rx_length) ? 0 : 1; 
}


/****************************************************************************************
TRANSMIT SIDE FUNCTIONS **************************************************************
****************************************************************************************/

//UDR Empty ISR
ISR(USART0_UDRE_vect)
{      
	if(tx_byte< tx_pkt_length)
	{
		UDR0=tx_data[tx_byte];
		tx_byte++;
        
		if(tx_led==1) 
		{	
			PORTLT &= ~(tx_l);
		}
	}				
	if(tx_byte==tx_pkt_length)
	{
        if(tx_led==1) 
		{	
			PORTLT |= (tx_l);
		}
        
		tx_ing=0;
	}
}  

//**********************************************************
// Encodes some of the bytes that need to be sent over RF during transmission
void encode(void)
{
    //sunchronization.
	tx_data[0] = synch_char; //calibration
	tx_data[1] = synch_char; //calibration
	tx_data[2] = synch_char; //synchronization
	tx_data[3] = synch_char; //synchronization

    //start character
	tx_data[4] = start_char; 

    //1-byte of ID
 	tx_data[5] = code[tx_id]; //Channel Id, static 0 for this unit

    //2-bytes of length
	tx_data[6] = code[tx_data_length>>4]; 	   //length of data to expect.
	tx_data[7] = code[(tx_data_length<<4)>>4]; //length of data to expect.

    //Payload
    tx_pkt_byte=8; 
	tx_data_byte=0; 
    
	while(tx_data_byte<tx_data_length)
    {
       	tx_data[tx_pkt_byte] = in_data[tx_data_byte];		
		tx_pkt_byte++;
	    tx_data_byte++;
    }

    //End character
	tx_data[tx_pkt_length-1] = end_char;
}             

//**********************************************************
// Function used to pass a data array from the main program that needs to be sent from transmitter over RF
void tx_me(char tx_data[], int length, int id)
{
        if(tx_ing==0)
        {
                txrx_i=0;
                
				while(txrx_i < length)
                {
                        in_data[txrx_i]=tx_data[txrx_i];
                        txrx_i++;
                }
                
				tx_id=id;
                tx_data_length=length;
                tx_pkt_length=length+9;
                
				encode();               
                
				tx_byte=0;
                tx_ing=1;
        }                
} 

//**********************************************************
// Returns a 1 if done transmitting
char txdone(void) 
{ 
	return tx_ing; 
}








This is a txrx.c file which i've include in my main code. This file includes all the functions for the main file.

Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is offline

  • member icon


Reputation: 4292
  • View blog
  • Posts: 13,458
  • Joined: 25-December 09

Re: "multiple declaration" error while building in atmel studio6(A

Posted 10 March 2013 - 06:20 AM

You should not be "including" this file, you should be adding this file to your project.

Jim
Was This Post Helpful? 0
  • +
  • -

#8 pradnesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-March 13

Re: "multiple declaration" error while building in atmel studio6(A

Posted 10 March 2013 - 07:42 AM

View Postjimblumberg, on 10 March 2013 - 01:20 PM, said:

You should not be "including" this file, you should be adding this file to your project.

Jim


View Postpradnesh, on 10 March 2013 - 02:39 PM, said:

View Postjimblumberg, on 10 March 2013 - 01:20 PM, said:

You should not be "including" this file, you should be adding this file to your project.

Jim

Was This Post Helpful? 0
  • +
  • -

#9 pradnesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-March 13

Re: "multiple declaration" error while building in atmel studio6(A

Posted 10 March 2013 - 07:49 AM

/*
 * uhvtransmitter.c
 *
 * Created: 3/7/2013 8:21:07 PM
 *  Author: MALGUNKAR
 */ 



//************************************************************
// Headers Files and other includes
//************************************************************





#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>






//Definitions
#define MAX_LENGTH_RX 			32
#define MAX_LENGTH_TX_PKT 		32 
#define MAX_LENGTH_TX_DATA 		16
#define synch_char 				0b10101010  //170
#define start_char 				0b11001010  //202
#define end_char 				0b11010100  //212

#define PORTLT	PORTD
#define PORTLR	PORTD
#define tx_l	0x80
#define rx_l	0x80

//declarations - general
volatile unsigned char txrx_i;

//declarations - RX
volatile unsigned char rx_, decoded_byte, rx_byte, rx_done, rx_length, buffer, rx_started, max_rx_length, rx_led;
volatile char rx_data[MAX_LENGTH_RX];

//declarations - TX
volatile unsigned char tx_data_length, tx_pkt_length, tx_id, tx_byte, tx_ing, tx_pkt_byte, tx_data_byte, tx_led;         
volatile char tx_data[MAX_LENGTH_TX_PKT];
volatile char in_data[MAX_LENGTH_TX_DATA];

//the encoding...
volatile char code[16] = {0b10001011,0b10001101,0b10010011,0b10010101,0b10010110,
0b10011001,0b10011010,0b10011100,0b10100011,0b10100101,0b10100110,0b10101001,
0b10101100,0b10110001,0b10110010,0b10110100};







//************************************************************
// Defines
//************************************************************

//Timeout values for different segments of the code
#define tinit	3000	// Initialization time for sensor
#define tm 		10		// Time	for setting up a 1 mS counter using the Timer0 100 microSec counter
#define tdemo	300		// Time for executing each stage of the demo sequence

#define tmotor 	25		// Time for controlling the stepper motor
#define tsen	50		// Time for reading the range provided by the sensor
#define tvib	50		// Time for controlling the vibrator motors
#define trf		150		// Time for transmitting RF

//**********************************

// Motor Port defines
#define DDRM	DDRC
#define PORTM	PORTC
#define PINM	PINC

// Ultrasonic Sensor Port defines
#define DDRU	DDRA
#define PORTU	PORTA
#define PINU	PINA
#define p_input	0x01

// Vibrator Motor Port defines
#define DDRV	DDRB
#define PORTV	PORTB
#define PINV	PINB

// RF / Led Port defines
#define DDRL	DDRD
#define PORTL	PORTD
#define PINL	PIND
#define cpu_l	0x04	// Led output for CPU board
#define cal_i	0x10    // Input for Calibration
#define cal_o	0x20    // Output for Calibration

//**********************************

// Demo Defines
#define demoC		0x01
#define demoN		10

// Motor Defines
#define step1	0x0A	// Step 1 representation of stepper motor
#define step2	0x09	// Step 2 representation of stepper motor
#define step3	0x05	// Step 3 representation of stepper motor
#define step4	0x06	// Step 4 representation of stepper motor
#define inh1	0x10	// Enable for Bridge 1 on L298, always set to high
#define inh2	0x20	// Enable for Bridge 2 on L298, always set to high
#define inh		0x30	// Both enables combined together, always set to high
#define numSteps 	36	// Number of steps to take in 1 rotation

// Sensor Defines
#define rangeChoice	1	// 0-Analog, 1-PWM

// RF defines
#define rftx_data_length	6			// Maximum length of the RF payload
#define baudrate			4800		// Bauadrate for sending control signals to RF transmitted chip
#define f_cpu 				16000000UL	// Crystal frequency of the MCU
#define tx_id		 		0x0A		// Transmission ID of the RF packet
#define ccw_id				0x21		// ID for indicating a counter clockwise range packet
#define cw_id				0x12		// ID for indicating a clockwise range packet

// Vibrator motor defines
#define vib1	0			// Range index for vibrator motor 1	angle = -135 degrees
#define vib2	3			// Range index for vibrator motor 2 angle = -90 degrees
#define vib3	6			// Range index for vibrator motor 3 angle = -45 degrees
#define vib4	9			// Range index for vibrator motor 4 angle = 0 degree
#define vib5	12			// Range index for vibrator motor 5 angle = 45 degrees
#define vib6	15			// Range index for vibrator motor 6 angle = 90 degrees
#define vib7	18			// Range index for vibrator motor 7 angle = 135 degrees
#define p5ft		9       // 0.5 feet, used as a reference for calculating other ranges

//************************************************************
// Variable Declarations
//************************************************************

// Timer Counters for different segments/ modules of the program
volatile unsigned int time_init, time_m, time_motor, time_sen, time_rf, time_vib, time_demo;

// Demo Declarations
unsigned char demoControl;			// Controls whether the program is in demo mode. Program in demo mode during startup for 3 secs
unsigned char demoNum;				// Specifies the number of times demo function needs to be executed

// Calibration declaration
unsigned char calibrate;			// Calibration Check variable. 2-During initialization, 1-Calibration, 0-Calibrated

// Motor declarations
unsigned char ccw;					// Rotation Control = 0-CounterClockwise, 1-Clockwise
unsigned char rot;  				// Step Counter. Specifies the step, and thus the angle at which motor is

// RF declarations
char rftx_data[rftx_data_length];	// Data to send over RF
char rf_range[3];					// Last 3 range values that need to be transmitted over RF
unsigned char packet_count; 		// Number of packets sent
unsigned char rf_id;				// Direction dependent ID for the RF packet
unsigned long baudval;				// baud rate for RF signal transmission from UART0

// Sensor declarations
int  range;							// Range to be used for calculation
char rangeType;						// 0-Analog, 1-PWM
int  a_range; 						// Analog Distance Input from range sensor
int  p_range; 						// PWM Distnace Input from range sensor
char p_valid;						// Check if PWM range is valid or not
int  sen_range[19];					// Storing the range at all the angles
unsigned int senIndex;				// Index for storing the range at a particular angle

// Vibrator Control declarations
int vib_pwm[7];						// PWM width for each of the vibrator motors. This sets the intensity of vibration of motor.
int vib_index[7];					// Contains the angle index for each of the vibrators
int vib_range[7];					// Contains the range values for each of the vibrators
unsigned char vibLed;				// Contains the state of each of the vibrator motors (on/off). Used to control LEDs at receiver
int range1, range2, range3, range4; // Threshold ranges for setting the vibration intensity

//************************************************************
// Function Declarations
//************************************************************

void initialize(void); 		// Initialization for the entire MCU
void demo(void);			// A demo procedure of the vibrators
void rangeCalc(void);  		// Find range based on type of input
void motorControl(void);  	// Executes at time specified by t1
void rfTransmit(void);		// Create RF packet and transmit RF data
void vibControl(void);		// Controls the vibrator motor based on particular angle
void filterRange(void);		// Filter the range appropriately so that range values at angles are represented well




































 

/****************************************************************************************
 GENERAL FUNCTIONS ********************************************************************
****************************************************************************************/

//**********************************************************
// Used to initialize the baud rate and and the UART0 connection 
void txrx_init(int tx, int rx, int baud_num, char led) //00-none, 10-tx only, 01-rx only, 11-both
{
	tx_byte=MAX_LENGTH_TX_PKT;
	tx_ing=0;
    tx_led=led;
	rx_done=1;
    rx_led=led;

	UCSRB = ((rx<<7)|(tx<<5)|(rx<<4)|(tx<<3));
	UBRRL = baud_num;
 }

//**********************************************************
char decodeOne(char msbyte)
{
	txrx_i=0;
    buffer=start_char;

	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}
		
		txrx_i++;
    }
        
	return buffer;
}

//**********************************************************
char decode(char msbyte, char lsbyte)
{
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}

		txrx_i++;
	}
	
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(lsbyte==code[txrx_i]) 
		{
			buffer = (buffer<<4);
			buffer = buffer | txrx_i; 
		}

		txrx_i++;
	}

	return buffer;
}


/****************************************************************************************
RECEIVE SIDE FUNCTIONS ***************************************************************
****************************************************************************************/

//RX Complete ISR
ISR(USART0_RX_vect)
{
        if(rx_done==0)
        {
	        if (rx_byte==0)
        	{
        		rx_data[rx_byte]=UDR;
	        	
		        if(rx_data[0]==synch_char) 
				{	
					rx_started=1;
				}
        		else 
				{	
					rx_started=0;
				}
	        	                        
		        if((rx_data[0]==synch_char) && rx_started)
        		{
	        		rx_byte++;
                    if(rx_led == 1) 
					{
						PORTLR &= ~(rx_l);
					}
        		}				
	        }
        	else if (rx_byte == 1)
	        {
        		rx_data[rx_byte]=UDR;
	        	
				if(rx_data[0]==synch_char && rx_data[1]==start_char)
		        {
        			rx_byte++;
       	        }				
        	}             
	        else
        	{
	        	rx_data[rx_byte]=UDR;                
		        
				if (rx_byte == 4)
        		{
	        	        rx_length = decode(rx_data[3],rx_data[4]);			
		        }		
        		else if(rx_byte>=max_rx_length || rx_data[rx_byte]==212)
	        	{
		        	if(rx_led==1) 
					{
						PORTLR |= (rx_l);
					}

			        rx_done=1;
        		}

	        	rx_byte++;
        	}	
		
			
        } 
		
				 
}

//**********************************************************
// Resets the receiver to receive another packet
void rx_reset(char max_rx)
{
	rx_done=0;
	rx_started=0; 
	rx_length=0;
	rx_byte=0;
	max_rx_length=max_rx;
}

//**********************************************************
// Returns a 1 if the RF is done receiving a packet
char rxdone(void) 
{ 
	return rx_done; 
}

//**********************************************************
// Initializes the read index to 0
void init_getrx(void) 
{ 
	rx_ = 0; 
}
         
// Returns the next byte that was received over RF
char get_next_rx_data(void)
{
	return rx_data[rx_++];
}

// Returns a 1 if there are still empty bytes left in the RX buffer
char rx_empty(void) 
{ 
	return (rx_ < max_rx_length) ? 0 : 1; 
}


/****************************************************************************************
TRANSMIT SIDE FUNCTIONS **************************************************************
****************************************************************************************/

//UDR Empty ISR
ISR(USART0_UDRE_vect)
{      
	if(tx_byte< tx_pkt_length)
	{
		UDR=tx_data[tx_byte];
		tx_byte++;
        
		if(tx_led==1) 
		{	
			PORTLT &= ~(tx_l);
		}
	}				
	if(tx_byte==tx_pkt_length)
	{
        if(tx_led==1) 
		{	
			PORTLT |= (tx_l);
		}
        
		tx_ing=0;
	}
}  

//**********************************************************
// Encodes some of the bytes that need to be sent over RF during transmission
void encode(void)
{
    //sunchronization.
	tx_data[0] = synch_char; //calibration
	tx_data[1] = synch_char; //calibration
	tx_data[2] = synch_char; //synchronization
	tx_data[3] = synch_char; //synchronization

    //start character
	tx_data[4] = start_char; 

    //1-byte of ID
 	tx_data[5] = code[tx_id]; //Channel Id, static 0 for this unit

    //2-bytes of length
	tx_data[6] = code[tx_data_length>>4]; 	   //length of data to expect.
	tx_data[7] = code[(tx_data_length<<4)>>4]; //length of data to expect.

    //Payload
    tx_pkt_byte=8; 
	tx_data_byte=0; 
    
	while(tx_data_byte<tx_data_length)
    {
       	tx_data[tx_pkt_byte] = in_data[tx_data_byte];		
		tx_pkt_byte++;
	    tx_data_byte++;
    }

    //End character
	tx_data[tx_pkt_length-1] = end_char;
}             

//**********************************************************
// Function used to pass a data array from the main program that needs to be sent from transmitter over RF
void tx_me(char tx_data[], int length, int id)
{
        if(tx_ing==0)
        {
                txrx_i=0;
                
				while(txrx_i < length)
                {
                        in_data[txrx_i]=tx_data[txrx_i];
                        txrx_i++;
                }
                
				tx_id=id;
                tx_data_length=length;
                tx_pkt_length=length+9;
                
				encode();               
                
				tx_byte=0;
                tx_ing=1;
        }                
} 

//**********************************************************
// Returns a 1 if done transmitting
char txdone(void) 
{ 
	return tx_ing; 
}


//************************************************************
// Interrupt Service Routines
//************************************************************

//Timer 0 compare A ISR
ISR (TIMER0_COMPA_vect)
{
  time_m++;

  //Decrement the time if not already zero
  if(time_m == tm)
  {
  	  time_m = 0;
	    
	  if (time_demo>0)	--time_demo;
	  if (time_init>0)	--time_init;
	  if (time_motor>0)	--time_motor;
	  if (time_rf>0)	--time_rf;
	  if (time_sen>0)	--time_sen;
	  if (time_vib>0)	--time_vib;	  

	  // Switch on all the motors at the start of the cycle
	  PORTV = 0xFF;	  
  }
  
  // Turn off the PWM for the vibrator motors at appropriate times  
  // If 0, then motor is turned off almost instantaneously
  if(time_m == vib_pwm[0] )		PORTV &= ~(0x01);
  if(time_m == vib_pwm[1] )		PORTV &= ~(0x02);
  if(time_m == vib_pwm[2] )		PORTV &= ~(0x04);
  if(time_m == vib_pwm[3] )		PORTV &= ~(0x08);
  if(time_m == vib_pwm[4] )		PORTV &= ~(0x10);
  if(time_m == vib_pwm[5] )		PORTV &= ~(0x20);
  if(time_m == vib_pwm[6] )		PORTV &= ~(0x40);

  // Calibration input, check when this input goes high and calibrate the motor position
  if((~PINL) & cal_i)
  {  	
	if(calibrate == 1)
	{
		// Set initial values of the motor
		ccw = 1;
		rot = 36;
		senIndex = 18; 

		// Turn motor to next step so that motor does not make contact with the wire in every rotation
		switch(PORTM & 0x0F)
		{
			case step1: PORTM = (inh | step4); break;
			case step2: PORTM = (inh | step1); break;
			case step3: PORTM = (inh | step2); break;
			case step4: PORTM = (inh | step3); break;
			default: PORTM = (inh | step1);
		}

		// Calibration complete indication
		calibrate = 0; 				
	}		
  }

  // Check if the PWM input from Ultrasonic sensor is high and start counting 
  if(PINU & p_input)
  {
  	if(p_valid == 1)
	{
		p_valid = 0;
		p_range = 0;
	}

	p_range++;	
  }
  else
  {
  	p_valid = 1;
	range = p_range;							
  }

}

//************************************************************
// main() function
//************************************************************

int main(void)
{

  // Initialize entire MCU
  initialize();
  
  // Main task scheduler loop
  while(1)
  {
    if((time_demo == 0) && (demoControl == 1))
	{
		// Executing the demo code
		demo();	
		
		demoNum--;

		if(demoNum == 0)
		{
			demoControl = 0;
			time_demo = 0;
		}
		else
		{			
			time_demo = tdemo;
		}		
	}
	
	// If demo executed, execute all other parts of the program
	if((time_init==0) && (demoControl==0))	
	{
		if(calibrate == 2)
		{
			calibrate  = 1;
		}

		if (time_motor==0)
	    {
	    	time_motor = tmotor;
			motorControl();			
	    }

		if(calibrate == 0)
		{
			if (time_sen == 0)
			{
				time_sen = tsen;
				rangeCalc();
			}
		
			if (time_vib == 0)
			{
				time_vib = tvib;
				vibControl();
			}

			if(time_rf == 0)
			{
				time_rf = trf;
				rfTransmit();			
				PORTL ^= (cpu_l);	
			}
		}
	}		
  }
}


//************************************************************
// Local Functions
//************************************************************

// demo() - Initial Demo Function
void demo(void)
{
	// Demo sequence steps. Vibrator motors start vibrating from one end, 
	// vibration progresses to the other end and returns to the first motor
	switch(demoNum)
	{
		case 10: vib_pwm[1] = 8; break;
		case 9:  vib_pwm[1] = 0; vib_pwm[2] = 8; break;
		case 8:  vib_pwm[2] = 0; vib_pwm[3] = 8; break;
		case 7:  vib_pwm[3] = 0; vib_pwm[4] = 8; break;
		case 6:  vib_pwm[4] = 0; vib_pwm[5] = 8; break;
		case 5:  vib_pwm[4] = 8; vib_pwm[5] = 0; break;
		case 4:  vib_pwm[3] = 8; vib_pwm[4] = 0; break;
		case 3:  vib_pwm[2] = 8; vib_pwm[3] = 0; break;
		case 2:  vib_pwm[1] = 8; vib_pwm[2] = 0; break;
		case 1:  vib_pwm[1] = 0; break;
	}
}	

//**************************************************

// filterRange() - Filter the range value at particular angles and the surrounding range values to represent the best 
// approximate vibrator range
void filterRange(void)
{

	int i;

	vib_range[0] = sen_range[vib_index[0]];
	vib_range[6] = sen_range[vib_index[6]];
		
	for(i=1; i<6; i++)
	{	
		vib_range[i] = ((2 * sen_range[vib_index[i]]) + sen_range[vib_index[i]-1] + sen_range[vib_index[i]+1]);
	}

	vib_range[3] = sen_range[vib_index[3]] << 2;

}

//**************************************************

// rangeCalc() - Calculate the range from the sensor depending on type of range
void rangeCalc(void)
{
	
	if(rangeType == 0)
	{
		a_range = ((int)ADCH);	
	  	ADCSRA |= (1<<ADSC); 

		range = a_range;
	}
	else if((rangeType == 1) && (p_valid == 1))
	{		
		range = p_range;						
	}
	
	
	rf_range[0] = rf_range[1]; 	
	rf_range[1] = rf_range[2];
	rf_range[2] = range;

	sen_range[senIndex] = range;

	if(ccw == 0)
	{
		senIndex++;
	}
	else if(ccw == 1)
	{
		senIndex--;
	}
}

//**************************************************

// vibControl() - scheduled by tvib. Used to control the operation of vibrator motors at particular angles
void vibControl(void)
{
	int i;

	vibLed = 0x00;
	
	for(i = 0; i<7; i++)
	{

		filterRange();			

		if(vib_range[i] == 0)
		{
			vib_pwm[i] = 0;
		}
		else if(vib_range[i] <= range1)
		{
			vib_pwm[i] = 9;
		}
		else if((vib_range[i] > range1) && (vib_range[i] <= range2))
		{
			vib_pwm[i] = 7;			
		}
		else if((vib_range[i] > range2) && (vib_range[i] <= range3))
		{
			vib_pwm[i] = 5;			
		}
		else if((vib_range[i] > range3) && (vib_range[i] <= range4))
		{
			vib_pwm[i] = 4;			
		}
		else if(vib_range[i] > range4)
		{
			vib_pwm[i] = 0;			
		}

		if(vib_pwm[i] <= 4)
		{
			vibLed |= (1 << i);
		}

	}

	vibLed = vibLed >> 1;
}


//**************************************************

// motorControl() - scheduled by tmotor, Generates control signals for stepper motor and controls rotation
// and number of steps
void motorControl(void)
{	
	if(ccw == 0)
	{
		// Counter clockwise step sequence
		switch(PORTM & 0x0F)
		{
			case step1: PORTM = (inh | step2); break;
			case step2: PORTM = (inh | step3); break;
			case step3: PORTM = (inh | step4); break;
			case step4: PORTM = (inh | step1); break;
			default: PORTM = (inh | step1);
		}
	}
	else if (ccw == 1)
	{
		// Clockwise step sequence
		switch(PORTM & 0x0F)
		{
			case step1: PORTM = (inh | step4); break;
			case step2: PORTM = (inh | step1); break;
			case step3: PORTM = (inh | step2); break;
			case step4: PORTM = (inh | step3); break;
			default: PORTM = (inh | step1);
		}
	}
	
	if(calibrate == 0)
	{
		if(ccw == 0)
		{ 
			rot++;
			if(rot == numSteps) 
			{
				ccw = 1;				
			}
		}
		else if(ccw == 1)
		{
			rot--;
			if(rot == 0) 
			{
				ccw = 0;					
			}
	    }
	}
}

//**************************************************

// Form and transmit RF data packet
void rfTransmit (void)
{
	// Increment packet count
	packet_count++;

	// Set the RF id according to rotation
	if(ccw == 0)
	{
		rf_id = ccw_id;
	}
	else if (ccw == 1)
	{
		rf_id = cw_id;
	}
	
	// Construct data packet
	rftx_data[0] = vibLed;					
	rftx_data[1] = rf_id;
	rftx_data[2] = rot;
	rftx_data[3] = rf_range[0];
	rftx_data[4] = rf_range[1];
	rftx_data[5] = rf_range[2];

	// Transmit data packet
	tx_me(rftx_data, rftx_data_length, tx_id);
}


//************************************************************
// MCU Initialization Functions
//************************************************************

// Primary Initialization Function
void initialize(void)
{
  // Set the type of the current range input from the sensor
  rangeType = rangeChoice;

  //ADC initialization  
  //Initialize the ADC only if the choice is set to 0
  if(rangeType == 0)	
  {
	  //init the A to D converter, channel zero, left adj, EXTERNAL Aref!
	  ADMUX = (1<<ADLAR) ;  
	  //enable ADC and set prescaler to 1/128*16MHz=125,000, and clear interupt enable, and start a conversion
	  ADCSRA = ((1<<ADEN) | (1<<ADSC)) + 7; 
  }	

//******************************************

  //Timer Initialization
  //Set up timer 0 for 1 mSec timebase
  TIMSK= (1<<OCIE1A);							// turn on timer 0 cmp match ISR
  OCR1A = 24;  									// set the compare to 25 time ticks
  TCCR1B= 3; 									// set prescalar to divide by 64 //0b00000011;
  TCCR1A= (1<<WGM01) ;							// turn on clear-on-match
  
//******************************************

  //RF Initialization
  baudval = (f_cpu / (16UL * baudrate)) - 1; 
  txrx_init(1,0,(int)baudval, 0);				// Transmission initialization. Enable Transmit, Disable Receive, Set Baud Value

//******************************************

  //Port Initialization
  
  // Motor
  DDRM = 0xFF;					// Set all the stepper motor connections to outputs
  PORTM = (inh | step1);		// Set the initial step for the stepper motor

  // Ultrasonic Sensor
  DDRU &= ~(p_input);			// Set the sensor connection on port A as input

  // Vibrating Motor
  DDRV 	= 0xFF;					// Set all vibrator motor connections to outputs
  PORTV = 0x00;					// Turn off all vibrator motors initially

  // Leds
  DDRL  |= (cpu_l | cal_o);		// Set the CPU led and calibration output connections as outputs
  DDRL  &= ~(cal_i);			// Set the calibration input as input
  PORTL |= (cpu_l | cal_i);		// Turn off Led (active low) and pull up cal_i input
  PORTL &= ~(cal_o);			// Set cal_o output to 0

//******************************************

  // Variable Initialization

  // Initial Calibration
  calibrate = 2;
  
  // Timers
  time_init = tinit;
  time_m = 0;
  time_sen = 0;
  time_motor = 0;
  time_rf = 0;
  time_vib = 0;

  // Motors
  ccw = 0;
  rot = 0;
  
  // RF
  rf_id = ccw_id;
  packet_count = 0;

  // Ultrasonic Sensor
  senIndex = 0;
  range = 0;
  a_range = 0;
  p_range = 0;
  p_valid = 0;

  // Vibrator Motors
  vib_index[0] = vib1;
  vib_index[1] = vib2;
  vib_index[2] = vib3;
  vib_index[3] = vib4;
  vib_index[4] = vib5;
  vib_index[5] = vib6;
  vib_index[6] = vib7;

  vibLed = 0x00;

  range1 = (p5ft * 4) << 2;
  range2 = (p5ft * 6) << 2;
  range3 = (p5ft * 8) << 2;
  range4 = (p5ft * 10) << 2;

    // Demo
  demoControl = demoC;

  if(demoControl == 1)
  {
  	time_demo = tdemo;
	demoNum = demoN;
  }
  else
  {
  	time_demo = 0 ;
	demoNum = 0;
  }
  
//******************************************

//Start the ISRs
  sei();

}







This is what I have done.I have placed the entire txrx.c file into the main code.Also I have declared all the variables and functions at the beginning.All the "multiple definition" errors got removed ,but now i'm getting a new error.The error is:


Error :lvalue required as left operand of assignment C:\Users\MALGUNKAR\Documents\Atmel Studio\uhvtransmitter\uhvtransmitter\uhvtransmitter.c line:496 column:10 uhvtransmitter
Was This Post Helpful? 0
  • +
  • -

#10 pradnesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-March 13

Re: "multiple declaration" error while building in atmel studio6(A

Posted 10 March 2013 - 07:55 AM

View Postpradnesh, on 10 March 2013 - 02:49 PM, said:

/*
 * uhvtransmitter.c
 *
 * Created: 3/7/2013 8:21:07 PM
 *  Author: MALGUNKAR
 */ 



//************************************************************
// Headers Files and other includes
//************************************************************





#include <util/delay.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>






//Definitions
#define MAX_LENGTH_RX 			32
#define MAX_LENGTH_TX_PKT 		32 
#define MAX_LENGTH_TX_DATA 		16
#define synch_char 				0b10101010  //170
#define start_char 				0b11001010  //202
#define end_char 				0b11010100  //212

#define PORTLT	PORTD
#define PORTLR	PORTD
#define tx_l	0x80
#define rx_l	0x80

//declarations - general
volatile unsigned char txrx_i;

//declarations - RX
volatile unsigned char rx_, decoded_byte, rx_byte, rx_done, rx_length, buffer, rx_started, max_rx_length, rx_led;
volatile char rx_data[MAX_LENGTH_RX];

//declarations - TX
volatile unsigned char tx_data_length, tx_pkt_length, tx_id, tx_byte, tx_ing, tx_pkt_byte, tx_data_byte, tx_led;         
volatile char tx_data[MAX_LENGTH_TX_PKT];
volatile char in_data[MAX_LENGTH_TX_DATA];

//the encoding...
volatile char code[16] = {0b10001011,0b10001101,0b10010011,0b10010101,0b10010110,
0b10011001,0b10011010,0b10011100,0b10100011,0b10100101,0b10100110,0b10101001,
0b10101100,0b10110001,0b10110010,0b10110100};







//************************************************************
// Defines
//************************************************************

//Timeout values for different segments of the code
#define tinit	3000	// Initialization time for sensor
#define tm 		10		// Time	for setting up a 1 mS counter using the Timer0 100 microSec counter
#define tdemo	300		// Time for executing each stage of the demo sequence

#define tmotor 	25		// Time for controlling the stepper motor
#define tsen	50		// Time for reading the range provided by the sensor
#define tvib	50		// Time for controlling the vibrator motors
#define trf		150		// Time for transmitting RF

//**********************************

// Motor Port defines
#define DDRM	DDRC
#define PORTM	PORTC
#define PINM	PINC

// Ultrasonic Sensor Port defines
#define DDRU	DDRA
#define PORTU	PORTA
#define PINU	PINA
#define p_input	0x01

// Vibrator Motor Port defines
#define DDRV	DDRB
#define PORTV	PORTB
#define PINV	PINB

// RF / Led Port defines
#define DDRL	DDRD
#define PORTL	PORTD
#define PINL	PIND
#define cpu_l	0x04	// Led output for CPU board
#define cal_i	0x10    // Input for Calibration
#define cal_o	0x20    // Output for Calibration

//**********************************

// Demo Defines
#define demoC		0x01
#define demoN		10

// Motor Defines
#define step1	0x0A	// Step 1 representation of stepper motor
#define step2	0x09	// Step 2 representation of stepper motor
#define step3	0x05	// Step 3 representation of stepper motor
#define step4	0x06	// Step 4 representation of stepper motor
#define inh1	0x10	// Enable for Bridge 1 on L298, always set to high
#define inh2	0x20	// Enable for Bridge 2 on L298, always set to high
#define inh		0x30	// Both enables combined together, always set to high
#define numSteps 	36	// Number of steps to take in 1 rotation

// Sensor Defines
#define rangeChoice	1	// 0-Analog, 1-PWM

// RF defines
#define rftx_data_length	6			// Maximum length of the RF payload
#define baudrate			4800		// Bauadrate for sending control signals to RF transmitted chip
#define f_cpu 				16000000UL	// Crystal frequency of the MCU
#define tx_id		 		0x0A		// Transmission ID of the RF packet
#define ccw_id				0x21		// ID for indicating a counter clockwise range packet
#define cw_id				0x12		// ID for indicating a clockwise range packet

// Vibrator motor defines
#define vib1	0			// Range index for vibrator motor 1	angle = -135 degrees
#define vib2	3			// Range index for vibrator motor 2 angle = -90 degrees
#define vib3	6			// Range index for vibrator motor 3 angle = -45 degrees
#define vib4	9			// Range index for vibrator motor 4 angle = 0 degree
#define vib5	12			// Range index for vibrator motor 5 angle = 45 degrees
#define vib6	15			// Range index for vibrator motor 6 angle = 90 degrees
#define vib7	18			// Range index for vibrator motor 7 angle = 135 degrees
#define p5ft		9       // 0.5 feet, used as a reference for calculating other ranges

//************************************************************
// Variable Declarations
//************************************************************

// Timer Counters for different segments/ modules of the program
volatile unsigned int time_init, time_m, time_motor, time_sen, time_rf, time_vib, time_demo;

// Demo Declarations
unsigned char demoControl;			// Controls whether the program is in demo mode. Program in demo mode during startup for 3 secs
unsigned char demoNum;				// Specifies the number of times demo function needs to be executed

// Calibration declaration
unsigned char calibrate;			// Calibration Check variable. 2-During initialization, 1-Calibration, 0-Calibrated

// Motor declarations
unsigned char ccw;					// Rotation Control = 0-CounterClockwise, 1-Clockwise
unsigned char rot;  				// Step Counter. Specifies the step, and thus the angle at which motor is

// RF declarations
char rftx_data[rftx_data_length];	// Data to send over RF
char rf_range[3];					// Last 3 range values that need to be transmitted over RF
unsigned char packet_count; 		// Number of packets sent
unsigned char rf_id;				// Direction dependent ID for the RF packet
unsigned long baudval;				// baud rate for RF signal transmission from UART0

// Sensor declarations
int  range;							// Range to be used for calculation
char rangeType;						// 0-Analog, 1-PWM
int  a_range; 						// Analog Distance Input from range sensor
int  p_range; 						// PWM Distnace Input from range sensor
char p_valid;						// Check if PWM range is valid or not
int  sen_range[19];					// Storing the range at all the angles
unsigned int senIndex;				// Index for storing the range at a particular angle

// Vibrator Control declarations
int vib_pwm[7];						// PWM width for each of the vibrator motors. This sets the intensity of vibration of motor.
int vib_index[7];					// Contains the angle index for each of the vibrators
int vib_range[7];					// Contains the range values for each of the vibrators
unsigned char vibLed;				// Contains the state of each of the vibrator motors (on/off). Used to control LEDs at receiver
int range1, range2, range3, range4; // Threshold ranges for setting the vibration intensity

//************************************************************
// Function Declarations
//************************************************************

void initialize(void); 		// Initialization for the entire MCU
void demo(void);			// A demo procedure of the vibrators
void rangeCalc(void);  		// Find range based on type of input
void motorControl(void);  	// Executes at time specified by t1
void rfTransmit(void);		// Create RF packet and transmit RF data
void vibControl(void);		// Controls the vibrator motor based on particular angle
void filterRange(void);		// Filter the range appropriately so that range values at angles are represented well




































 

/****************************************************************************************
 GENERAL FUNCTIONS ********************************************************************
****************************************************************************************/

//**********************************************************
// Used to initialize the baud rate and and the UART0 connection 
void txrx_init(int tx, int rx, int baud_num, char led) //00-none, 10-tx only, 01-rx only, 11-both
{
	tx_byte=MAX_LENGTH_TX_PKT;
	tx_ing=0;
    tx_led=led;
	rx_done=1;
    rx_led=led;

	UCSRB = ((rx<<7)|(tx<<5)|(rx<<4)|(tx<<3));
	UBRRL = baud_num;
 }

//**********************************************************
char decodeOne(char msbyte)
{
	txrx_i=0;
    buffer=start_char;

	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}
		
		txrx_i++;
    }
        
	return buffer;
}

//**********************************************************
char decode(char msbyte, char lsbyte)
{
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(msbyte==code[txrx_i])
		{	
			buffer=txrx_i;
		}

		txrx_i++;
	}
	
	txrx_i=0;
	
	while(txrx_i<16) 
	{
		if(lsbyte==code[txrx_i]) 
		{
			buffer = (buffer<<4);
			buffer = buffer | txrx_i; 
		}

		txrx_i++;
	}

	return buffer;
}


/****************************************************************************************
RECEIVE SIDE FUNCTIONS ***************************************************************
****************************************************************************************/

//RX Complete ISR
ISR(USART0_RX_vect)
{
        if(rx_done==0)
        {
	        if (rx_byte==0)
        	{
        		rx_data[rx_byte]=UDR;
	        	
		        if(rx_data[0]==synch_char) 
				{	
					rx_started=1;
				}
        		else 
				{	
					rx_started=0;
				}
	        	                        
		        if((rx_data[0]==synch_char) && rx_started)
        		{
	        		rx_byte++;
                    if(rx_led == 1) 
					{
						PORTLR &= ~(rx_l);
					}
        		}				
	        }
        	else if (rx_byte == 1)
	        {
        		rx_data[rx_byte]=UDR;
	        	
				if(rx_data[0]==synch_char && rx_data[1]==start_char)
		        {
        			rx_byte++;
       	        }				
        	}             
	        else
        	{
	        	rx_data[rx_byte]=UDR;                
		        
				if (rx_byte == 4)
        		{
	        	        rx_length = decode(rx_data[3],rx_data[4]);			
		        }		
        		else if(rx_byte>=max_rx_length || rx_data[rx_byte]==212)
	        	{
		        	if(rx_led==1) 
					{
						PORTLR |= (rx_l);
					}

			        rx_done=1;
        		}

	        	rx_byte++;
        	}	
		
			
        } 
		
				 
}

//**********************************************************
// Resets the receiver to receive another packet
void rx_reset(char max_rx)
{
	rx_done=0;
	rx_started=0; 
	rx_length=0;
	rx_byte=0;
	max_rx_length=max_rx;
}

//**********************************************************
// Returns a 1 if the RF is done receiving a packet
char rxdone(void) 
{ 
	return rx_done; 
}

//**********************************************************
// Initializes the read index to 0
void init_getrx(void) 
{ 
	rx_ = 0; 
}
         
// Returns the next byte that was received over RF
char get_next_rx_data(void)
{
	return rx_data[rx_++];
}

// Returns a 1 if there are still empty bytes left in the RX buffer
char rx_empty(void) 
{ 
	return (rx_ < max_rx_length) ? 0 : 1; 
}


/****************************************************************************************
TRANSMIT SIDE FUNCTIONS **************************************************************
****************************************************************************************/

//UDR Empty ISR
ISR(USART0_UDRE_vect)
{      
	if(tx_byte< tx_pkt_length)
	{
		UDR=tx_data[tx_byte];
		tx_byte++;
        
		if(tx_led==1) 
		{	
			PORTLT &= ~(tx_l);
		}
	}				
	if(tx_byte==tx_pkt_length)
	{
        if(tx_led==1) 
		{	
			PORTLT |= (tx_l);
		}
        
		tx_ing=0;
	}
}  

//**********************************************************
// Encodes some of the bytes that need to be sent over RF during transmission
void encode(void)
{
    //sunchronization.
	tx_data[0] = synch_char; //calibration
	tx_data[1] = synch_char; //calibration
	tx_data[2] = synch_char; //synchronization
	tx_data[3] = synch_char; //synchronization

    //start character
	tx_data[4] = start_char; 

    //1-byte of ID
 	tx_data[5] = code[tx_id]; //Channel Id, static 0 for this unit

    //2-bytes of length
	tx_data[6] = code[tx_data_length>>4]; 	   //length of data to expect.
	tx_data[7] = code[(tx_data_length<<4)>>4]; //length of data to expect.

    //Payload
    tx_pkt_byte=8; 
	tx_data_byte=0; 
    
	while(tx_data_byte<tx_data_length)
    {
       	tx_data[tx_pkt_byte] = in_data[tx_data_byte];		
		tx_pkt_byte++;
	    tx_data_byte++;
    }

    //End character
	tx_data[tx_pkt_length-1] = end_char;
}             

//**********************************************************
// Function used to pass a data array from the main program that needs to be sent from transmitter over RF
void tx_me(char tx_data[], int length, int id)
{
        if(tx_ing==0)
        {
                txrx_i=0;
                
				while(txrx_i < length)
                {
                        in_data[txrx_i]=tx_data[txrx_i];
                        txrx_i++;
                }
                
				tx_id=id;
                tx_data_length=length;
                tx_pkt_length=length+9;
                
				encode();               
                
				tx_byte=0;
                tx_ing=1;
        }                
} 

//**********************************************************
// Returns a 1 if done transmitting
char txdone(void) 
{ 
	return tx_ing; 
}


//************************************************************
// Interrupt Service Routines
//************************************************************

//Timer 0 compare A ISR
ISR (TIMER0_COMPA_vect)
{
  time_m++;

  //Decrement the time if not already zero
  if(time_m == tm)
  {
  	  time_m = 0;
	    
	  if (time_demo>0)	--time_demo;
	  if (time_init>0)	--time_init;
	  if (time_motor>0)	--time_motor;
	  if (time_rf>0)	--time_rf;
	  if (time_sen>0)	--time_sen;
	  if (time_vib>0)	--time_vib;	  

	  // Switch on all the motors at the start of the cycle
	  PORTV = 0xFF;	  
  }
  
  // Turn off the PWM for the vibrator motors at appropriate times  
  // If 0, then motor is turned off almost instantaneously
  if(time_m == vib_pwm[0] )		PORTV &= ~(0x01);
  if(time_m == vib_pwm[1] )		PORTV &= ~(0x02);
  if(time_m == vib_pwm[2] )		PORTV &= ~(0x04);
  if(time_m == vib_pwm[3] )		PORTV &= ~(0x08);
  if(time_m == vib_pwm[4] )		PORTV &= ~(0x10);
  if(time_m == vib_pwm[5] )		PORTV &= ~(0x20);
  if(time_m == vib_pwm[6] )		PORTV &= ~(0x40);

  // Calibration input, check when this input goes high and calibrate the motor position
  if((~PINL) & cal_i)
  {  	
	if(calibrate == 1)
	{
		// Set initial values of the motor
		ccw = 1;
		rot = 36;
		senIndex = 18; 

		// Turn motor to next step so that motor does not make contact with the wire in every rotation
		switch(PORTM & 0x0F)
		{
			case step1: PORTM = (inh | step4); break;
			case step2: PORTM = (inh | step1); break;
			case step3: PORTM = (inh | step2); break;
			case step4: PORTM = (inh | step3); break;
			default: PORTM = (inh | step1);
		}

		// Calibration complete indication
		calibrate = 0; 				
	}		
  }

  // Check if the PWM input from Ultrasonic sensor is high and start counting 
  if(PINU & p_input)
  {
  	if(p_valid == 1)
	{
		p_valid = 0;
		p_range = 0;
	}

	p_range++;	
  }
  else
  {
  	p_valid = 1;
	range = p_range;							
  }

}

//************************************************************
// main() function
//************************************************************

int main(void)
{

  // Initialize entire MCU
  initialize();
  
  // Main task scheduler loop
  while(1)
  {
    if((time_demo == 0) && (demoControl == 1))
	{
		// Executing the demo code
		demo();	
		
		demoNum--;

		if(demoNum == 0)
		{
			demoControl = 0;
			time_demo = 0;
		}
		else
		{			
			time_demo = tdemo;
		}		
	}
	
	// If demo executed, execute all other parts of the program
	if((time_init==0) && (demoControl==0))	
	{
		if(calibrate == 2)
		{
			calibrate  = 1;
		}

		if (time_motor==0)
	    {
	    	time_motor = tmotor;
			motorControl();			
	    }

		if(calibrate == 0)
		{
			if (time_sen == 0)
			{
				time_sen = tsen;
				rangeCalc();
			}
		
			if (time_vib == 0)
			{
				time_vib = tvib;
				vibControl();
			}

			if(time_rf == 0)
			{
				time_rf = trf;
				rfTransmit();			
				PORTL ^= (cpu_l);	
			}
		}
	}		
  }
}


//************************************************************
// Local Functions
//************************************************************

// demo() - Initial Demo Function
void demo(void)
{
	// Demo sequence steps. Vibrator motors start vibrating from one end, 
	// vibration progresses to the other end and returns to the first motor
	switch(demoNum)
	{
		case 10: vib_pwm[1] = 8; break;
		case 9:  vib_pwm[1] = 0; vib_pwm[2] = 8; break;
		case 8:  vib_pwm[2] = 0; vib_pwm[3] = 8; break;
		case 7:  vib_pwm[3] = 0; vib_pwm[4] = 8; break;
		case 6:  vib_pwm[4] = 0; vib_pwm[5] = 8; break;
		case 5:  vib_pwm[4] = 8; vib_pwm[5] = 0; break;
		case 4:  vib_pwm[3] = 8; vib_pwm[4] = 0; break;
		case 3:  vib_pwm[2] = 8; vib_pwm[3] = 0; break;
		case 2:  vib_pwm[1] = 8; vib_pwm[2] = 0; break;
		case 1:  vib_pwm[1] = 0; break;
	}
}	

//**************************************************

// filterRange() - Filter the range value at particular angles and the surrounding range values to represent the best 
// approximate vibrator range
void filterRange(void)
{

	int i;

	vib_range[0] = sen_range[vib_index[0]];
	vib_range[6] = sen_range[vib_index[6]];
		
	for(i=1; i<6; i++)
	{	
		vib_range[i] = ((2 * sen_range[vib_index[i]]) + sen_range[vib_index[i]-1] + sen_range[vib_index[i]+1]);
	}

	vib_range[3] = sen_range[vib_index[3]] << 2;

}

//**************************************************

// rangeCalc() - Calculate the range from the sensor depending on type of range
void rangeCalc(void)
{
	
	if(rangeType == 0)
	{
		a_range = ((int)ADCH);	
	  	ADCSRA |= (1<<ADSC); 

		range = a_range;
	}
	else if((rangeType == 1) && (p_valid == 1))
	{		
		range = p_range;						
	}
	
	
	rf_range[0] = rf_range[1]; 	
	rf_range[1] = rf_range[2];
	rf_range[2] = range;

	sen_range[senIndex] = range;

	if(ccw == 0)
	{
		senIndex++;
	}
	else if(ccw == 1)
	{
		senIndex--;
	}
}

//**************************************************

// vibControl() - scheduled by tvib. Used to control the operation of vibrator motors at particular angles
void vibControl(void)
{
	int i;

	vibLed = 0x00;
	
	for(i = 0; i<7; i++)
	{

		filterRange();			

		if(vib_range[i] == 0)
		{
			vib_pwm[i] = 0;
		}
		else if(vib_range[i] <= range1)
		{
			vib_pwm[i] = 9;
		}
		else if((vib_range[i] > range1) && (vib_range[i] <= range2))
		{
			vib_pwm[i] = 7;			
		}
		else if((vib_range[i] > range2) && (vib_range[i] <= range3))
		{
			vib_pwm[i] = 5;			
		}
		else if((vib_range[i] > range3) && (vib_range[i] <= range4))
		{
			vib_pwm[i] = 4;			
		}
		else if(vib_range[i] > range4)
		{
			vib_pwm[i] = 0;			
		}

		if(vib_pwm[i] <= 4)
		{
			vibLed |= (1 << i);
		}

	}

	vibLed = vibLed >> 1;
}


//**************************************************

// motorControl() - scheduled by tmotor, Generates control signals for stepper motor and controls rotation
// and number of steps
void motorControl(void)
{	
	if(ccw == 0)
	{
		// Counter clockwise step sequence
		switch(PORTM & 0x0F)
		{
			case step1: PORTM = (inh | step2); break;
			case step2: PORTM = (inh | step3); break;
			case step3: PORTM = (inh | step4); break;
			case step4: PORTM = (inh | step1); break;
			default: PORTM = (inh | step1);
		}
	}
	else if (ccw == 1)
	{
		// Clockwise step sequence
		switch(PORTM & 0x0F)
		{
			case step1: PORTM = (inh | step4); break;
			case step2: PORTM = (inh | step1); break;
			case step3: PORTM = (inh | step2); break;
			case step4: PORTM = (inh | step3); break;
			default: PORTM = (inh | step1);
		}
	}
	
	if(calibrate == 0)
	{
		if(ccw == 0)
		{ 
			rot++;
			if(rot == numSteps) 
			{
				ccw = 1;				
			}
		}
		else if(ccw == 1)
		{
			rot--;
			if(rot == 0) 
			{
				ccw = 0;					
			}
	    }
	}
}

//**************************************************

// Form and transmit RF data packet
void rfTransmit (void)
{
	// Increment packet count
	packet_count++;

	// Set the RF id according to rotation
	if(ccw == 0)
	{
		rf_id = ccw_id;
	}
	else if (ccw == 1)
	{
		rf_id = cw_id;
	}
	
	// Construct data packet
	rftx_data[0] = vibLed;					
	rftx_data[1] = rf_id;
	rftx_data[2] = rot;
	rftx_data[3] = rf_range[0];
	rftx_data[4] = rf_range[1];
	rftx_data[5] = rf_range[2];

	// Transmit data packet
	tx_me(rftx_data, rftx_data_length, tx_id);
}


//************************************************************
// MCU Initialization Functions
//************************************************************

// Primary Initialization Function
void initialize(void)
{
  // Set the type of the current range input from the sensor
  rangeType = rangeChoice;

  //ADC initialization  
  //Initialize the ADC only if the choice is set to 0
  if(rangeType == 0)	
  {
	  //init the A to D converter, channel zero, left adj, EXTERNAL Aref!
	  ADMUX = (1<<ADLAR) ;  
	  //enable ADC and set prescaler to 1/128*16MHz=125,000, and clear interupt enable, and start a conversion
	  ADCSRA = ((1<<ADEN) | (1<<ADSC)) + 7; 
  }	

//******************************************

  //Timer Initialization
  //Set up timer 0 for 1 mSec timebase
  TIMSK= (1<<OCIE1A);							// turn on timer 0 cmp match ISR
  OCR1A = 24;  									// set the compare to 25 time ticks
  TCCR1B= 3; 									// set prescalar to divide by 64 //0b00000011;
  TCCR1A= (1<<WGM01) ;							// turn on clear-on-match
  
//******************************************

  //RF Initialization
  baudval = (f_cpu / (16UL * baudrate)) - 1; 
  txrx_init(1,0,(int)baudval, 0);				// Transmission initialization. Enable Transmit, Disable Receive, Set Baud Value

//******************************************

  //Port Initialization
  
  // Motor
  DDRM = 0xFF;					// Set all the stepper motor connections to outputs
  PORTM = (inh | step1);		// Set the initial step for the stepper motor

  // Ultrasonic Sensor
  DDRU &= ~(p_input);			// Set the sensor connection on port A as input

  // Vibrating Motor
  DDRV 	= 0xFF;					// Set all vibrator motor connections to outputs
  PORTV = 0x00;					// Turn off all vibrator motors initially

  // Leds
  DDRL  |= (cpu_l | cal_o);		// Set the CPU led and calibration output connections as outputs
  DDRL  &= ~(cal_i);			// Set the calibration input as input
  PORTL |= (cpu_l | cal_i);		// Turn off Led (active low) and pull up cal_i input
  PORTL &= ~(cal_o);			// Set cal_o output to 0

//******************************************

  // Variable Initialization

  // Initial Calibration
  calibrate = 2;
  
  // Timers
  time_init = tinit;
  time_m = 0;
  time_sen = 0;
  time_motor = 0;
  time_rf = 0;
  time_vib = 0;

  // Motors
  ccw = 0;
  rot = 0;
  
  // RF
  rf_id = ccw_id;
  packet_count = 0;

  // Ultrasonic Sensor
  senIndex = 0;
  range = 0;
  a_range = 0;
  p_range = 0;
  p_valid = 0;

  // Vibrator Motors
  vib_index[0] = vib1;
  vib_index[1] = vib2;
  vib_index[2] = vib3;
  vib_index[3] = vib4;
  vib_index[4] = vib5;
  vib_index[5] = vib6;
  vib_index[6] = vib7;

  vibLed = 0x00;

  range1 = (p5ft * 4) << 2;
  range2 = (p5ft * 6) << 2;
  range3 = (p5ft * 8) << 2;
  range4 = (p5ft * 10) << 2;

    // Demo
  demoControl = demoC;

  if(demoControl == 1)
  {
  	time_demo = tdemo;
	demoNum = demoN;
  }
  else
  {
  	time_demo = 0 ;
	demoNum = 0;
  }
  
//******************************************

//Start the ISRs
  sei();

}







This is what I have done.I have placed the entire txrx.c file into the main code.Also I have declared all the variables and functions at the beginning.All the "multiple definition" errors got removed ,but now i'm getting a new error.The error is:


Error :lvalue required as left operand of assignment C:\Users\MALGUNKAR\Documents\Atmel Studio\uhvtransmitter\uhvtransmitter\uhvtransmitter.c line:488 column:10 uhvtransmitter

Was This Post Helpful? 0
  • +
  • -

#11 jimblumberg  Icon User is offline

  • member icon


Reputation: 4292
  • View blog
  • Posts: 13,458
  • Joined: 25-December 09

Re: "multiple declaration" error while building in atmel studio6(A

Posted 10 March 2013 - 08:01 AM

So what line actually corresponds to the line (496) your error message refers to?
The code you provided doesn't match the error message.


You really need to figure out how to use multiple files with your compiler. Having one giant file that contains all your source will make finding problems, following your logic difficult, especially when you use so many global variables.

Jim
Was This Post Helpful? 1
  • +
  • -

#12 pradnesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-March 13

Re: "multiple declaration" error while building in atmel studio6(A

Posted 10 March 2013 - 08:03 AM

View Postjimblumberg, on 10 March 2013 - 03:01 PM, said:

So what line actually corresponds to the line (496) your error message refers to?
The code you provided doesn't match the error message.


You really need to figure out how to use multiple files with your compiler. Having one giant file that contains all your source will make finding problems, following your logic difficult, especially when you use so many global variables.

Jim


This is the line in which i'm getting the error i.e. line no 488
tx_id=id;
Was This Post Helpful? 0
  • +
  • -

#13 jimblumberg  Icon User is offline

  • member icon


Reputation: 4292
  • View blog
  • Posts: 13,458
  • Joined: 25-December 09

Re: "multiple declaration" error while building in atmel studio6(A

Posted 10 March 2013 - 08:09 AM

Since your message is talking about the left value (the value to the left of the = sign) what type of variable, and where is this variable defined? I'm not going to sift thru 500 + lines of text to find where you defined this variable. You need to stop using global variables now!

Jim

This post has been edited by jimblumberg: 10 March 2013 - 08:09 AM

Was This Post Helpful? 1
  • +
  • -

#14 pradnesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-March 13

Re: "multiple declaration" error while building in atmel studio6(A

Posted 10 March 2013 - 08:15 AM

View Postjimblumberg, on 10 March 2013 - 03:09 PM, said:

Since your message is talking about the left value (the value to the left of the = sign) what type of variable, and where is this variable defined? I'm not going to sift thru 500 + lines of text to find where you defined this variable. You need to stop using global variables now!

Jim

It's on line no.55:

volatile unsigned char tx_data_length, tx_pkt_length, tx_id, tx_byte, tx_ing, tx_pkt_byte, tx_data_byte, tx_led;
Was This Post Helpful? 0
  • +
  • -

#15 jimblumberg  Icon User is offline

  • member icon


Reputation: 4292
  • View blog
  • Posts: 13,458
  • Joined: 25-December 09

Re: "multiple declaration" error while building in atmel studio6(A

Posted 10 March 2013 - 08:25 AM

Why have you used the volatile modifier on all these variables? Since this variable is an unsigned char and the other side is an int I suggest you try to cast the int to the unsigned char.



Jim
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2