Example #1
0
int main(){
  unsigned char statusAccel, accelerationReady;
  OSCConfiguration();     //Running at 40 MIPS
  IOConfiguration();      //EINT and SPI pins mapped
  SPIConfiguration();     //SPI1 configuration for accelerometer 
  INT1Configuration();    //INT1 configuration for accelerometer
  INT2Configuration();    //INT2 configuration for accelerometer
  TIMER1Configuration();  //TIMER1 configuration
  LCDInitialization();

  //SplashScreen();
  LCDClearScreen();
  ACCELInitialization();
  statusAccel = SPIRead(MCTL);

  average = 0;
  averageShow = 0;
  accelerationx = 0;
  lastAccelerationx = 0;  
  velocityx = 0;
  lastVelocityx = 0;

  while(1) {
    statusAccel = ACCELGetStatus();
    if (statusAccel & 0x01) {   //if data is ready in accelerometer
      xAxis = ACCELReadAxis(X_AXIS8);
      yAxis = ACCELReadAxis(Y_AXIS8);
      zAxis = ACCELReadAxis(Z_AXIS8);
      accelerationx += (float)xAxis;
      average++;
      if (average == 5){
        accelerationx /= average;
        accelerationx *= -1;
        average = 0;
        if (accelerationx > 3 || accelerationx < -3){
          accelerationx = (accelerationx* 19.6) / 127;
          accelerationx *= 0.08;
          velocityx = lastVelocityx + lastAccelerationx + ((accelerationx - lastAccelerationx) / 2);
          lastVelocityx = velocityx;
          lastAccelerationx = accelerationx;
          accelerationx = 0;
          if(velocityx < 0) velocityx = 0;
        }
      }
      if(averageShow++ == 7){
        averageShow = 0;
        ShowVelocity();
      }
    }
  }
  return 1;
}
Example #2
0
/*************************************************
  Function:		LCDInit
  Description:  
  Input:		
  Output:		
  Return:		
  Others:
*************************************************/
void LCDInit(void) 
{
	#if _LCD_LOG_
	mLcdline1Len = 0;
	#endif
	
	#if (_LCD_MODULE_ == _LCD_1602_)
	LCD1602Init();
	#endif

	#if (_LCD_MODULE_ == _LCD_12864B_)
	LCD12864Init();
	#endif
	
	#if (_LCD_MODULE_ != _LCD_NONE_)
	LCDClearScreen();
	LCDVersion();
	#endif
}
int main (void) {

  SPIDDR=(1<<SDA)|(1<<CLK)|(1<<CS)|(1<<RESET); //Port-Direction Setup


  //Init Uart and send OK
  UCR = (1<<RXEN)|(1<<TXEN);
  UBRR=(F_CPU / (BAUD_RATE * 16L) - 1);
  loop_until_bit_is_set(USR, UDRE);
  UDR = 'O';
  loop_until_bit_is_set(USR, UDRE);
  UDR = 'K';


  CS0
  SDA0
  CLK1

  RESET1
  RESET0
  RESET1

  CLK1
  SDA1
  CLK1

  waitms(10);

  //Software Reset
  sendCMD(0x01);

  //Sleep Out
  sendCMD(0x11);

  //Booster ON
  sendCMD(0x03);

  waitms(10);

  //Display On
  sendCMD(0x29);

  //Normal display mode
  sendCMD(0x13);

  //Display inversion on
  sendCMD(0x21);

  //Data order
  sendCMD(0xBA);

  //Memory data access control
  sendCMD(0x36);

  sendData(8);   //rgb + MirrorX
 //sendData(8|64);   //rgb + MirrorX
 // sendData(8|128);   //rgb + MirrorY

#ifdef MODE565
  sendCMD(0x3A);
  sendData(5);   //16-Bit per Pixel
#else
  sendCMD(0x3A);
  sendData(3);   //12-Bit per Pixel (default)
#endif


  //Set Constrast
  sendCMD(0x25);
  sendData(55);


LCDClearScreen();

 LCDSetRect(50,0,100,50,1,ORANGE);
 unsigned char i=30;
 
 while (i>5){
 LCDSetCircle(100,100,i,BLACK);
 i = i-5;
 }
 
 LCDPutChar('A', 20, 20, SMALL, RED, BLUE);
 LCDPutChar('N', 20, 26, SMALL, RED, BLUE);
 LCDPutChar('D', 20, 32, 0, RED, BLUE);
 LCDPutChar('-', 20, 38, SMALL, RED, BLUE);
 LCDPutChar('T', 20, 42, SMALL, RED, BLUE);
 LCDPutChar('E', 20, 48, 0, RED, BLUE);
 LCDPutChar('C', 20, 54, SMALL, RED, BLUE);
 LCDPutChar('H', 20, 60, SMALL, RED, BLUE);
 LCDPutChar('.', 20, 66, 0, RED, BLUE);
 LCDPutChar('P', 20, 72, SMALL, RED, BLUE);
 LCDPutChar('L', 20, 78, 0, RED, BLUE);
 //LCDPutChar("Hello World!", 20, 20, SMALL, WHITE, BLACK);
 
 LCDSetLine(30,120,70,90,GREEN);
 LCDSetLine(70,90,30,70,GREEN);
 LCDSetLine(30,70,30,120,GREEN);
}