Exemple #1
0
// *************************** Capture image dimensions out of BMP**********
int main(void){
  TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
  Output_Init();
	ADC0_Init();
	DAC_Init();
	SysTick_Init();
	Menu_Init();
	Sound_Init();
	UART1_Init();
	
	Button0_Init();
	Timer0_Init(Play, 80000000/11025);	// 11.025 kHz 80000000/11025
	Timer1_Init(Master_Funk,  80000000/60);
	//Timer2_Init(SomeUART function, high speed); //for UART

 /* ST7735_FillScreen(0x0000);            // set screen to black
  ST7735_SetCursor(1, 1);
  ST7735_OutString("GAME OVER");
  ST7735_SetCursor(1, 2);
  ST7735_OutString("Nice try,");
  ST7735_SetCursor(1, 3);
  ST7735_OutString("Earthling!");
  ST7735_SetCursor(2, 4);
  LCD_OutDec(1234);	 */
  while(1){							
  } 
}
Exemple #2
0
void Sound_Init(void){
	DAC_Init();
  Timer1_Init(Sound_Init, 7256);
	Index=0;
  length = 1304;
	array=  Centipede_Beat;
};
int main( void )
{   
	sei();
 	Timer1_Init();
	I2C_init(0x52);	 
    USARTInit(9600);
//	SERVO_Init();
	
		
//	SERVO_UpdateServo(0,1500);
//	SERVO_UpdateServo(1,1800);
//	SERVO_UpdateServo(2,2600);
//	SERVO_UpdateServo(3,2800);
	

	//Timer1_print_time(Timer1_get_time());
	
	USARTWriteString("\r\nReset\r\n");
	SERVO_Run();

	
	
	while(1)
	{
		//handleI2C();
		//I2C_isdataready();
		
	}
	
	return 0;
}
/*************************************************************
//! 函数名:void main (void)
//! 函数说明:主程序
*************************************************************/
void main (void)
{
   unsigned char i,max_data_chn; 
   struct movement_info *car_cmd;

   PCA0MD &= ~0x40;    //关闭看门狗                
   Oscillator_Init();  //时钟晶振初始化
    // ADC_PortInit();                  
   Timer1_Init();      //定时器1初始化                
   //Timer3_Init ();                                                        
   SMBus_Init ();      //SMBus初始化(IIC控制器)    
   PWM_Init();		   //PWM初始化
   servo_init();	   //舵机控制初始化            
  //Watchdog_Init();
   EA = 1;             // 开中断
  
	do
	{	      

	    Flag = 0; 
		while (!rec_flag) ;	//检测接收控制数据的标志

		rec_flag = 0;
		car_cmd = (struct movement_info *)Data; //若接收到数据,则从全局区取出
		car_movement_control(car_cmd);			//根据控制信息执行车体控制代码
		
	}while(1);

}
// ////
// MAIN
int main()
{
    ////Setup////
    CHARGE_EN_RELAY_TRIS		= 0;			//Output
    DISCHARGE_EN_PMOS_TRIS	= 0;     		//Output
    CHARGE_EN_PMOS_TRIS 		= 0;        	//Output
    FLASH_DISABLE_TRIS		= 0;			//Output
    VPACK_OUT_TRIS			= 1;			//Input
    VPACK_IN_TRIS				= 1;			//Input
    VSUPPLY_TRIS				= 1;			//Input
    VSHUNT_CHARGE_AMP_TRIS 	= 1;    		//Input
    VSHUNT_DISCHARGE_AMP_TRIS	= 1;            //Input

    DISCHARGE_EN_PMOS_BIT 	= 0;
    CHARGE_EN_PMOS_BIT 		= 0;
    CHARGE_EN_RELAY_BIT 		= 0;
    FLASH_DISABLE_BIT			= 1;			//Disable Flash

    MEM_ADDR_STRUCT Mem_Addr_Struct;
    Mem_Addr_Struct.Mem_Addr_Total = 0;

    Timer1_Init();							//Initialize Timer 1
    ADC_Init();								//Initialize ADC
    UART_Init();
    //FLASH_MEM_Init();
    //UNBLOCK_MEMORY();

    unsigned char temp;

    printf("\nTester Unit running...\n\n");

    while(1)
    {
        if(INCOMING_UART_INPUT)
        {
            temp = UART_INPUT;

            switch(temp)
            {
            case 'c':
            case 'C':
            {
                printf("Hub sent a 'Charge' request.\n");
                break;
            }
            case 'd':
            case 'D':
            {
                printf("Hub sent a 'Discharge' request.\n");
                break;
            }
            default:
                printf("Hub sent an unfamiliar request.\n");
            } /*End Switch*/
        }/*End if(INCOMING_UART_INPUT)*/
    } /*End while*/
} /*End Main*/
Exemple #6
0
/*******************************************************
* "Soft" real-time event handler for slow rate
********************************************************/
void slow_event_handler(void)
{
    if(slow_event_count > slow_ticks_limit)
    {
        slow_event_count = 0;
        
        if(control_flags.first_scan)
        {
            putsUART((unsigned char *)WelcomeMsg,&UART1);
            //putsUART((unsigned char *)WelcomeMsg,&UART2);
            
            control_flags.first_scan = 0;
        }

        // (RAM) Parameters update management
        if(control_flags.PAR_update_req)
        {
            update_params();
            control_flags.PAR_update_req = 0;
        }
        
        if(direction_flags.word != direction_flags_prev)
        {
            // RESET COUNTS
            QEI1_Init();
            QEI2_Init();
            Timer1_Init();
            Timer4_Init();
            direction_flags_prev = direction_flags.word;
        }

        // EEPROM update management
        if(control_flags.EE_update_req)
        {
			control_flags.EE_update_req = 0;
        }

        update_delta_joints();
		update_delta_EE();//aggiornamento delle strutture dati
        status_flags.homing_done = home_f.done;

        // SACT protocol timeout manager (see SACT_protocol.c)
        SACT_timeout();
		SACT_SendSDP();
		SACT_SendSSP();

        // CONTROL MODE STATE MANAGER
        control_mode_manager();

    } // END IF slow_event_count..
}// END slow_event_handler
Exemple #7
0
int main()
{
	MCU_Init();
	Timer1_Init();
	Timer2_Init();
	IO_Init();
	ADC_Init();
	Timer1_ON;		//start 16 bit timer1
	Timer2_ON;		//start 16 bit timer2
	ADC_ON;			//turns on ADC module

	while(1)
	{
		ADC_Convert();
	}
}
int main(void){
	
  PLL_Init(Bus80MHz);                   // 80 MHz
	DisableInterrupts();
  //ADC0_InitSWTriggerSeq3_Ch9();         // allow time to finish activating
  Timer0A_Init100HzInt();               // set up Timer0A for 100 Hz interrupts
	Timer1_Init();
	Display_Init();						//initialize display
	Timer2_Init1Hz();		
	PortF_Init(); //initialize portf with onboard switches
	PortE_Init(); // initialize port e as breadboard switches.
	
  EnableInterrupts();

  while(1){

	}
}
Exemple #9
0
int main(void){
	PLL_Init(Bus80MHz);                   // 80 MHz
  SYSCTL_RCGCGPIO_R |= 0x20;            // activate port F
  ADC0_InitSWTriggerSeq3_Ch9();         // allow time to finish activating
  Timer0A_Init100HzInt();               // set up Timer0A for 100 Hz interrupts
  Timer1_Init();
	//Timer2_Init();											//Enable this for part D.
	GPIO_PORTF_DIR_R |= 0x06;             // make PF2, PF1 out (built-in LED)
  GPIO_PORTF_AFSEL_R &= ~0x06;          // disable alt funct on PF2, PF1
  GPIO_PORTF_DEN_R |= 0x06;             // enable digital I/O on PF2, PF1
                                        // configure PF2 as GPIO
  GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF00F)+0x00000000;
  GPIO_PORTF_AMSEL_R = 0;               // disable analog functionality on PF
  PF2 = 0;                      // turn off LED
	EnableInterrupts();
  while(1){
    PF1 ^= 0x02;  // toggles when running in main
		//GPIO_PORTF_DATA_R ^= 0x02;  // Uncomment this for part C. and comment the line above.
		//PF1 = (PF1*12345678)/1234567+0x02;  // Uncomment this for part D.
		if(i==1000){
			int largest = 0;
			for(int j; j < 1000; j++){
				if(largest < array2[i]){
					largest = array2[i];
					i++;
				}
			}
			Output_Init();              // initialize output device
			Errors = 0;
			int x;
			int y;
			DisableInterrupts();
			storeFrequency();
			makePMF(array3, pmf);
			ST7735_XYplotInit("Lab 2 PMF", 0, 4095, 0, 1000);
			for(int j = 0; j < 1000; j += 10){
			 	ST7735_PlotBar(pmf[j] * 9);
				ST7735_PlotNext();
			}
			break;
		}
  }
	while(1);
}
Exemple #10
0
void main()
{
	EA=1;
	P1&=0XEF;
	Timer0_Init(1);
	Timer1_Init();
	INT0_Init();
	while(1)
	{
		if(Flag_IR)
		{
			Flag_IR=0;
			LedBuff[0]=LedChar[IRBuff[0]/16];
			LedBuff[1]=LedChar[IRBuff[0]%16];;
			LedBuff[4]=LedChar[IRBuff[2]/16];;
			LedBuff[5]=LedChar[IRBuff[2]%16];;
		}
	}
}
//***************Timer3A_Handler****************
//Plays the Tetris Sound onces at the beginning of each round
//Then it deactivates itself until the next round begins 
//Input: none
//Output: none
void Timer3A_Handler(void){
	TIMER3_ICR_R = 0x01;
	TIMER3_CTL_R = 0x0000000;    //disable TIMER0
//	TIMER1_CTL_R = 0x0000000;    //disable TIMER1
//	TIMER2_CTL_R = 0x0000000;    //disable TIMER2
			for(int num =0; num  < 133; num++){//133
					if(TETRIS[num] == Z1) i=5;else i =150;	//check if Z1 change the period to 5
			Sound_Play2(TETRIS[num]);						//play the note
			Delay10ms(i);												//delay after each note usign the value of i
			}
		NVIC_ST_CTRL_R =0;					 //disable SysTick after the song has been played 
//		TIMER0_CTL_R = 0x0000001;    //enable TIMER0
//		TIMER2_CTL_R = 0x0000001;    //enable TIMER2
			DisableInterrupts();
		Timer0_Init(70000000);				//1000000
		Timer1_Init(7255);
		Timer2_Init(30000000);
			EnableInterrupts();			
		TIMER3_CTL_R = 0x0000000;		 //disable TIMER1A 
}
Exemple #12
0
int main(void) {
    // Initialize all hardware
    PLL_Init();
    eStopInit();
    encoderInit(actlPos);
    motorInit();
    lightsInit();
    lightsUpdate(COLOR_RED);
    UART_Init();
    Timer1_Init();
    softRun();
    
    // Send welcome message to UART terminal
    UART_OutChar('W');UART_OutChar('e');UART_OutChar('l');UART_OutChar('c');
    UART_OutChar('o');UART_OutChar('m');UART_OutChar('e');
    UART_OutChar(CR);UART_OutChar(LF);
 
    // Spin forever
    while(1) {
        parse(UART_InUDec()); // read commands from UART
            
        // All other functions performed by Timer 1 interrupt handler
    }
}
Exemple #13
0
int main(void){
  PLL_Init(Bus80MHz);                   // 80 MHz
  SYSCTL_RCGCGPIO_R |= 0x20;            // activate port F
  //ADC0_InitSWTriggerSeq3_Ch9();         // allow time to finish activating
  
  GPIO_PORTF_DIR_R |= 0x06;             // make PF2, PF1 out (built-in LED)
  GPIO_PORTF_AFSEL_R &= ~0x06;          // disable alt funct on PF2, PF1
  GPIO_PORTF_DEN_R |= 0x06;             // enable digital I/O on PF2, PF1
                                        // configure PF2 as GPIO
  GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF00F)+0x00000000;
  GPIO_PORTF_AMSEL_R = 0;               // disable analog functionality on PF
  PF2 = 0;                      // turn off LED
	DisableInterrupts();
	Timer0A_Init60HzInt();  //updates time every second
	Timer1_Init();	//sound
	Timer2_Init();
	//Switch_Init();					//interrupts on switch press
	ST7735_InitR(INITR_REDTAB);
	ST7735_PlotClear(0,160);
		play = 0;
		TIMER1_CTL_R = 0x00000000;
	EnableInterrupts();	
	ST7735_Circle(ST7735_BLACK);
	//drawClockHands(hour, minute, 1);
	drawDigTime(hour, minute, AMPM);
	ST7735_SetCursor(2, 14);
	printf("<");
	ST7735_SetCursor(18, 14);
	printf(">");
	drawClockHands(2,30,1);
		play = 1;
		TIMER1_CTL_R = 0x00000001;
	while(1){
		
	}
}
void main(){ 
	
	Setup_IOports();
	atod_init();
	_delay(200);
	lcd_init();
	Serial_Init();
	Timer1_Init();
	enableInterrupt();

	clr_display();
	printf("Body Temperature ");
	position(2,1);
	printf(" and Heart Rate  ");
	__delay_ms(5000);
		
	clr_display();
	
	while(1){				
		switch (Mode){
			case  0 :			
				a2d_read();				
				__delay_ms(100);
				check_pc();
			break;
			case 1 :			
				Tx_Control = 1;
				Serial_Print( "*#DREQ=123" );
				Serial_NewLine();
				Tx_Control = 0;		
			break;
			case 2 :
				Tx_Control = 1;
				Serial_Print( "*#123=" );				
				Serial_NewLine();				
				Tx_Control = 0;	
			break;
			case 3 :
				Tx_Control = 1;				
				Serial_Print( "*#123=" );							
				Tx_Control = 0;	
				
				position(1,1);
				printf("Data request... ");
				position(2,1);
				printf("                ");
							
			break;
			case 4 :
				Tx_Control = 1;				
				Serial_NewLine();
				Tx_Control = 0;	
								
			case 5 :
				clr_display();			
			break;
			default:
			
			break;
		}	
	}
}
Exemple #15
0
/*******************************************************
* MAIN function, just setup some inits and loops
* "soft" real-time event handlers, defined hereafter
********************************************************/
int main(void)
{    
// configuro l'oscillatore interno che mi fornisce Tcy
// Fosc = Fin (M/(N1*N2))
// FCY = Fosc/2
    PLLFBD = 39; 			// M = 40
    CLKDIVbits.PLLPOST=0; 	// N2 = 2
    CLKDIVbits.PLLPRE=0; 	// N1 = 2

    RCONbits.SWDTEN = 0;	//disabilito il watchdog 

	DataEEInit();

    //Init Peripheral Pin Selection (QEI and UART)
    PPS_Init();
   
    control_flags.first_scan = 1;
    slow_ticks_limit = SLOW_RATE * (FCY_PWM / 1000) - 1 ;
    medium_ticks_limit = MEDIUM_RATE * (FCY_PWM / 1000) - 1;
    
    mposition1 = zero_pos1;//parto dalla posizione iniziale 90 90 90
	mposition2 = zero_pos2;
	mposition3 = zero_pos3;

	/*mtheta1 = 0;
	mtheta2 = 0;
	mtheta3 = 0;

	x_cart = 0;
	y_cart = 0;
	z_cart = 0;*/

	coordinates_actual.x = 0;
	coordinates_actual.y = 0;
	coordinates_actual.z = 0;

	coordinates_temp.x = 0;
	coordinates_temp.y = 0;
	coordinates_temp.z = 0;

	angleJoints_actual.theta1 = 0;
	angleJoints_actual.theta2 = 0;
	angleJoints_actual.theta3 = 0;

	angleJoints_temp.theta1 = 0;
	angleJoints_temp.theta2 = 0;
	angleJoints_temp.theta3 = 0;

	update_params();
    
    direction_flags_prev = direction_flags.word;

     // UARTs init
     // no need to set TRISx, they are "Module controlled"
    UART1_Init();  

    // Setup control pins and PWM module,
    // which is needed also to schedule "soft"
    // real-time tasks w/PWM interrupt tick counts
    DIR1 = direction_flags.motor1_dir;//0;
    DIR2 = direction_flags.motor2_dir;//1; 
    DIR3 = direction_flags.motor3_dir;
             
    //BRAKE1 = 0;
    //BRAKE2 = 0; 

    DIR1_TRIS = OUTPUT;
    DIR2_TRIS = OUTPUT;
    DIR3_TRIS = OUTPUT;
    //BRAKE1_TRIS = OUTPUT;
    //BRAKE2_TRIS = OUTPUT;
    
    CURRSENSE1_TRIS = INPUT;
    CURRSENSE2_TRIS = INPUT;
    CURRSENSE3_TRIS = INPUT;
    
    PWM_Init();
    
    // MUST SETUP ALSO ANALOG PINS AS INPUTS
    AN0_TRIS = INPUT;
    AN1_TRIS = INPUT;
    AN2_TRIS = INPUT;
    
    ADC_Init();
    DMA0_Init();
    
    // SETUP ENCODER INPUTS
    // QEI inputs are "module controlled"
    // -> no need to set TRISx
    QEI1_Init();
    QEI2_Init();
    
    // Timers used to acquire Encoder 3
    // corresponding PINS set as inputs
    T1CK_TRIS = INPUT;
    T4CK_TRIS = INPUT;
    Timer1_Init();
	Timer2_Init();
    Timer4_Init();
	
    // Timer5 used to schedule POSITION loops
    Timer5_Init();

	//Input capture
	IC1_Init();
	IC2_Init();

    // TEST PIN
    TEST_PIN_TRIS = OUTPUT;
    TEST_PIN = FALSE;

    while(1)//a ciclo infinito ripeto queste 2 routine
        {	            
			medium_event_handler();
            slow_event_handler();
        }
    
    return 0; //code should never get here
}// END MAIN()
Exemple #16
0
int main(void){
  PLL_Init();                           // 25 MHz
	

	
  SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // activate port F
   ADC0_InitSWTriggerSeq3(0);            // allow time to finish activating
 // ADC0_InitAllTriggerSeq3(0);           // allow time to finish activating
	Timer0A_Init10HzInt();                // set up Timer0A for 10 Hz interrupts
  Timer1_Init();												// Intitalize timer1 count down
	
  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_PORTF2 = 0;                      // turn off LED
	 EnableInterrupts();
   ST7735_InitR(INITR_REDTAB);
	ST7735_FillScreen(0);  // set screen to black
	ST7735_SetCursor(0,0);
  ST7735_XYplotInit("Lab 2 PMF Averaging \n", 0, 4096, 0, 50);
	ST7735_OutString("1 point \n");
  while(1){
     WaitForInterrupt();
		 
//    GPIO_PORTF2 = 0x04;                 // profile
//    ADCvalue = ADC0_InSeq3();
//    GPIO_PORTF2 = 0x00;
		
		
		if(Buffer_Counter == 1000){
		    break;
		}
  }
		uint32_t Jitter;
	//	DisableInterrupts();
		//	TIMER1_CTL_R = 0x00000000;    // 10) enable TIMER1A
			GPIO_PORTF2 = 0x04;                   // profile
			
			
			Jitter = Calc_Jitter();  
			 uint32_t n = ADCvalue;
 	  //	 ST7735_OutUDec(n);
			Calc_PMF();  // will populate the frequency table ADC_Data = x-axis ADC_Freq = y-axis
			// Next line is call to the plot point function we created in lab1
		  //	ST7735_XYplotInit("PMF", 0, 4096, 0, 50);
		  //  ST7735_XYplot(1000, ADC_Data, ADC_Freq);
			int j = 0;
			uint32_t x = 0;
			uint32_t y = 0;
	    int i = 0;
			//ST7735_PlotClear(32, 159);
		//	for(j = 0; j < 1000; j+=1){
				ST7735_XYplotInit("Lab 2 PMF", 0, 4095, 0, 1000);
				ST7735_XYplot(1000, ADC_Data, ADC_Freq);
			 	// ST7735_PlotBar(ADC_Freq[j]);
				// ST7735_PlotBar(ADC_Freq[j]);
				 //ST7735_PlotBar(30);
				//ST7735_PlotNext();
				
			//	  y = 32+(127*(400-ADC_Freq[j]))/400;
		  //		x = 127-(127*(4095 - ADC_Data[j])/4095);
			//	  if(x<0)x = 0;
			//		if(x>127)x=127;
			//		if(y<32) y = 32;
			//	ST7735_PlotBar(y);
			//	if(y>159) y = 159;
			 // 	if(x > i){
				//		ST7735_PlotNext();
				 //	  i += 1;
				 // }
				
				/*
				if(j < 14){
				ST7735_OutUDec(ADC_Data[j]);
				ST7735_OutString(" ");
				ST7735_OutUDec(ADC_Freq[j]);
					ST7735_OutString("\n");
				}
				*/
//			}
			GPIO_PORTF2 = 0x00;
		//	EnableInterrupts();
}
void Pwm_Init_Devices(void)
{
 Pwm_Port_Init();
 Timer1_Init();
}
Exemple #18
0
/*
 * Application's entry point
 */
int main(void){
	SlSecParams_t secParams;
  char *pConfig = NULL;
	uint32_t timeElapsed;
  initClk();        // PLL 50 MHz
  UART_Init();      // Send data to PC, 115200 bps
  LED_Init();       // initialize LaunchPad I/O 
	Timer1_Init();
	ADC0_InitSWTriggerSeq3_Ch9(); //initialize ADC sampler
	ST7735_InitR(INITR_REDTAB);
	
	ST7735_SetCursor(1,1);
	printf("Lab4C\n");
	Wifi_Connect(pConfig, &secParams);
  UARTprintf("Weather App\n");
	while(1){
		// clear the data output
		ST7735_SetCursor(0,4);
		for(uint16_t i = 0; i < 6; i += 1) {
			printf("               \n");
		}
		ST7735_SetCursor(0,4);

		LED_GreenOn();
		Timer1_StartWatch();
		char *weather_data = HTTP_Request(
			"api.openweathermap.org", 80,
			"GET", "/data/2.5/weather?q=Austin%20Texas&units=metric&APPID=d6e361f259c47a6ea9837d41b1856b03",
			NULL,
			NULL
		);
		timeElapsed = Timer1_StopWatch();
		LED_GreenOff();
		UARTprintf("\r\n\r\n");
		UARTprintf(weather_data);  UARTprintf("\r\n");
    
		printf("Temp = %6s C\n", Extract_Temperature(weather_data));
		printf("Time = %lums\n", timeElapsed * 125 / 10 / 1000000 );
		
		uint32_t sample = ADC0_InSeq3();
		LED_GreenOn();
		Timer1_StartWatch();
		char *send_data = HTTP_Request(
			// embsysmooc or embedded-systems-server?
			"embsysmooc.appspot.com", 80,
			"GET", "/query?city=Austin%20Texas&id=John%20Starich%20and%20Jon%20Ambrose&edxcode=8086&greet=Voltage~",
			VoltageToString(sample),
			"V"
		);
		timeElapsed = Timer1_StopWatch();
		LED_GreenOff();
		UARTprintf("\r\n\r\n");
		UARTprintf(send_data);  UARTprintf("\r\n");
		printf("Voltage~%luV\n", sample);
		printf("Time = %lums\n", timeElapsed * 125 / 10 / 1000000 );

		LED_GreenOn();
		Timer1_StartWatch();
		char *custom = HTTP_Request(
			"tomcat.johnstarich.com", 80,
			"GET", "/%22temp%22:1000,",
			NULL,
			NULL
		);
		timeElapsed = Timer1_StopWatch();
		LED_GreenOff();
		UARTprintf("\r\n\r\n");
		UARTprintf(send_data);  UARTprintf("\r\n");
		UARTprintf("Custom temp: %s", custom);  UARTprintf("\r\n");
		printf("Custom temp: %s\n", Extract_Temperature(custom));
		printf("Time = %lums\n", timeElapsed * 125 / 10 / 1000000 );

    while(Board_Input()==0){}; // wait for touch
  }
}
Exemple #19
0
int main(void){int32_t retVal;  SlSecParams_t secParams;
  char *pConfig = NULL; INT32 ASize = 0; SlSockAddrIn_t  Addr;
	ADC0_InitSWTriggerSeq3_Ch9();         // allow time to finish activating
  initClk();        // PLL 50 MHz
	Output_On();
	UART_Init();      // Send data to PC, 115200 bps
  Timer1_Init();
  LED_Init();       // initialize LaunchPad I/O 
  UARTprintf("Weather App\n");
  retVal = configureSimpleLinkToDefaultState(pConfig); // set policies
  if(retVal < 0)Crash(4000000);
  retVal = sl_Start(0, pConfig, 0);
  if((retVal < 0) || (ROLE_STA != retVal) ) Crash(8000000);
  secParams.Key = PASSKEY;
  secParams.KeyLen = strlen(PASSKEY);
  secParams.Type = SEC_TYPE; // OPEN, WPA, or WEP
  sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
  while((0 == (g_Status&CONNECTED)) || (0 == (g_Status&IP_AQUIRED))){
    _SlNonOsMainLoopTask();
  }
  UARTprintf("Connected\n");
  while(1){
		int i = 0;
		while(i < 10){
			int sendc = 0;
			strcpy(HostName,"openweathermap.org");
			retVal = sl_NetAppDnsGetHostByName(HostName,
							 strlen(HostName),&DestinationIP, SL_AF_INET);
			if(retVal == 0){
				Addr.sin_family = SL_AF_INET;
				Addr.sin_port = sl_Htons(80);
				Addr.sin_addr.s_addr = sl_Htonl(DestinationIP);// IP to big endian 
				ASize = sizeof(SlSockAddrIn_t);
				SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
				if( SockID >= 0 ){
					retVal = sl_Connect(SockID, ( SlSockAddr_t *)&Addr, ASize);
				}
				if((SockID >= 0)&&(retVal >= 0)){
					strcpy(SendBuff,REQUEST); 
					sl_Send(SockID, SendBuff, strlen(SendBuff), 0);// Send the HTTP GET 
					sl_Recv(SockID, Recvbuff, MAX_RECV_BUFF_SIZE, 0);// Receive response 
					sl_Close(SockID);
					LED_GreenOn();
					UARTprintf("\r\n\r\n");
					UARTprintf(Recvbuff);  UARTprintf("\r\n");
				}
			}
			ST7735_OutUDec(sendc);
			ST7735_OutString("\n");
			i++;
		}
		
		//while(Board_Input()==0){}; // wait for touch
		LED_GreenOff();
		//Temp Part e
		getTemp(Recvbuff);
		ST7735_OutChar('T');
		ST7735_OutChar('e');
		ST7735_OutChar('m');
		ST7735_OutChar('p');
		ST7735_OutChar(' ');
		ST7735_OutChar('=');
		ST7735_OutChar(' ');
		for(int i = 0; i < 5; i++){
			ST7735_OutChar(myArray[i]);
		}
		ST7735_OutChar('\n');

		//ADC Part f
		ADC0_SAC_R = ADC_SAC_AVG_64X;    //enable 64 times average before obtaining result
    int voltage = ADC0_InSeq3();
		ST7735_OutString("Voltage~");
		ST7735_sDecOut3(voltage);
		
		char* voltageString;
		char voltageStringNum[5];
		sprintf(voltageStringNum, "%.1d.%.3d", voltage/1000, voltage%1000);
		//ST7735_OutString(voltageStringNum);
		
		char* sendString;
		char str1[173] = "GET /query?city=Austin%20Texas&id=Ty%20Winkler%20Jeremiah%20Bartlett&greet=Voltage%3D";
		strcat(str1, voltageStringNum);
		strcat(str1, "V&edxcode=8086 HTTP/1.1\r\nUser-Agent: Keil\r\nHost: embsysmooc.appspot.com\r\n\r\n");
		
		
		strcpy(HostName,"embsysmooc.appspot.com");
		retVal = sl_NetAppDnsGetHostByName(HostName,
						 strlen(HostName),&DestinationIP, SL_AF_INET);
		if(retVal == 0){
			Addr.sin_family = SL_AF_INET;
			Addr.sin_port = sl_Htons(80);
			Addr.sin_addr.s_addr = sl_Htonl(DestinationIP);// IP to big endian 
			ASize = sizeof(SlSockAddrIn_t);
			SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
			if( SockID >= 0 ){
				retVal = sl_Connect(SockID, ( SlSockAddr_t *)&Addr, ASize);
			}
			if((SockID >= 0)&&(retVal >= 0)){
				strcpy(SendBuff, str1);
				count = 0;					
				sl_Send(SockID, SendBuff, strlen(SendBuff), 0);// Send the HTTP GET 
				sl_Recv(SockID, Recvbuff, MAX_RECV_BUFF_SIZE, 0);// Receive response 
				sl_Close(SockID);
				LED_GreenOn();
				UARTprintf("\r\n\r\n");
				//ST7735_OutString(Recvbuff);  
				UARTprintf("\r\n");
			}
		}
		while(1);
	}
}
Exemple #20
0
int main(void) {
    int addScore, position, pauseSel;

    // Initializations
    PLL_Init();  			// Clock set at 80 MHz
    LCD_Init();
    Board_Init();
    Input_Init();
    DAC_Init();
    Random_Init(NVIC_ST_CURRENT_R);
    Timer2_Init(80000000); 	// time interrupt
    Timer1_Init(2000);		// sound interrupt
    EnableInterrupts();
    generateRandomTile();
    drawAllTiles();
    writeScore(0);
    writeHighscore(0);
    writeTime(0);
    displayHighestTile();

    while(1) {

        // draw arrow if ready
        if (arrowReady == 1) {
            // acknowledge flag
            arrowReady = 0;
            // draw arrow
            drawArrow();
        }

        // write time if ready
        if (timeReady == 1) {
            // acknowledge flag
            timeReady = 0;
            // write time
            writeTime(elapsedTime);
        }

        // Play mode and button1 is pushed
        if(Button1 && !pauseMode && !gameOver) {
            // Play sound
            playSound = 1;
            // shift and merge tiles towards arrow
            position = getSliderPosition();
            if (position == 1) {
                shiftLeft();
                addScore = mergeLeft();
                shiftLeft();
            }
            else if (position == 2) {
                shiftUp();
                addScore = mergeUp();
                shiftUp();
            }
            else if (position == 3) {
                shiftRight();
                addScore = mergeRight();
                shiftRight();
            }
            else {
                shiftDown();
                addScore = mergeDown();
                shiftDown();
            }

            eraseBoard();
            drawAllTiles();

            // update score
            score += addScore;
            addScore = 0;
            writeScore(score);
            displayHighestTile();

            // delay before adding new tile
            delay(200);

            // create new tile
            if (countEmptyTiles() != 0) {
                generateRandomTile();
            }
            drawAllTiles();

            // update highest tile image
            displayHighestTile();

            // check if game over
            if (checkGameOver() == 1) {
                gameOver = 1;
            }

            // unset flag
            Button1 = 0;
        }

        // button 2 is pause
        else if (Button2 && !gameOver && !pauseMode) {
            pauseMode = 1;
            pauseSel = 0;

            // disable arrow and timer
            NVIC_ST_CTRL_R = 0;
            TIMER2_CTL_R = 0x00000000;
            LCD_DrawFilledRect(prevX,prevY,20,20,BLACK);

            // draw pause mode screen
            drawPauseMode();

            // acknowledge button
            Button2 = 0;

            // wait until button is pushed
            while (pauseMode) {

                // Button 1 selects current pause selection button
                if (Button1) {

                    // acknowledge button
                    Button1 = 0;
                    Button2 = 0;
                    pauseMode = 0;

                    // if pause selection = "continue" (pauseSel = 0), continue with game
                    if (pauseSel == 0) {

                        // redraw screen
                        eraseBoard();
                        drawAllTiles();

                        // enable gameplay
                        NVIC_ST_CTRL_R = 0x07;
                        TIMER2_CTL_R = 0x00000001;
                    }

                    // if pause selection = "restart" (pauseSel = 0), end game
                    else if (pauseSel == 1) {
                        if (score > highscore) {
                            writeHighscore(score);
                        }
                        score = 0;
                        eraseScore();
                        writeScore(0);
                        clearBoard();
                        eraseBoard();
                        pauseMode = 0;
                        generateRandomTile();
                        drawAllTiles();
                        elapsedTime = 0;
                        eraseTime();
                        writeTime(0);
                        displayHighestTile();
                        NVIC_ST_CTRL_R = 0x07;
                        TIMER2_CTL_R = 0x00000001;
                    }
                }

                // Button 2 changes pause selection
                else if (Button2) {
                    Button2 = 0;
                    if (pauseSel == 0) {
                        pauseSel = 1;
                        LCD_DrawRect(144,112,58,16,BLACK);
                        LCD_DrawRect(222,112,51,16,WHITE);
                    }
                    else if (pauseSel == 1) {
                        pauseSel = 0;
                        LCD_DrawRect(222,112,51,16,BLACK);
                        LCD_DrawRect(144,112,58,16,WHITE);
                    }
                }
            }
        }

        // game over
        if (gameOver == 1) {
            NVIC_ST_CTRL_R = 0;
            TIMER2_CTL_R = 0x00000000;
            LCD_DrawFilledRect(156,38,100,20,BLACK);
            LCD_SetTextColor(255,255,240);
            LCD_Goto(30,5);
            printf("GAME OVER");
            while (Button1 == 0 && Button2 == 0) {}
            Button1 = 0;
            Button2 = 0;
            LCD_DrawFilledRect(prevX,prevY,20,20,BLACK);
            drawGameOver(score, elapsedTime);
            if (score > highscore) {
                writeHighscore(score);
                gameOverHighscore(score);
            }
            // wait til button is pushed
            while (Button1 == 0 && Button2 == 0) {}
            // acknowledge buttons
            Button1 = 0;
            Button2 = 0;
            // start new game
            score = 0;
            eraseScore();
            writeScore(0);
            clearBoard();
            eraseBoard();
            pauseMode = 0;
            generateRandomTile();
            drawAllTiles();
            elapsedTime = 0;
            eraseTime();
            writeTime(0);
            displayHighestTile();
            NVIC_ST_CTRL_R = 0x07;
            TIMER2_CTL_R = 0x00000001;

            // finish game over mode
            gameOver = 0;
        }
    }
}
Exemple #21
0
//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
//
// Main routine performs all configuration tasks, then loops forever sending
// and receiving SMBus data to the slave <SLAVE_ADDR>.
//
void main (void)
{
	unsigned char odoslat[4] = {0x00,0x00,0x12,0xFF};
   volatile unsigned char dat;         // Test counter
   unsigned char i;                    // Dummy variable counters

   PCA0MD &= ~0x40;                    // WDTE = 0 (watchdog timer enable bit)

   OSCICN |= 0x07;                     // Set internal oscillator to highest
                                       // setting of 24500000

   // If slave is holding SDA low because of an improper SMBus reset or error
   while(!SDA)
   {
      // Provide clock pulses to allow the slave to advance out
      // of its current state. This will allow it to release SDA.
      XBR1 = 0x40;                     // Enable Crossbar
      SCL = 0;                         // Drive the clock low
      for(i = 0; i < 255; i++);        // Hold the clock low
      SCL = 1;                         // Release the clock
      while(!SCL);                     // Wait for open-drain
                                       // clock output to rise
      for(i = 0; i < 10; i++);         // Hold the clock high
      XBR1 = 0x00;                     // Disable Crossbar
   }

   Port_Init ();                       // Initialize Crossbar and GPIO

   Timer1_Init ();                     // Configure Timer1 for use as SMBus
                                       // clock source

   Timer3_Init ();                     // Configure Timer3 for use with SMBus
                                       // low timeout detect

   SMBus_Init ();                      // Configure and enable SMBus

   EIE1 |= 0x01;                       // Enable the SMBus interrupt

   LED = 0;

   EA = 1;                             // Global interrupt enable

// TEST CODE-------------------------------------------------------------------

   dat = 0;                            // Output data counter
   NUM_ERRORS = 0;                     // Error counter
   while (1)
   {
      // SMBus Write Sequence
      if (dat < 4){
				SMB_DATA_OUT = odoslat[dat];              // Define next outgoing byte
      TARGET = SLAVE_ADDR; 				// Target the F3xx/Si8250 Slave for next
                                       // SMBus transfer
      SMB_Write();                     // Initiate SMBus write
			}
      // SMBus Read Sequence
     // TARGET = SLAVE_ADDR;             // Target the F3xx/Si8250 Slave for next
                                       // SMBus transfer
      //SMB_Read();

      // Check transfer data
      /*if(SMB_DATA_IN != SMB_DATA_OUT)  // Received data match transmit data?
      {
         NUM_ERRORS++;                 // Increment error counter if no match
      }*/

      // Indicate that an error has occurred (LED no longer lit)
      if (NUM_ERRORS > 0)
      {
         LED = 0;
      }
      else
      {
         LED = ~LED;
      }

      // Run to here to view the SMB_DATA_IN and SMB_DATA_OUT variables

      dat++;

      T0_Wait_ms (1);                  // Wait 1 ms until the next cycle
   }

// END TEST CODE---------------------------------------------------------------

}