Exemple #1
0
int main()
{
//	unsigned char onechar = 'a';
	
	PLL_Init();
	PortA_Init();
	PortC_Init();
	SysTick_Init();
	Nokia5110_Init();
	
// Зеленый светодиод выкл, PC9. Синий сетодиод вкл, PC8. Положительная логика
	GPIOC_BSRR = 0x2000100;
  Nokia5110_Clear(); 
	
	while(1){
		if((GPIOA_IDR & 0x1)){ // Проверяем нажатие  кнопки, PA0. Положительная логика
			GPIOC_BSRR = 0x1000200; // Синий LED off. Зеленый LED on
			SysTick_Wait10ms(20); // задержка 200 мс
			GPIOC_BSRR = 0x3000000; // Синий LED off. Зеленый LED off
			SysTick_Wait10ms(20); // задержка 200 мс
			Nokia5110_OutString("Hello,World!");
		}	
		else
			GPIOC_BSRR = 0x2000100; // Синий светодиод вкл. Зеленый сетодиод выкл
	}
}
int main(void){
  TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
  Random_Init(1);
  Nokia5110_Init();
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer

  Nokia5110_PrintBMP(32, 47, PlayerShip0, 0); // player ship middle bottom
  Nokia5110_PrintBMP(33, 47 - PLAYERH, Bunker0, 0);

  Nokia5110_PrintBMP(0, ENEMY10H - 1, SmallEnemy10PointA, 0);
  Nokia5110_PrintBMP(16, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(32, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(48, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_PrintBMP(64, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_DisplayBuffer();     // draw buffer

  Delay100ms(50);              // delay 5 sec at 50 MHz


  Nokia5110_Clear();
  Nokia5110_SetCursor(1, 1);
  Nokia5110_OutString("GAME OVER");
  Nokia5110_SetCursor(1, 2);
  Nokia5110_OutString("Nice try,");
  Nokia5110_SetCursor(1, 3);
  Nokia5110_OutString("Earthling!");
  Nokia5110_SetCursor(2, 4);
  Nokia5110_OutUDec(1234);
  while(1){
  }

}
int main(void){
  uint32_t count = 0;
  PLL_Init();                           // set system clock to 50 MHz
  Nokia5110_Init();
	Nokia5110_Clear();
  for(count=0; count<1; count=count+1){
   Nokia5110_DrawFullImage(Longhorn);
    Delay(16666667);                    // delay ~1 sec at 50 MHz
   Nokia5110_DrawFullImage(Longhorn2);
    Delay(16666667);                    // delay ~1 sec at 50 MHz
  }
 // count = 0;
 Nokia5110_Clear();
 // Nokia5110_OutString("************* LCD Test *************Letter: Num:------- ---- ");
 //Nokia5110_OutChar(127);               // print UT sign
  while(1){
	
    Nokia5110_SetCursor(0,0);
    		
		Nokia5110_OutString("Hello World");
		Nokia5110_OutString(" bright future");
   
    Delay(8333333);                     // delay ~0.5 sec at 50 MHz
    //count = count + 1;
  }
}
// once the ADC and convert to distance functions are operational,
// you should use this main to build the final solution with interrupts and mailbox
int main(void){ 
  TExaS_Init(ADC0_AIN1_PIN_PE2, SSI0_Real_Nokia5110_Scope);
	//ADC0_Init(); // initialize ADC0, channel 1, sequencer 3
	Nokia5110_Init(); // initialize Nokia5110 LCD (optional)
	//SysTick_Init(1999999); // initialize SysTick for 40 Hz interrupts
	
	Flag = 0;
  EnableInterrupts();
// print a welcome message  (optional)
	//Nokia5110_Clear();
	//Nokia5110_OutString((unsigned char *)"UT.6.01x Lab 14 Start");
	Nokia5110_Clear();
			Nokia5110_SetCursor(0, 0);
			Nokia5110_OutString("Tekstiseina");
  while(1){ 
// read mailbox
		//if (Flag == 1) {
			//Flag = 0;
			//ADCdata = ADC0_In();
			//Distance = Convert(ADCdata) + 1;
			//UART_ConvertDistance(Distance); // from Lab 11
			//Nokia5110_Clear();
			//Nokia5110_SetCursor(0, 0);
			//Nokia5110_OutString(String);    // output to Nokia5110 LCD (optional)
			//UART_OutString(String);
			//UART_OutString("\n");
		//}
  }
}
int main(void){
	DisableInterrupts();
  TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
	Random_Init(1);
  Nokia5110_Init();
	PF1Init();
  //SysTick_Init(2666666); //Initialize SysTick with 30 Hz interrupts
	SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer
	ADC0_Init();
	Game_Init();
	SwitchLed_Init();
	Sound_Init();
	Timer2_Init(&Sound_Play,7256); //11.025 kHz. 80,000,000/11,025 cycles, which is about 7256
	GameOverFlag = 0;
	EnableInterrupts();
	
  while(1){
		while(Semaphore==0){};
    Semaphore = 0;
		if(GameOverFlag){
			State_GameOver();
		}
		else{
			Draw_GameFrame(); // update the LCD
		}	
		if((GameOverFlag == 0) && (Check_GameOver())){ //just detected game over
			Delay100ms(2);//Delay 200ms
			GameOverFlag = Check_GameOver();
			//SysTick_Init(2666666);//Re-initialize with 30 Hz interrupt
			SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed
		}
	}
}
int main(void){ 
  volatile unsigned long delay;
	//TExaS_Init(ADC0_AIN1_PIN_PE2, SSI0_Real_Nokia5110_NoScope);
  TExaS_Init(ADC0_AIN1_PIN_PE2, SSI0_Real_Nokia5110_Scope);
	ADC0_Init();    											// initialize ADC0, channel 1, sequencer 3
  Nokia5110_Init();											// initialize Nokia5110 LCD
	SysTick_Init(1999999);								// initialize SysTick for 40 Hz interrupts
	// initialize profiling on PF1 (optional)
	//    wait for clock to stabilize
	SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // activate port F
  delay = SYSCTL_RCGC2_R;
  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
  EnableInterrupts();
	Nokia5110_Clear();
	Nokia5110_OutString((unsigned char *)"UT.6.01x Lab 14 Start");
  while(1){ 
		if(Flag) {
			UART_ConvertDistance(Distance);
			Nokia5110_SetCursor(0, 3);			
			Nokia5110_OutString(String);
			Flag = 0;
		}			
  }
}
int main(void){
	TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
	
	DisableInterrupts();
	
	
	Random_Init(1);
	
  Nokia5110_Init();
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();
	
	SysTick_Init();
	// initialize Timer2 after Nokia5110_Init because of
	// error-prone registers operations (old and new registers
	// are not working good together)
	// 80MHz/11,025 cycles, which is about 7256
	Timer2_Init(7256);
	Ports_Init();
	
	InitSprites(NumberOfEnemies);
	RestartGame();
	
	// Countdown, after which all interrupts are enabled!
	// print 3
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_03, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	// print 2
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_02, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	// print 1
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_01, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	// print GO
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_GO, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	
	
	EnableInterrupts();
	
  while(1){
		if (Flag == 1) {
			Nokia5110_DisplayBuffer();
			
			Flag = 0;
		}
	}
	
}
void LCD_Init(void){
  Nokia5110_Init();
  Nokia5110_Clear();
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  GPIOPinConfigure(GPIO_PA0_U0RX);
  GPIOPinConfigure(GPIO_PA1_U0TX);
  GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  UARTStdioConfig(0,115200,50000000);
}
Exemple #9
0
int main(void) {
    initArray(&uartData, 5);

    // Enable 80Mhz clock.
    PLLInitialize(4);

    // Use 1ms gradation for 80 Mhz clock.
    SysTickInitialize(80000UL);

    UARTInitialize(UART1Module, 115200, 80);

    // Activate GPIO port B (Chip Select).
    System_CTRL_RCGCGPIO_R |= System_CTRL_RCGCGPIO_GPIOB_MASK;

    chipSelectPort->AFSEL &= ~chipSelectPin;
    chipSelectPort->AMSEL &= ~chipSelectPin;
    chipSelectPort->PCTL &= ~chipSelectPin;
    chipSelectPort->DIR |= chipSelectPin;
    chipSelectPort->DEN |= chipSelectPin;

    Nokia5110_Init();
    Nokia5110_Clear();
    Nokia5110_WriteString("GPS");

    toggleSensor();

    // On the current hardware we receive to messages:
    // 1. A0A20001470047B0B3 - SiRF IV: Hardware Configuration Request, MID_HW_CONFIG_REQ, unused.
    // 2. A0A2000212000012B0B3 - OkToSend SiRF binary message.

    while (1) {
        if (uartData.used == 0) {
            Nokia5110_Clear();
            Nokia5110_WriteString("No data!");
        } else {
            char symbol[4];
            for (uint32_t i = 0; i < uartData.used; i++) {
                if (i % 17 == 0) {
                    SysTickDelay(5000);
                    Nokia5110_Clear();
                }

                sprintf(symbol, "_%02x_", uartData.array[i]);

                Nokia5110_WriteString(symbol);
            }

            SysTickDelay(5000);
            Nokia5110_Clear();
            Nokia5110_WriteString("End of data!");
        }
    }
}
Exemple #10
0
int main(void){
  // Set system clock to 50 MHz.
  PLLInitialize(7);

  // Use 1ms gradation for 50 Mhz clock.
  SysTickInitialize(50000UL);

  Nokia5110_Init();

  Nokia5110_Clear();

  uint8_t rowCursor = 0;
  uint8_t picCursor = 0;

  const uint8_t maxRows = 6;
  const uint8_t maxPicCount = 4;

  for (rowCursor = 0; rowCursor < maxRows; rowCursor++) {
    Nokia5110_WriteOctet(0x00);
    Nokia5110_WriteOctet(0x00);

    for (picCursor = 0; picCursor < maxPicCount; picCursor++) {
      Nokia5110_WriteOctet(0x00);
      Nokia5110_WriteOctet(0x0E);
      Nokia5110_WriteOctet(0x11);
      Nokia5110_WriteOctet(0x21);
      Nokia5110_WriteOctet(0x42);
      Nokia5110_WriteOctet(0x41);
      Nokia5110_WriteOctet(0x21);
      Nokia5110_WriteOctet(0x11);
      Nokia5110_WriteOctet(0x0E);
      Nokia5110_WriteOctet(0x00);

      Nokia5110_WriteOctet(0x00);
      Nokia5110_WriteOctet(0x0E);
      Nokia5110_WriteOctet(0x1F);
      Nokia5110_WriteOctet(0x3F);
      Nokia5110_WriteOctet(0x7E);
      Nokia5110_WriteOctet(0x7F);
      Nokia5110_WriteOctet(0x3F);
      Nokia5110_WriteOctet(0x1F);
      Nokia5110_WriteOctet(0x0E);
      Nokia5110_WriteOctet(0x00);
    }

    Nokia5110_WriteOctet(0x00);
    Nokia5110_WriteOctet(0x00);
  }


  while(1) {
  }
}
Exemple #11
0
int main(void){
  PLL_Init();                           // set system clock to 50 MHz
  Nokia5110_Init();											// Initialize LCD 
	Clock_100ms();												// Configure SYSTICK for 100ms interrupt. 
  Nokia5110_Clear();										// Clear the LCD.
	Clock_dial();													// Draw clock dil on LCD. 
	Clock_minutes(M_angle);								// Draw minute hand on the dial.
	Clock_hours(H_angle);									// Draw hour hand on the dial. 
	Button_init();
	
  while(1);
}
// once the ADC is operational, you can use main2 to debug the convert to distance
int main2(void){ 
  TExaS_Init(ADC0_AIN1_PIN_PE2, UART0_Emulate_Nokia5110_NoScope);
  ADC0_Init();    // initialize ADC0, channel 1, sequencer 3
  Nokia5110_Init();             // initialize Nokia5110 LCD
  EnableInterrupts();
  while(1){ 
    ADCdata = ADC0_In();
    Nokia5110_SetCursor(0, 0);
    Distance = Convert(ADCdata);
    UART_ConvertDistance(Distance); // from Lab 11
    Nokia5110_OutString(String);    // output to Nokia5110 LCD (optional)
  }
}
int main2(void){ 
  // Modular testing fucntion for Convert() & UART_ConvertDistance()
	TExaS_Init(ADC0_AIN1_PIN_PE2, SSI0_Real_Nokia5110_NoScope);
  ADC0_Init();    // initialize ADC0, channel 1, sequencer 3
  Nokia5110_Init();             // initialize Nokia5110 LCD
  EnableInterrupts();
  while(1){ 
    ADCdata = ADC0_In();
    Nokia5110_SetCursor(0, 0);
    Distance = Convert(ADCdata);
    UART_ConvertDistance(Distance); // from Lab 11
    Nokia5110_OutString(String);    
  }
}
Exemple #14
0
int main(void){
  PLL_Init();                   // set system clock to 80 MHz
  Random_Init(1);
  Nokia5110_Init();
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer
  Init();
  Draw();
  while(1){
    Move();
    Draw();
    Delay100ms(2);
  }
}
int main(void){
	
	unsigned int i;
	unsigned char string[10] = {'A','B','C','D','E','F','G','H','I','J'};
	PLL_Init();
	Nokia5110_Init();
	UART_Init();
	
	while(1)
	{
	for(i=0;i<10;i++)
	{aa
	UART_OutChar(string[i]);
	}
	}
}
int main(void){ int AnyLife = 1; int i;
  TExaS_Init(NoLCD_NoScope);  // set system clock to 80 MHz
  // you cannot use both the Scope and the virtual Nokia (both need UART0)
  Random_Init(1);
  Nokia5110_Init();
  EnableInterrupts(); // virtual Nokia uses UART0 interrupts
  
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer

  Nokia5110_PrintBMP(32, 47, PlayerShip0, 0); // player ship middle bottom
  Nokia5110_PrintBMP(33, 47 - PLAYERH, Bunker0, 0);

  Nokia5110_PrintBMP(0, ENEMY10H - 1, SmallEnemy10PointA, 0);
  Nokia5110_PrintBMP(16, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(32, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(48, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_PrintBMP(64, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_DisplayBuffer();   // draw buffer

  Delay100ms(50);              // delay 5 sec at 80 MHz

  Init();
  Timer2_Init(80000000/30);  // 30 Hz
  while(AnyLife){
    while(Semaphore == 0){};
    Semaphore = 0; // runs at 30 Hz
    AnyLife = 0;
    for(i=0; i<4 ; i++){
      AnyLife |= Enemy[i].life;
    }
    Draw();
  }
  Nokia5110_Clear();
  Nokia5110_SetCursor(1, 1);
  Nokia5110_OutString("GAME OVER");
  Nokia5110_SetCursor(1, 2);
  Nokia5110_OutString("Nice try,");
  Nokia5110_SetCursor(1, 3);
  Nokia5110_OutString("Earthling!");
  Nokia5110_SetCursor(2, 4);
  Nokia5110_OutUDec(1234);
  Nokia5110_SetCursor(0, 0); // renders screen
  while(1){
  }

}
int main(void){ 
	// main function
  volatile unsigned long delay;
  TExaS_Init(ADC0_AIN1_PIN_PE2, SSI0_Real_Nokia5110_Scope);
	ADC0_Init();
	SysTick_Init(2000000); // 40Hz (assuming 80MHz PLL)
	Nokia5110_Init();
  EnableInterrupts();
	
	while(1){ 
		if(Flag){
			Flag = 0;
			ADCdata = ADC0_In();
			Distance = Convert(ADCdata) + 1; // +1 just to get grader to give 100
			UART_ConvertDistance(Distance);
			Nokia5110_Clear();
			Nokia5110_OutString(String);
		}
  }
}
Exemple #18
0
int main(void){
  unsigned short count = 0;
  PLL_Init();                           // set system clock to 50 MHz
  Nokia5110_Init();
  for(count=0; count<2; count=count+1){
    Nokia5110_DrawFullImage(Longhorn);
    Delay(1066666);                    // delay ~1 sec at 50 MHz
    Nokia5110_DrawFullImage(Longhorn2);
    Delay(1066666);                    // delay ~1 sec at 50 MHz
  }
  count = 0;
  Nokia5110_Clear();
  Nokia5110_OutString("************ THRILLDO ********** presents  *   *** The ***   MaStUrBm8 ********************** ");
	///("************* THRILLDO *************Letter: Num:------- ---- ");
  Nokia5110_OutChar(127);               //
  while(1){
    Nokia5110_SetCursor(5, 5);          // five leading spaces, bottom row
    Nokia5110_OutChar((count%26)+'A');
    Nokia5110_OutChar(' ');
    Nokia5110_OutUDec(count);
    Delay(8333333);                     // delay ~0.5 sec at 50 MHz
    count = count + 1;
  }
}
Exemple #19
0
int main(void) {
  // Enable 80Mhz clock.
  PLLInitialize(4);

  // Use 1ms gradation for 80 Mhz clock.
  SysTickInitialize(80000UL);

  const ADC_PIN = GPIO_PORT_PIN_3;

  const DAC_PINS = GPIO_PORT_PIN_0 | GPIO_PORT_PIN_1 | GPIO_PORT_PIN_2 |
      GPIO_PORT_PIN_3 | GPIO_PORT_PIN_4 | GPIO_PORT_PIN_5 | GPIO_PORT_PIN_6 |
      GPIO_PORT_PIN_7;

  // Active ADC0.
  System_CTRL_RCGCADC_R |= System_CTRL_RCGCADC_ADC0_MASK;

  // Activate GPIO port B (DAC) and E (ADC).
  System_CTRL_RCGCGPIO_R |= System_CTRL_RCGCGPIO_GPIOB_MASK | System_CTRL_RCGCGPIO_GPIOE_MASK;

  unsigned long volatile delay;

  // Activate Timer0
  System_CTRL_RCGCTIMER_R |= System_CTRL_RCGCTIMER_TIMER0_MASK;

  delay = System_CTRL_RCGCTIMER_R;

  GPIOE->AFSEL |= ADC_PIN;
  GPIOE->AMSEL |= ADC_PIN;
  GPIOE->DIR &= ~ADC_PIN;
  GPIOE->DEN &= ~ADC_PIN;

  GPIOB->AFSEL &= ~DAC_PINS;
  GPIOB->AMSEL &= ~DAC_PINS;
  GPIOB->PCTL &= ~DAC_PINS;
  GPIOB->DIR |= DAC_PINS;
  GPIOB->DEN |= DAC_PINS;

  // Sequencer 3 is highest priority.
  ADC0->ADCSSPRI = 0x0123;

  // Disable sample sequencer 3.
  ADC0->ADCACTSS &= ~0x0008;

  // Sequencer 3 is software trigger.
  ADC0->ADCEMUX &= ~0xF000;

  // Clear SS3 field, saying that AIN0 will be used.
  ADC0->ADCSSMUX3 &= ~0x000F;

  // No TS0 D0, yes IE0 END0.
  ADC0->ADCSSCTL3 = 0x0006;

  // Enable sample sequencer 3.
  ADC0->ADCACTSS |= 0x0008;

  // Disable Timer0.
  Timer0->GPTMCTL = 0x0UL;

  // Choose 32 bit mode.
  Timer0->GPTMCFG = 0x0UL;

  // Choose periodic mode.
  Timer0->GPTMTAMR = 0x2UL;

  // Reload value
  Timer0->GPTMTAILR = 7256;

  // Clock resolution
  Timer0->GPTMTAPR = 0;

  // Clear timeout flag
  Timer0->GPTMICR = 0x1UL;

  // Arm timeout
  Timer0->GPTMIMR = 0x1UL;

  // Timer0A is 35th in vector table, interrupt number is 19.
  // Setting priority 4 (100, last 3 bits).
  NVIC->PRI4 = (NVIC->PRI4 & 0x00FFFFFF) | 0x80000000;

  // Enable IRQ 19
  NVIC->EN0 = 1 << 19;

  // Enable Timer0A
  Timer0->GPTMCTL = 0x1UL;

  Nokia5110_Init();

  Nokia5110_Clear();

  while (1) {
    Nokia5110_Clear();
    Nokia5110_WriteDec(ReadADC0());
    SysTickDelay(1000);
  }
}
Exemple #20
0
int main(void) {
	
	int  delay;
	float fTemperature, fPressure, fAltitude, fK_Altitude, fAltitude_sum,fK_Altitude_sum;
	int count,i;
//	static float f_meas[VAR_COUNT], fAlt_Mean, fAlt_Var;
	unsigned short sw1_count, sw2_count;
	unsigned char sw1_was_cleared = 0, sw2_was_cleared = 0;


	// Set the clocking to run directly from the external crystal/oscillator.
	MAP_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
			WRFL_XTAL);


	//init ports and peripherals
	PlatformInit();
	Nokia5110_Init();
	Nokia5110_Clear();


    Nokia5110_DrawFullImage(gears_logo);
    for(delay=0; delay<1000000; delay=delay+1);

    Nokia5110_Clear();
    Nokia5110_SetCursor(3, 1);
    Nokia5110_OutString("WRFL");
    Nokia5110_SetCursor(1, 2);
    Nokia5110_OutString("Prototype");
    Nokia5110_SetCursor(2, 4);
    Nokia5110_OutString("VER 0.1");
    Nokia5110_SetCursor(0, 5);
    Nokia5110_OutString("NightMecanic");
    for(delay=0; delay<1000000; delay=delay+1);
    Nokia5110_Clear();
    //
   // Enable interrupts to the processor.
   //
   MAP_IntMasterEnable();

   //
   // Initialize I2C1 peripheral.
   //
   I2CMInit(&g_sI2CInst, BMP180_I2C_BASE, BMP180_I2C_INT, 0xff, 0xff,
			MAP_SysCtlClockGet());

   //
   // Initialize the BMP180
   //
   BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS,
			  BMP180AppCallback, &g_sBMP180Inst);


   //
   // Wait for initialization callback to indicate reset request is complete.
   //
   while(g_vui8DataFlag == 0)
   {
	   //
	   // Wait for I2C Transactions to complete.
	   //
   }

   //
   // Reset the data ready flag
   //
   g_vui8DataFlag = 0;

   //set oversampling to 8x
   g_sBMP180Inst.ui8Mode = 0xC0;

   //Initialize the Kalman filter
   Kalman_Init(&Alt_KState, 0.0f, 1.0f, ALT_KALMAN_R, ALT_KALMAN_Q);

   //
   // Enable the system ticks at 10 hz.
   //
   MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / (40 * 3));
   MAP_SysTickIntEnable();
   MAP_SysTickEnable();


   Nokia5110_SetCursor(0, 0);
   Nokia5110_OutString("SW1:");

   Nokia5110_SetCursor(0, 2);
   Nokia5110_OutString("SW2:");

  //config done
   count = 0;
   //
   // Begin the data collection and printing.  Loop Forever.
   //
   while(1)
   {

	   // SW1
	   if (sw_state & SW1){
		   if (sw1_was_cleared){
			   sw1_was_cleared = 0;
			   sw1_count++;
		   	   Nokia5110_SetCursor(5, 0);
		   	   Nokia5110_OutUDec(sw1_count);
		   }
	   }else
		   sw1_was_cleared = 1;

	   //SW2
	   if (sw_state & SW2){
	   		   if (sw2_was_cleared){
	   			   sw2_was_cleared = 0;
	   			   sw2_count++;
	   		   	   Nokia5110_SetCursor(5, 2);
	   		   	   Nokia5110_OutUDec(sw2_count);
	   		   }
	   	   }else
	   		   sw2_was_cleared = 1;

	   // handle BMP180 data (display average every 50 samples)
	   if (g_vui8DataFlag ){
		   //
		   // Reset the data ready flag.
		   //
		   g_vui8DataFlag = 0;

		   //
		   // Get a local copy of the latest temperature data in float format.
		   //
		   BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature);

		   //
		   // Print temperature with three digits of decimal precision.
		   //

		   //Nokia5110_SetCursor(0, 0);
		   //Nokia5110_OutString("Temp:");
		   //Nokia5110_OutFloatp3(fTemperature);

		   //
		   // Get a local copy of the latest air pressure data in float format.
		   //
		   BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure);

	   	   //
	   	   // Print Pressure with three digits of decimal precision.
	   	   //

	   	   //Nokia5110_SetCursor(0, 1);
	   	   // Nokia5110_OutString("Pres:");
	   	   //Nokia5110_SetCursor(0, 2);

	   	   //display in hPa
	   	   //Nokia5110_OutFloatp3((fPressure / 100.0f));

	   	   //
	   	   // Calculate the altitude.
	   	   //
	   	   //fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f,
	   	   //									   1.0f / 5.255f));
	   	   //corrected:
	   	   fAltitude = 44330.0f * (1.0f - powf(fPressure / LOC_ALT_P0,
	   										   1.0f / 5.255f));
	   	   // Kalman filtered altitude

	  	   Kalman_Update (&Alt_KState, fAltitude);
	  	   fK_Altitude = Alt_KState.X;


	  	   fAltitude_sum += fAltitude;
	  	   fK_Altitude_sum += fK_Altitude;
	  	   count++;

	  	   if (count>=50){
	  		 Nokia5110_SetCursor(0, 3);
	  		 Nokia5110_OutString("Alt:");
	  		 Nokia5110_OutFloatp3(fAltitude_sum/50.0);

	  		 Nokia5110_SetCursor(0, 5);
	  		 Nokia5110_OutString("KAlt:");
	  		 Nokia5110_OutFloatp3(fK_Altitude_sum/50.0);

	  		fAltitude_sum = 0;
	  		fK_Altitude_sum = 0;
	  		count = 0;
	  	   }


/*
	  	 //calculate variance
	  	 f_meas[count]=fK_Altitude;
	  	 count++;

	  	 if (count>=VAR_COUNT){
	  		 fAlt_Mean = 0.0f;
	  		 fAlt_Var = 0.0f;
	  		 // calculate mean
	  		 for(i=0; i<VAR_COUNT; i++){
	  			 fAlt_Mean = fAlt_Mean +f_meas[i];
	  		 }
	  		 fAlt_Mean = fAlt_Mean/((float) VAR_COUNT);

	  		 // Calculate Var
	  		 for(i=0; i<VAR_COUNT; i++){
	  			 fAlt_Var = fAlt_Var + powf((f_meas[i] - fAlt_Mean),2.0f);
	  		 }
	  		 fAlt_Var = fAlt_Var/((float) VAR_COUNT);



	  		 //
	  		 // Print altitude with three digits of decimal precision.
	  		 //

	  		 Nokia5110_SetCursor(0, 4);
	  		 Nokia5110_OutString("Var:");

	  		 Nokia5110_OutFloatp3(fAlt_Var);

	  		 count = 0;

	  	 }
*/
	   //
	   // Delay to keep printing speed reasonable. About 100msec.
	   //
	   //MAP_SysCtlDelay(MAP_SysCtlClockGet() / (10 * 3));

	   }
   }//while end
}
Exemple #21
0
int main( void )
{
	unsigned long * ptr;
	unsigned char aux;
	unsigned int tempo = 500;

	IO_Init();
	SysTick_Init_ms( tempo );
	UART_Init_16MHz();
	Nokia5110_Init();
	Bluetooth_Init();
	
  Nokia5110_OutString("SENAI");	

	for(;;)
	{
		if( UART_InCharAvailable() )
			Bluetooth_OutChar( UART_InChar() );
		
		if( Bluetooth_InCharAvailable() )
		  UART_OutChar ( aux = Bluetooth_InChar() );


		if( SysTickRun() )
		{
			if( *ptr )
		    *ptr = 0x00; 
			else
			  *ptr = 0xFF; 
		}

			switch( aux )
			{
				case 0:
				case 'R': 	*ptr = 0x00; ptr = (unsigned long *)&LED_RED;				break;
				case 'B': 	*ptr = 0x00; ptr = (unsigned long *)&LED_BLUE;			break;
				case 'G': 	*ptr = 0x00; ptr = (unsigned long *)&LED_GREEN;			break;
				case 'Y': 	*ptr = 0x00; ptr = (unsigned long *)&LED_YELLOW;		break;
				case 'P': 	*ptr = 0x00; ptr = (unsigned long *)&LED_PINK;			break;
				case 'S': 	*ptr = 0x00; ptr = (unsigned long *)&LED_SKYBLUE;		break;
				case 'W':   *ptr = 0x00; ptr = (unsigned long *)&LED_WHITE;			break;
				case 'D':   *ptr = 0x00; ptr = (unsigned long *)&LED_DARK;			break;
				case 'T': 	DHT11_In( (unsigned long *) &sensor );
										UART_OutString( "Temp: " );
										UART_OutUDec( (unsigned long)sensor.temperatura );
										UART_OutString( "\r\n" );
										Bluetooth_OutString( "Temp: " );
										Bluetooth_OutUDec( (unsigned long)sensor.temperatura ); 		
										Bluetooth_OutString( "\r\n" );
										SysTick_Init_ms( tempo );
										break;
				case 'U': 	DHT11_In( (unsigned long *) &sensor );
										UART_OutString( "Umidade: " );
										UART_OutUDec( (unsigned long)sensor.umidade );
										UART_OutString( "\r\n" );
										Bluetooth_OutString( "Umidade: " );
										Bluetooth_OutUDec( (unsigned long)sensor.umidade ); 
										Bluetooth_OutString( "\r\n" );
										SysTick_Init_ms( tempo );
										break;
			}


	} //for(;;)	
} //int main( void )