Пример #1
0
void ADT_shutdown()
{
	uint8_t i;
	//shutdown
	for(i=0;i<ADT_sensor_count;i++)
	{
		#ifdef debug
		uart_print("ADT shutdown:");
		uart_num(i,1);
		uart_nl();
		#endif		
		if(bit_get(ADT_status,BIT(i)))
		{
			#ifdef debug
			uart_println("SKIP");
			#endif
			continue;
		}

		i2c_start(ADT_addr_base|i,I2C_WRITE);
		i2c_write(0x03);//config reg
		i2c_write(0b11100000);//7: 16bit res, 6~5: shutdown mode
		i2c_stop();
	}
		#ifdef debug
		uart_println("ADTs off");
		#endif

}
Пример #2
0
void ADT_wake()
{
	uint8_t i;
	//power on sensors
	for(i=0;i<ADT_sensor_count;i++)
	{
		#ifdef debug
		uart_print("ADT wake:");
		uart_num(i,1);
		uart_nl();
		#endif		
		if(bit_get(ADT_status,BIT(i)))
		{
			#ifdef debug
			uart_println("SKIP");
			#endif		
			continue;//jump to next sensor, this one is broken
		}

		i2c_start(ADT_addr_base|i,I2C_WRITE);
		i2c_write(0x03);//config reg
		i2c_write(0b10000000);
		i2c_stop();
	}
	
}
Пример #3
0
uint8_t ADT_check()
{
	uint8_t i;
	for(i=0;i<ADT_sensor_count;i++)
	{
		#ifdef debug
		uart_print("ADT chk: ");
		uart_num(i,1);
		#endif	
		if(i2c_start(ADT_addr_base|i,I2C_READ))
		{
			bit_set(ADT_status,BIT(i));//set Ith bit as sign of sensor error
			#ifdef debug
				uart_println(" FAIL");
			#endif
		}
		else
		{
			i2c_read(0);
			bit_clr(ADT_status,BIT(i));//set as working
			#ifdef debug
			uart_println(" OK");
			#endif
		}
		i2c_stop();
		
	}

	if(ADT_minimum_working > ADT_get_working_count())
	{
		error_flags.ADT=1;
		return 1;
	}
	else
	{	
		error_flags.ADT=0;
		return 0;
	}
}
Пример #4
0
uint8_t ADT_measure(int16_t *storage, uint8_t samples,uint16_t sample_pause_ms)
{
	ADT_wake();

	int32_t temp=0;
	
	uint8_t sensor_num,sample_num;
	
	int8_t Htemp;
	int16_t Ltemp;

	
	//delay fow proper wakeup
	
	delay_ms(300);//because 1st conversion after wake is fast and inaccurate,
	//nomal conversion tooks 240ms
	
	for(sample_num=0;sample_num<samples;sample_num++)//take N samples
	{
	
		
		for(sensor_num=0;sensor_num<ADT_sensor_count;sensor_num++)
		{

			#ifdef debug
			uart_print("ADT measure:");
			uart_num(sensor_num,1);
			uart_nl();
			#endif	

			if(!bit_get(ADT_status,BIT(sensor_num)))
			{
				if(i2c_start(ADT_addr_base|sensor_num,I2C_READ))//start reading
					return 1;
				Htemp=i2c_readAck();//recieve degrees
				Ltemp=i2c_readNak();//recieve decimals (hexadecimals correctly), align them on lower bits
				i2c_stop();

				temp+=(Htemp<<8)+Ltemp;
				
				#ifdef debug
				uart_num((Htemp<<8)+Ltemp,4);
				uart_putc('\n');
				#endif
			}
			#ifdef debug
			else
				uart_println("SKIP");
			#endif

		}
		delay_ms(sample_pause_ms); //wait for another conversion, tooks 240ms at minimum
	}
	
	

	temp=temp/(samples*ADT_get_working_count());//calculate average value (still not converted)
	//there is now sth. like 3089 (24.1°C)

	temp*=10;//without this, we will lose decimal information in next step
	temp/=128;//convert into value
	//now it is 241

	ADT_shutdown();
	
	*storage=temp;

	//all measurements done
	
	return 0;
}
Пример #5
0
int main(void)
{//all initializations
	int i,j,z,n;
	z=1;
i=0;
j=0;
DDRB|=0xFF;
DDRD|=0xFF;
DDRC|=0xFF;
TCCR1A|=(1<<WGM11)|(1<<COM1B1)|(1<<COM1A1)|(1<<COM1A0)|(1<<COM1B0);
TCCR1B|=(1<<WGM13)|(1<<WGM12)|(1<<CS11);
ICR1=19999;
	
	
	uart_init();
	while(1){
		
		
			while(1){i=0;
int grabbed=0;
			char input9[100]=" ";
		while(1) {input9[i] = uart_read();
			if (input9[i]=='.') 
			break;
			i++;}
		
		if(strcmp(input9,"Grab.")==0||strcmp(input9,"\nGrab.")==0)
		{//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
		//code to hold cube in 2 brackets, add delay and then hold with other 2 brackets if you want
PORTC=0b00001000;//select linear RL
		OCR1A=19150;
		_delay_ms(5000);
		PORTC=0b00000001;//select linear FB
		OCR1B=19150;
		_delay_ms(5000);
	
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
		grabbed=1;
		uart_string("Grabbed.\n");
			}
		else if(strcmp(input9,"Ungrab.")==0||strcmp(input9,"\nUngrab.")==0)
			{//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
		//all brackets go back,leaving cube
PORTC=0b00000000;//select linear RL and FB
			OCR1A=17200;
			OCR1B=17200;
			_delay_ms(5000);
	
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
		grabbed=0;
		uart_string("Ungrabbed.\n");
		
			}
		else if(strcmp(input9,"Start.")==0||strcmp(input9,"\nStart.")==0)
			{
				
//if (grabbed==1)
//{
uart_string("Ready.\n");
goto right;
	//}
			}


else {uart_string("Invalid.\n");
	uart_num(strcmp(input9,"Start."));
	uart_string(input9);
}
		}

	
		//*******************************************************************************************//Right	
		right:
		i=0;
		char input6[100]=" ";
		
		while(1) {
			input6[i] = uart_read();//read char
			if (input6[i]=='.')
			break;
			i++;
			
		}
		
		
		
		if(strcmp(input6,"\nRight.")==0)
		{
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
		//code to bring R to the top face

PORTC=0b00000001;//select linear FB
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00100100;//select R and L
		OCR1A=17200;
		OCR1B=19150;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=19150;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=17200;
		_delay_ms(100);
		PORTC=0b00100100;//select R and L
		OCR1A=18250;
		OCR1B=18250;
		_delay_ms(100);
		PORTC=0b00010010;//select B and F
		OCR1B=17200;
		OCR1A=19150;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=19150;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00010010;//select B and F
		OCR1B=18250;
		OCR1A=18250;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=19150;
		_delay_ms(100);

		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
		uart_string("Right.\n");
		}
		else {
		uart_num(strcmp(input6,"\nRight."));
			goto right;
		}
		//*******************************************************************************************//front
		front:
		i=0;
		char input1[100]=" ";
		
		
		while(1) {
			input1[i] = uart_read();//read char
			if (input1[i]=='.')
			break;
			i++;
			
		}
		
		
		if(strcmp(input1,"\nFront.")==0)
		{//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//code to bring F to the top face
		PORTC=0b00001000;//select linear RL
		OCR1A=17200;
		_delay_ms(100);
		PORTC=0b00010010;//select B and F
		OCR1A=17200;
		OCR1B=19150;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=19150;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00010010;//select B and F
		OCR1B=18250;
		OCR1A=18250;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=19150;
		_delay_ms(100);
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
		uart_string("Front.\n");
		}	
		else goto front;
		//*******************************************************************************************//down
		down:
		i=0;
		char input2[100]=" ";
		
		
		while(1) {
			input2[i] = uart_read();//read char
			if (input2[i]=='.')
			break;
			i++;
			
		}
		
		if(strcmp(input2,"\nDown.")==0)
		{//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//code to bring D to the top face
			
PORTC=0b00000001;//select linear FB
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00100100;//select R and L
		OCR1A=17200;
		OCR1B=19150;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=19150;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=17200;
		_delay_ms(100);
		PORTC=0b00100100;//select R and L
		OCR1A=18250;
		OCR1B=18250;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=19150;
		_delay_ms(100);
			
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		uart_string("Down.\n");
		}
		else goto down;
		//*******************************************************************************************//left
		left:
		i=0;
		char input3[100]=" ";
		
		
		while(1) {
			input3[i] = uart_read();//read char
			if (input3[i]=='.')
			break;
			i++;
			
		}
		
		
		if(strcmp(input3,"\nLeft.")==0)
		{//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//code to bring L to the top face


PORTC=0b00000001;//select linear FB
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00100100;//select R and L
		OCR1A=19150;
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=19150;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=17200;
		_delay_ms(100);
		PORTC=0b00100100;//select R and L
		OCR1A=18250;
		OCR1B=18250;
		_delay_ms(100);
		PORTC=0b00010010;//select B and F
		OCR1A=17200;
		OCR1B=19150;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=19150;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00010010;//select B and F
		OCR1B=18250;
		OCR1A=18250;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=19150;
		_delay_ms(100);


		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
		uart_string("Left.\n");
		}
		else goto left;
		//*******************************************************************************************//back
		back:
		i=0;
		char input4[100]=" ";
		
		
		while(1) {
			input4[i] = uart_read();//read char
			if (input4[i]=='.')
			break;
			i++;
			
		}
		
		
		if(strcmp(input4,"\nBack.")==0)
		{//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//code to bring B to the top face
PORTC=0b00001000;//select linear RL
		OCR1A=17200;
		_delay_ms(100);
		PORTC=0b00010010;//select B and F
		OCR1A=17200;
		OCR1B=19150;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=19150;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00010010;//select B and F
		OCR1B=18250;
		OCR1A=18250;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=19150;
		_delay_ms(100);

		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
		uart_string("Back.\n");
		}
		else goto back;
		//*******************************************************************************************//
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//write code to bring U on top again


PORTC=0b00000001;//select linear FB
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00010010;//select B and F
		OCR1A=17200;
		OCR1B=19150;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=19150;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=17200;
		_delay_ms(100);
		PORTC=0b00010010;//select B and F
		OCR1A=19150;
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=19150;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00010010;//select B and F
		OCR1A=18250;
		OCR1B=18250;
		_delay_ms(100);
		PORTC=0b00100100;//select R and L
		OCR1A=19150;
		OCR1B=17200;
		_delay_ms(100);
		PORTC=0b00000001;//select linear FB
		OCR1B=19150;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=17200;
		_delay_ms(100);
		PORTC=0b00100100;//select R and L
		OCR1A=18250;
		OCR1B=18250;
		_delay_ms(100);
		PORTC=0b00001000;//select linear RL
		OCR1A=19150;
		_delay_ms(100);
		//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//*******************************************************************************************//
		i=0;
		char input[100]=" ";
		
		
		while(1) {
			input[i] = uart_read();//read char
			if (input[i]=='.')
			break;
			i++;
			
		}
//*******************************************************************************************//solve cube
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//now code for solving the cube //solution is char input [100]
		
while(input[z]!='.')
{

while(input[j]!=' ')
{
n=n+1;
j++;
}
if(n==1)
{
if(input[z]=='R')
{
PORTC=0b00001100;//select R
OCR1A=17200;//rotR-0
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00001100;//select R
OCR1A=18250;//rotR-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}
else if(input[z]=='L')
{
PORTC=0b00100001;//select L
OCR1B=17200;//rotL-0
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100001;//select L
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}
else if(input[z]=='F')
{
PORTC=0b00001010;//select F
OCR1A=17200;//rotF-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1B=18250;//rotF-90
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
}
else if(input[z]=='B')
{
PORTC=0b00010001;//select B
OCR1B=17200;//rotB-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=18250;//rotB-90
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
}
else if(input[z]=='U')
{
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=19150;//rotR-180
OCR1B=17200;//rotL-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00000000;
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1A=17200;//rotF-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1A=18250;//rotF-90
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=17200;//rotR-0
OCR1B=19150;//rotL-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}
else if(input[z]=='D')
{
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=19150;//rotR-180
OCR1B=17200;//rotL-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=17200;//rotB-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=18250;//rotB-90
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=17200;//rotR-0
OCR1B=19150;//rotL-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}
z++;
}
if(n==2)
{
if(input[z+1]=='2')
{
if(input[z]=='R')
{
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00001100;//select R
OCR1A=19150;//rotR-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
PORTC=0b00001100;//select R
OCR1A=17200;//rotR-0
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00001100;//select R
OCR1A=18250;//rotR-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}
else if(input[z]=='L')
{
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100001;//select L
OCR1B=19150;//rotL-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
PORTC=0b00100001;//select L
OCR1B=17200;//rotL-0
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100001;//select L
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}
else if(input[z]=='F')
{
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1A=19150;//rotF-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1A=17200;//rotF-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1A=18250;//rotF-90
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
}
else if(input[z]=='B')
{
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=19150;//rotB-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=17200;//rotB-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=18250;//rotB-90
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
}
else if(input[z]=='U')
{
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=19150;//rotR-180
OCR1B=17200;//rotL-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1A=19150;//rotF-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1A=17200;//rotF-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1A=18250;//rotF-90
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=17200;//rotR-0
OCR1B=19150;//rotL-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}
else if(input[z]=='D')
{
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=19150;//rotR-180
OCR1B=17200;//rotL-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=19150;//rotB-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=17200;//rotB-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=18250;//rotB-90
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=17200;//rotR-0
OCR1B=19150;//rotL-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}
z+=2;}
else 
if(input[z]=='R')
{
PORTC=0b00001100;//select R
OCR1A=19150;//rotR-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00001100;//select R
OCR1A=18250;//rotR-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}
else if(input[z]=='L')
{
PORTC=0b00100001;//select L
OCR1B=19150;//rotL-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100001;//select L
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}
else if(input[z]=='F')
{
PORTC=0b00001010;//select F
OCR1A=19150;//rotF-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1A=18250;//rotF-90
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
}
else if(input[z]=='B')
{
PORTC=0b00010001;//select B
OCR1B=19150;//rotB-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=18250;//rotB-90
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
}
else if(input[z]=='U')
{
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=19150;//rotR-180
OCR1B=17200;//rotL-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1A=19150;//rotF-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00001010;//select F
OCR1A=18250;//rotF-90
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=17200;//rotR-0
OCR1B=19150;//rotL-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}
else if(input[z]=='D')
{
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=19150;//rotR-180
OCR1B=17200;//rotL-0
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=19150;//rotB-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=17200;//linFB-0
_delay_ms(100);
PORTC=0b00010001;//select B
OCR1B=18250;//rotB-90
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=17200;//rotR-0
OCR1B=19150;//rotL-180
_delay_ms(100);
PORTC=0b00000001;//select linear FB
OCR1B=19150;//linFB-180
_delay_ms(100);
PORTC=0b00001100;//select linear RL
OCR1A=17200;//linRL-0
_delay_ms(100);
PORTC=0b00100100;//select R and L
OCR1A=18250;//rotR-90
OCR1B=18250;//rotL-90
_delay_ms(100);
PORTC=0b00001000;//select linear RL
OCR1A=19150;//linRL-180
_delay_ms(100);
}

z+=2;
}
z++;

}



//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++		
//*******************************************************************************************//done
	uart_string("Done\n");
	}


	}
Пример #6
0
//------------------------------------------------------------------------------
void main()
{
	WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
#if 1
	BCSCTL2 = SELM_0 | DIVM_0 | DIVS_0;
	DCOCTL = 0x00;
	BCSCTL1 = CALBC1_1MHZ;
	DCOCTL = CALDCO_1MHZ;

	BCSCTL1 |= XT2OFF | DIVA_0;
	BCSCTL3 = XT2S_0 | LFXT1S_0 | XCAP_1;

	/*do {
        IFG1 &= ~OFIFG; // Clear OSC fault flag
        __delay_cycles(50);  // 50us delay
    } while (IFG1 & OFIFG);
	*/
	WDTCTL = WDTPW | WDTTMSEL | WDTSSEL;
#else
	BCSCTL3 |= LFXT1S_2;                  // VLOCLK

	BCSCTL1 = CALBC1_1MHZ;                // Set DCO to calibrated 1 MHz.
	DCOCTL = CALDCO_1MHZ;

	//BCSCTL1 |= DIVA_0;  // ACLK / 8
	BCSCTL3 |= XCAP_3;
#endif
	// Init timer1
	//
	TA0CCR0   = 0x7FFF;
	TA0CCTL0  = CCIE;
	TA0CTL = TASSEL_1 + MC_1 + ID_0; // ACLK, up to CCR0, divider /1

	// Init timer2
	//
	TA1CCR0   = 0x3FFF;
	TA1CCTL0  = CCIE;
	TA1CTL = TASSEL_1 + MC_1 + ID_0; // ACLK, up to CCR0, divider /1

	// Init timer3
	//
	WDTCTL = WDT_ADLY_1000;
	IE1 |= WDTIE;

	uart_init();

	// main loop
	//
	config_port_init();
	app_init();

	uart_num(BCSCTL1);
	uart_str("main\n");

	//if (BCSCTL3 & LFXT1OF)
	//	uart_str("osc fault\n");

	//__enable_interrupt();
	while (1) {
		if (g_event == 0)
			__bis_SR_register(LPM0_bits + GIE);

		if (g_event & EV_TIMER1) {
			if (cb_timer1)
				cb_timer1();
			g_event &= ~EV_TIMER1;
		}
		if (g_event & EV_TIMER2) {
			if (cb_timer2)
				cb_timer2();
			g_event &= ~EV_TIMER2;
		}
		if (g_event & EV_TIMER3) {
			if (cb_timer3)
				cb_timer3();
			g_event &= ~EV_TIMER3;
		}
		if (g_event & EV_TX) {
			if (cb_uart_tx)
				cb_uart_tx();
			g_event &= ~EV_TX;
		}
			
	}
}