Ejemplo n.º 1
0
int main(void){
	volatile uint32_t delay;
	int i;
	
	PLL_Init();
	Output_Init();
//	CAN0_Open();
	
	DisableInterrupts();
	
	SYSCTL_RCGCGPIO_R |= 0x20;
  while((SYSCTL_PRGPIO_R&0x0020) == 0){};// ready?
  Count = 0;                       // allow time to finish activating
//  GPIO_PORTF_DIR_R |= 0x04;        // make PF2 out (built-in LED)
//  GPIO_PORTF_AFSEL_R &= ~0x04;     // disable alt funct on PF2
//  GPIO_PORTF_DEN_R |= 0x04;        // enable digital I/O on PF2
//                                   // configure PF2 as GPIO
//  GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF0FF)+0x00000000;
//  GPIO_PORTF_AMSEL_R = 0;          // disable analog functionality on PF
	
	GPIO_PORTF_LOCK_R = 0x4C4F434B;   // 2) unlock GPIO Port F
	GPIO_PORTF_CR_R = 0x1F;           // allow changes to PF4-0
	GPIO_PORTF_AMSEL_R = 0x00;        // 3) disable analog on
    
	GPIO_PORTF_DIR_R &= ~0x03;       // make PB6 in
  GPIO_PORTF_AFSEL_R |= 0x03;      // enable alt funct on PB6
  GPIO_PORTF_DEN_R |= 0x03;        // enable digital I/O on PB6
                                   // configure PB6 as T0CCP0
  GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFFF00)+0x00000077;
  GPIO_PORTF_AMSEL_R &= ~0xFF;     // disable analog functionality on PB6
		
	SYSCTL_RCGCGPIO_R  |= 0x01;
	delay = SYSCTL_RCGCGPIO_R;      // 2) allow time for clock to stabilize
  delay = SYSCTL_RCGCGPIO_R;
	GPIO_PORTA_DIR_R |= 0x01;  			// 3.11) make PA6 output
  GPIO_PORTA_AFSEL_R &= ~0x01; 		// 4.11) disable alternate function on PA6
  GPIO_PORTA_DEN_R |= 0x01;  			// 5.11) enable digital I/O on PA6
  GPIO_PORTA_AMSEL_R = 0; 				// 6.11) disable analog functionality on PA6	
	Switch_Init();
	
	Init_Timer4A();
	Timer4A_Wait(80000000); //wait 1 sec
	Init_Timer5A(80000);
	ADC0_InitTimer3ATriggerSeq3PD3(6000);
	ADC0_InitTimer3BTriggerSeq2PD2(5500);
	
	TimerCapture_Init(UserTask2);
	InitMotors();
	
	EnableInterrupts();
	
	
	while(1) {
		getSensorValues();
		printSensorValues(0);
		if(buttonL) {
			printSensorValues(6);
			ControlMotors(35000,35000);
			ST7735_SetCursor(0,8);ST7735_OutString("Buttonback");
			buttonL = 0;
			for(i = 0; i < 1440000; i++);
		}
		if(buttonR) {
			printSensorValues(6);
			ControlMotors(35000,35000);
			ST7735_SetCursor(0,1);ST7735_OutString("ButtonR");
			buttonR = 0;
			for(i = 0; i < 1440000; i++);
		}
		
		if (Ping1 < 18) {
			//ControlMotors(40000, 40000);
			ST7735_SetCursor(0,1);
			ST7735_OutString("Stopped");
			printSensorValues(3);
//			while(1) {
				ST7735_SetCursor(0,1);ST7735_OutString("Stopped");
				getSensorValues();
				printSensorValues(0);
//			}
			if(IR_L > IR_R) {
				ControlMotors(35000,35000);
				ST7735_SetCursor(0,8);ST7735_OutString("BL");
			}
			else {
				ControlMotors(35000,35000);
				ST7735_SetCursor(0,8);ST7735_OutString("BR");
			}
			for(i = 0; i < 1440000; i++);
		}
		else if (((Ping2 > 80) != (Ping3 > 80)) && (Ping1 < 40)) {
			if (Ping2>80) {
				//spot turn right
				ControlMotors(20000, 60000);
			}
			if (Ping3>80) {
				//spot turn left
				ControlMotors(60000, 20000); 
			}
		//	ControlMotors(40000,40000);
		}
		else if(IR_L < 1500 && IR_R < 1500) {
			ControlMotors(70000,65000);
			ST7735_SetCursor(0,8);ST7735_OutString("FO");
		}
		else if(IR_L < IR_R) {
			ControlMotors(70000,50000);
			ST7735_SetCursor(0,8);ST7735_OutString("LE");
		}
		else if(IR_R < IR_L) {
			ControlMotors(70000,72000);
			ST7735_SetCursor(0,8);ST7735_OutString("RI");
		}
	}
}
Ejemplo n.º 2
0
//---------------------------- PING_Init -----------------------------
//called before OS_Launch
void PING_Init(void (*task)(void)){
	
	TimerCapture_Init(task);
	//setup edge interrupt (with interrupts not enabled for PB6; )

}