コード例 #1
0
ファイル: device.cpp プロジェクト: Tilka/epsilon
void init() {
  initClocks();

  // Ensure right location of interrupt vectors
  // The bootloader leaves its own after flashing
  SYSCFG.MEMRMP()->setMEM_MODE(SYSCFG::MEMRMP::MemMode::MainFlashmemory);
  CM4.VTOR()->setVTOR((void*) 0);

  // Put all inputs as Analog Input, No pull-up nor pull-down
  // Except for the SWD port (PB3, PA13, PA14)
  GPIOA.MODER()->set(0xEBFFFFFF);
  GPIOA.PUPDR()->set(0x24000000);
  GPIOB.MODER()->set(0xFFFFFFBF);
  GPIOB.PUPDR()->set(0x00000000);
  for (int g=2; g<5; g++) {
    GPIO(g).MODER()->set(0xFFFFFFFF); // All to "Analog"
    GPIO(g).PUPDR()->set(0x00000000); // All to "None"
  }

#if EPSILON_DEVICE_BENCH
  bool consolePeerConnectedOnBoot = Ion::Console::Device::peerConnected();
#endif

  initPeripherals();

#if EPSILON_DEVICE_BENCH
  if (consolePeerConnectedOnBoot) {
    Ion::Device::Bench::run();
  }
#endif
}
コード例 #2
0
ファイル: main.c プロジェクト: NHLBI-MR/PRiME
void uProcConfig(void)
{
	initClocks();
	Setup1msTimer();

	__bis_SR_register(GIE);
}
コード例 #3
0
ファイル: multibuf.c プロジェクト: AndreMiras/EFM32-Library
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Chip errata */
  CHIP_Init();
  
  /* Select clock source  */
  initClocks();
  
  /* Initialize EBI configuration for external RAM and display controller */
  BSP_Init(BSP_INIT_DK_EBI);
  
  /* Initialize emWin Library. Will call initDisplayController to initialize Direct Drive. */
  GUI_Init();
  
  
  /* Initialization done, enter drawing loop. 
   * More emWin examples can be viewed by copy pasting into this file and 
   * uncommenting the following line calling MainTask() instead of drawingLoop()
   * emWin examples can be found under reptile/emwin/examples
   */
  
  drawingLoop();
  
  //MainTask();
  
  return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: pacoard/TFG_2016
void main(void)
{
    WDTCTL = WDTPW + WDTHOLD;		// Halt the dog

    // MSP430 USB requires a Vcore setting of at least 2.  2 is high enough
	// for 8MHz MCLK, below.
    PMM_setVCore(PMM_BASE, PMM_CORE_LEVEL_2);

    initPorts();           // Config all the GPIOS for low-power (output low)
    initClocks(8000000);   // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz
    bcUartInitLaunchpad();   // Init the back-channel UART for F5529 launchpad (9600 bps).
    //bcUartInitPGN();        // Init the back-channel UART for PGN (9600 bps).
    switchMessage = 0;
    __buttonsInit();
    __enable_interrupt();  // Enable interrupts globally

    while(1)
    {
       // Look for rcv'ed command on the backchannel UART. If any, process.
       rxByteCount = bcUartReadCommandTimeout(rx_buf_bcuart);
       if(rxByteCount != -1)
       {
         processReceivedFrame(rx_buf_bcuart, rxByteCount);
       }
       else // Timeout
       {
         // Do other things
//         tx_buf_bcuart[0] = 0xCC;
//         tx_buf_bcuart[1] = 0xDD;
//         bcUartSend(tx_buf_bcuart, 2);
       }
    }
}
コード例 #5
0
ファイル: main.c プロジェクト: phuonglab/CM3-Scheduler
int main()
{
	
	// Chip errata
	CHIP_Init();
	
	// ensure core frequency has been updated
	SystemCoreClockUpdate();
	
	// start clocks
	initClocks();
		
	// init LEDs
	LED_Init();
	
	// init scheduler
	SCHEDULER_Init();
	
	// enable timers
	enableTimers();
	
	// enable interrupts
	enableInterrupts();
	
	// init tasks
	SCHEDULER_TaskInit(&radio_task, radio_task_entrypoint);
	
	// run
	SCHEDULER_Run();
	
}
コード例 #6
0
ファイル: main.c プロジェクト: DoctorKey/msp430_workshop
//***** Functions *************************************************************
void main (void)
{
    // Stop watchdog timer
//    WDT_A_hold( WDT_A_BASE );

    // Set pin P1.0 to output direction and initialize low
//    GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 );
//    GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 );
     initGPIO();
     initClocks();

    while(1) {
        // Turn on LED
        GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 );

        // Wait about a second
        __delay_cycles( ONE_SECOND );

        // Turn off LED
        GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 );

        // Wait another second
        __delay_cycles( ONE_SECOND );
    }
}
コード例 #7
0
ファイル: main.c プロジェクト: ngg123/barndoor
int main() {
  int driverPointer = 0;
  // Stop the watchdog
  WDTCTL = WDTPW |  WDTHOLD;
  // enable output for pins connected to LEDs on Launchpad
  // init the peripherals
  initClocks();	
  initTimer();

  P1DIR |= BIT0 | BIT1 | BIT2 | BIT4;
  P1OUT |= BIT0 | BIT1 | BIT2 | BIT4;
  P1REN &= ~(BIT0|BIT1|BIT2|BIT4);

  // enable interrupts
  __bis_status_register(GIE);
  

  while(1) {
    __nop();
    __bis_status_register(CPUOFF);
    if (P1IN & BIT3){
      driverPointer +=1;
      TACCR0 = SIDEREAL_RATE;
    } else {
      driverPointer -= 1;
      TACCR0 = 300;
    }
    driverPointer = driverPointer & ((sizeof DRIVER_TABLE / sizeof *DRIVER_TABLE)-1);
    
    setDriver(DRIVER_TABLE[driverPointer]);
  }
}
コード例 #8
0
ファイル: main.c プロジェクト: elpurofresh/codeComposer
void main(void) {

	initClocks();
	initUARTSdCard();
	initUARTBot();

	initLEDs();
	//initLEDWait();	// Sleep for 5 sec: 5*8MHz.
	initUartBuffer();

	_EINT();

	/*initCorrect = checkSDCardStatus(); // Enables/Disables the main while loop

	if (initCorrect) {
		StartUpSequence();
	} else {
		blinkLED8(1);
	}*/
	initCorrect = 1;

	OperationMode = Listening;

	P1OUT &= ~BIT4;                           //
	P1IES &= ~BIT4;                           // P1.4 Lo/Hi edge
	P1IE |= BIT4;                              // P1.4 interrupt enabled
	P1IFG &= ~BIT4;                           // P1.4 IFG cleared


	while(initCorrect){

		switch (OperationMode) {

		case Broadcasting:
			broadCast();
			OperationMode = Listening;
			break;

		case Counting:
			break;

		case Listening:
			__bis_SR_register(LPM3_bits + GIE);     // Enter LPM4 w/interrupt
			PJOUT ^= BIT3;                          // P1.0 = toggle
			//P1IE |= BIT4;                         // P1.4 interrupt enabled
			timeKeeper();
			PJOUT ^= BIT3;
			break;

		case Saving:
			savingToSdCard();
			break;

		default:
			OperationMode = Listening;
			break;
		}
	}
}
コード例 #9
0
ファイル: ClockEventSender.cpp プロジェクト: hcmlab/mobileSSI
void ClockEventSender::enter() {

	initClocks();
	_next = 0;
	_event.time = 0;
	_event.dur = 0;
	_init = true;
}
コード例 #10
0
ファイル: myTimer.c プロジェクト: ACPLMaverick/marjan
void myTimerExec(void)
{
	initClocks();
	initTimer1();

	T1TCR = 0x01;

	for(;;);
}
コード例 #11
0
ファイル: work_cycle.cpp プロジェクト: TheDZhon/hc001
void wcycle_init ()
{
	initPins ();
	initClocks ();
	initFlash ();
	initUART ();
	initPWM ();
	initDHT ();

	wcycle_pwm_ctl (readFlash());
}
コード例 #12
0
ファイル: uart.c プロジェクト: larytet/cfa_735_simple
/* Initialize this UARTs Pins and clocks without enabling the port */
int UARTinit()
{
    /* Set up Rings */
    InitRing(&tx_ring);
    InitRing(&rx_ring);

    /* Set up clocks */
    initClocks();

    /* Set up interrupts */
    initInterruptController();

    return UARTRetOK;
}
コード例 #13
0
ファイル: wiring.c プロジェクト: AlexJaeger/Energia
void init()
{
	disableWatchDog();

	initClocks();

	//Copy RAM functions
	memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);

	//Setup flash waitstates
	initFlash();

	initPie();

	analogInit();

	EINT;
}
コード例 #14
0
ファイル: uart.c プロジェクト: sdeodhar/ARM
int main(void)
{
	char msg[] = { 'H','e','l','l','o',' ','t','h','i','s',' ','a','','t','e','s','t','\0' }; 
	int c=0; // count
	initClocks(); // Set CCLK=60Mhz and PCLK=60Mhz 
	initUART0();
	
	for(;;)		
	{
		while( msg[c]!='\0' )
		{
			U0Write(msg[c]);
			c++;
		}
		U0Write(NEW_LINE); 
		c=0; // reset count		
	}
	return 0;
	
}
コード例 #15
0
ファイル: main.c プロジェクト: DoctorKey/msp430_workshop
//*****************************************************************************
// Main
//*****************************************************************************
void main (void)
{
    // Stop watchdog timer
    WDT_A_hold( WDT_A_BASE );

    // Initialize GPIO
    initGPIO();

    // Initialize clocks
    initClocks();

    // Initialize timers
    initTimers();

    __bis_SR_register( GIE );         // Enable interrupts globally

    while(1) {
        __no_operation();             // Placeholder for while loop (not required)
    }
}
コード例 #16
0
ファイル: time.cpp プロジェクト: apvanzanten/SacrosonicMk3
    // calls the clocks initialisation function and then initializes and starts TIM2 running at 84mhz with a period of 0xffffffff (roughly 51 seconds)
    void init(){
        if(gIsInitialized) {
            return; // already initialized, do nothing.
        }

        initClocks();

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
        TIM_TimeBaseInitTypeDef initStruct;
        initStruct.TIM_Prescaler = 1 - 1; // prescaler 1:1 -> 84MHz
        initStruct.TIM_CounterMode = TIM_CounterMode_Up;
        initStruct.TIM_ClockDivision = TIM_CKD_DIV1; // clock division 1:1 -> 84MHz

        // - 1: timer counts up to (and incl.) the TIM*->ARR and then resets, thereby the period is actually (TIM*->ARR)+1
        initStruct.TIM_Period = (uint32_t)(TMR_PERIOD - 1);

        TIM_TimeBaseInit(TIM2,&initStruct);
        TIM_Cmd(TIM2,ENABLE);

        gIsInitialized = true;
    }
コード例 #17
0
ファイル: spo2h.c プロジェクト: XiaodongJia/jiaoxuetaojian
void SPO2H(int transmit_mode)
{
	USE_LCD();
	SpO2_lcd();
    int_adc();

    Init_UART2();
    UCA0IE |= UCRXIE;

    //PMM_setVCore(PMM_BASE, PMM_CORE_LEVEL_2);
    initClocks(20000000);   // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz
    delay_2();
    delay_2();
//    USB_setup(TRUE,TRUE);
    BUTTON_S4=0;
    while(!(buttonsPressed & BUTTON_S4))
    {
        Init_UART2();
        UCA0IE |= UCRXIE;
        _EINT();
       // delay_2();
      //  delay_2();
        ad();
        if(BUTTON_S4==0){
        on_ired();
        wave(1);    //显示红光
      /*  for(i=0;i<480;i++){
            results[i+480]=results[i];
        }*/
        NONUSE_LCD();
        save();  //      前0-480为红外 1000-1480为
       // delay_2();
  //      delay_2();
        ad();
        if(BUTTON_S4==0){
        on_red();
        wave(0);    //显示红外
       unsigned int count=0;   //ired
       unsigned int count1=0;  //red
       unsigned int count_spa=0;
       unsigned int count1_spa=0;
       //调试时 使用

       int red_hr=0;
       int hr = 0; //心率
       unsigned int j = 0, j1 = 0;


       for(i = 9; i < max-10 ;i++)  //ired
       {
           if(results[i]>=results[i+1]&&results[i]>=results[i+2]&&results[i]>=results[i+3]&&results[i]>=results[i-1]&&results[i]>=results[i-2]&&results[i]>=results[i-3]&&j<4&&
                   results[i]>=results[i+4]&&results[i]>=results[i+5]&&results[i]>=results[i+6]&&results[i]>=results[i-4]&&results[i]>=results[i-5]&&results[i]>=results[i-6]&&
                   results[i]>=results[i+7]&&results[i]>=results[i+8]&&results[i]>=results[i+9]&&results[i]>=results[i-7]&&results[i]>=results[i-8]&&results[i]>=results[i-9])
           {
               r_locate[count] = i;
               count++;
               if(count>=10)break;
               i = i+40;
           }

       }

       for(i = 9+480; i < max-10+480 ;i++)  //red
       {
           if(results[i]>=results[i+1]&&results[i]>=results[i+2]&&results[i]>=results[i+3]&&results[i]>=results[i-1]&&results[i]>=results[i-2]&&results[i]>=results[i-3]&&j1<4&&
                   results[i]>=results[i+4]&&results[i]>=results[i+5]&&results[i]>=results[i+6]&&results[i]>=results[i-4]&&results[i]>=results[i-5]&&results[i]>=results[i-6]&&
                   results[i]>=results[i+7]&&results[i]>=results[i+8]&&results[i]>=results[i+9]&&results[i]>=results[i-7]&&results[i]>=results[i-8]&&results[i]>=results[i-9])
           {
               r1_locate[count1] = i;
               count1++;
               if(count1>=10)break;
               i=i+40;
           }
       }

       /*计算心率 其实最后一个峰值坐标减去第一个 再除以个数就可以了哦*/
       count_spa = count - 1;
       count1_spa = count1 - 1;

      hr = (r_locate[count_spa]-r_locate[0])/count_spa;
      hr=(1.0/(float)(hr*0.01))*60;

      red_hr = (r1_locate[count1_spa]-r1_locate[0])/count1_spa;
      red_hr=(1.0/(float)(red_hr*0.01))*60;  //


      /*直流算平均值*/
      red_dc = 0.0;
      ired_dc = 0.0;
      length_idc = (float)(r_locate[count_spa]-r_locate[count_spa -2]);    //ired
      length_dc = (float)(r1_locate[count1_spa] - r1_locate[count1_spa -2]);
      for(i = r1_locate[count1_spa -2] ; i <r1_locate[count1_spa];i++)    //最后的位置是采样到最后一个峰峰值的坐标
      {
          red_dc += (float)results1[i]/length_dc;
      }
      for(i = r_locate[count_spa -2] ; i <r_locate[count_spa];i++)    //最后的位置是采样到最后一个峰峰值的坐标
      {
          ired_dc += (float)results1[i]/length_idc;
      }

      /*最小值及交流峰峰值 最后2个周期才稳定 可以用最后2个周期算峰峰值*/
      /*同时 红光用前一个峰值减去谷值 红外用后一个峰值减去谷值 去基线漂移*/
       red_min = results[1+480];//(float)red[0];
       ired_min = results[1];//(float)results[0];  避免第一个数采得不准
       ired_ac = 0;
       red_ac = 0;

       for(i =( count_spa -2); i <count_spa ;i++)  //ired
       {
           for(j=r_locate[i]; j < r_locate[i+1] ;j++)
           {
               if(results[j]<ired_min){ired_min=results[j];}
           }
           ired_ac += results[r_locate[i+1]] - ired_min;
           nr_locate[i]=ired_min;
           ired_min = results[1]; //更新初值
       }
       ired_ac = ired_ac/2;

       for(i = (count1_spa -2); i <count1_spa ;i++)  //red
       {
           for(j=r1_locate[i]; j < r1_locate[i+1] ;j++)
           {
               if(results[j]<red_min){red_min=results[j];}
           }
           red_ac += results[r1_locate[i]] - red_min;
           nr1_locate[i] = red_min;
           red_min = results[481];
       }
       red_ac = red_ac/2;


       /*计算血氧含量*/
       Q1 = (float)(red_ac/red_dc);
       Q2 = (float)ired_ac/(float)ired_dc ;
       Q = Q1/Q2 ;
       sao2 = (-4.1768)*Q + 100.9352 + 0.5;

       if(abs(hr-red_hr)>=10)                  //两次采样的心率值相差不大的情况下才更新Q
       {
           Q = pre_Q;
       }

       /*显示*/
       USE_LCD();
       SPILCD_Clear_Lim(212,260,18,52,WHITE); //371 355
       SPILCD_Clear_Lim(348,396,18,52,WHITE);
       unsigned int temp1,temp10,temp100;
       long temp_final1;
       long temp_final2;

       temp1=hr%10;             //计算心率个位
       temp10=(hr%100-temp1)/10;    //计算心率十位
       temp100=(hr-temp10*10-temp1)/100;    //计算心率百位
       temp_final1=(long)(temp1+temp10*10+temp100*100);
       if(temp100>0)    DRAW_NUM(244,20,temp100,BLUE);  //显示心率百位
       DRAW_NUM(228,18,temp10,BLUE);         //显示心率十位
       DRAW_NUM(212,18,temp1,BLUE);       //显示心率个位

       sao2=99;
       temp1=sao2%10;                  //计算个位
       temp10=(sao2%100-temp1)/10;    //计算十位
       temp100=(sao2-temp10*10-temp1)/100;    //计算百位
       temp_final2=(long)(temp1+temp10*10+temp100*100);
       if(temp100>0)    DRAW_NUM(380,18,temp100,BLUE);  //显示心率百位
       DRAW_NUM(364,18,temp10,BLUE);  //显示十位
       DRAW_NUM(348,18,temp1,BLUE);    //显示个位
       NONUSE_LCD();
       i = 0;

       pre_Q = Q;   //记录这次显示的Q

  /*     char start[7]={'S','T','A','R','T','S','O'};
       long a;
       char b[5];
       char c[3];
       char d[3];
       ltoa(temp_final1,b);
       if(temp_final1>=0&&temp_final1<=9)
       {
       c[0]='0';
       c[1]='0';
       c[2]=b[0];
       }
       if(temp_final1>=10&&temp_final1<=99)
       {
       c[0]='0';
       c[1]=b[0];
       c[2]=b[1];
       }
       if(temp_final1>=100&&temp_final1<=999)
       {
       c[0]=b[0];
       c[1]=b[1];
       c[2]=b[2];
       }

       ltoa(temp_final2,b);
       if(temp_final2>=0&&temp_final2<=9)
       {
       d[0]='0';
       d[1]='0';
       d[2]=b[0];
       }
       if(temp_final2>=10&&temp_final2<=99)
       {
       d[0]='0';
       d[1]=b[0];
       d[2]=b[1];
       }
       if(temp_final2>=100&&temp_final2<=999)
       {
       d[0]=b[0];
       d[1]=b[1];
       d[2]=b[2];
       }

       char end[3]={'E','N','D'};
       j=0;
       for(j=0;j<960;j++)        //采样数据除以40转化成两位,便于传送
           {
           results[j]=results[j]/40;
           }*/
       int i;
       for(i=959;i>=0;i--)
       {
           results[i+10]=results[i]>>5;
       }
       results[0]='S';
       results[1]='T';
       results[2]='A';
       results[3]='R';
       results[4]='T';
       results[5]='S';
       results[6]='O';
       if(hr>=127){
       results[7]=0x7F;
       results[8]=(char)(hr-127);}
       else{
     	  results[7]=(char)(hr);
     	  results[8]=0;
       }
       results[9]=sao2;
       results[970]='A';
       results[971]='A';
       results[972]='A';
       results[973]='A';
       results[974]='A';
//       results[974]=0x7F;
       results[975]='E';
       results[976]='N';
       results[977]='D';
//       CRCresult=0;
//       for(i=9;i<969;i++)
//       {
//           results[i]=results[i]>>5;
//           CRCtmp = CRCresult%256;
//           CRCindex = CRCtmp^results[i];
//           CRCtmp = CRCresult/256;   //除以256
//           CRCresult = CRCtmp;
//           CRCresult = CRCresult^CRC_TA[CRCindex];
//       }
//       long a;
//       char b[5];
//       a=CRCresult;
//       ltoa(a,b);
//       results[969]=b[0];
//       results[970]=b[1];
//       results[971]=b[2];
//       results[972]=b[3];
//       results[973]=b[4];
//       results[974]='E';
//       results[975]='N';
//       results[976]='D';



       if(transmit_mode==1){
           bcUartInit();
           bcUartSend_char(results,978);//buf_bcuartToUsb
       }


       if(transmit_mode==2){
           hidSendDataInBackground(results,1956, HID0_INTFNUM,10000);
       }


        if(transmit_mode==3){
      	 int i;
      	 for(i=0;i<978;i++)
      	 {
               UCA0TXBUF = results[i];

               while(!(UCTXIFG==(UCTXIFG & UCA0IFG))&&((UCA0STAT & UCBUSY)==UCBUSY));

               int a,k;
               for(a=0;a<10;a++)
               {
                    for(k=0;k<80;k++);
               }
      	 }
       }

	   BUTTON_S4=0;
	   buttonsPressed=0;
	   NONUSE_LCD();
        }
        }
コード例 #18
0
ファイル: main.c プロジェクト: XiaodongJia/jiaoxuetaojian
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// 关闭看门狗

    __enable_interrupt();       //使能全局中断

    init_key();                 //初始化按键的管脚设置

    init_LCD_hardware();        //初始化LCD液晶显示屏的管脚设置

    SetVCore(3);                //设VCore为最大,提高Vcore电压到最高级,以满足倍频需求该函数位于HAL_PMM.H中

    initClocks(20000000);       //初始化时钟20MHz

    init_SPI();                 //初始化SPI

    ILI9325_CMO24_Initial();
    SPILCD_SetWindow(0,480-1,0,320-1);
    SPILCD_Clear(WHITE);

	P6DIR |= BIT3+BIT4;
    Show_splash();

    int ai;
	for(ai=0;ai<200;ai++)
	{
		myDelay();
	}

    SPILCD_Clear(WHITE);
    Show_MenuTheme();
    Show_MenuMode(1);
    Show_Select();



    Init_UART2();
    UCA0IE |= UCRXIE;

    int as1=1;

    buttonsPressed=0;

    USB_setup(TRUE,TRUE);

    while (!buttonsPressed)
    {
    	buttonsPressed = 0;

    	for(ai=0;ai<30;ai++)
    	{
    		myDelay();
    	}

    	if (buttonsPressed & BUTTON_S3)
        {
        	Show_ButtonS3();
        	if(as1==4){
        		as1=1;
        		Show_MenuMode(as1);
        	}else{
        		if(as1==1){
        			as1=2;
        		    Show_MenuMode(as1);
        		}else{
        			if(as1==2){
        				as1=3;
        		        Show_MenuMode(as1);
        			}else{
        				if(as1==3){
        					as1=4;
        		            Show_MenuMode(as1);
        				}
        			}
        		}
        	}
        	buttonsPressed=0;
        	Show_Select();
        }

        if (buttonsPressed & BUTTON_S2)
        {
        	Show_ButtonS2();
        	if(as1==2){
        		as1=1;
        		Show_MenuMode(as1);
        	}else{
        		if(as1==3){
        			as1=2;
        		    Show_MenuMode(as1);
        		}else{
        			if(as1==4){
        				as1=3;
        		        Show_MenuMode(as1);
        			}else{
        				if(as1==1){
        					as1=4;
        					Show_MenuMode(as1);
        				}
        			}
        		}
        	}
        	buttonsPressed=0;
        	Show_Select();
        }

        if (buttonsPressed & BUTTON_S1)
        {
        	Init_UART2();
        	Show_ButtonS1();
        	if(as1==1){
        	    menu_select=1;
        	}
        	if(as1==2){
        	    menu_select=2;
        	}
        	if(as1==3){
        	    menu_select=3;
        	}
        	if(as1==4){
        	    menu_select=4;
        	}

        	chanle_menu();

        	as1=1;
        	buttonsPressed=0;
        	SPILCD_Clear(WHITE);

            Show_MenuTheme();
            Show_MenuMode(1);
            Show_Select();
        }

        if (buttonsPressed & BUTTON_S4){
        	Show_ButtonS4();
        	Show_MenuMode(as1);
        	buttonsPressed=0;
        	Show_Select();
        }
    }
}
コード例 #19
0
void BP(int transmit_mode){
	USE_LCD();

	_DINT();
	buttonsPressed=0;

    Init_UART2();
    UCA0IE |= UCRXIE;



	int ad_f ;
	ad_f = 0;
    SPILCD_Clear(WHITE);
    drawbpletter();   //draw 'BLOOD PRESURE'

//    PMM_setVCore(PMM_BASE, PMM_CORE_LEVEL_3);
    initClocks(20000000);   // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz

    int_adc12();
    //bcUartInit();          // Init the back-channel UART
//    USB_setup(TRUE,TRUE);  // Init USB; if a USB host (PC) is present, connect

    n=0;xaxis=0;flag=0;xx=0;mm=0;t1=0;pkn=0;section=0;x=0;
//   	int_adc12();//采样设置
    ADC12CTL0 |= ADC12SC;//启动采样
    ADC12CTL0 |= ADC12ENC+ADC12ON;
    ad_f = 0;
   	_EINT();//允许中断

  int_aerate();  //启动气阀自动充放气
   	 	//section=1;
  //int_adc12();
  while(n<500);
 // TA2CCR2 = 600;
  while(n<1000);
//  TA2CCR2 = 350;
  while(n<1400){           //等待采1500个样点
       // _EINT();
//__bis_SR_register(LPM0_bits + GIE); //低功耗,使能全局中断
 		_NOP();

 	}
 //	TA2CCR2 = 200;
 	while(n<1500);
 	_DINT();
 	ADC12IE &= ~0x02;
 	ADC12CTL0 &=~ ADC12ENC;      //停止转换
 	TA2CCR2 =0;
 	smooth();       //滤波
 	int_findpk();//找到脉搏波峰峰值
 	findBP();  //计算并显示血压


 	_EINT();


//    long a;
//    char b[5];
//    char c[3];
//    char cc[3];
/*    ltoa(temp_final1,b);
    if(temp_final1>=0&&temp_final1<=9)
    {
    c[0]='0';
    c[1]='0';
    c[2]=b[0];
    }
    if(temp_final1>=10&&temp_final1<=99)
    {
    c[0]='0';
    c[1]=b[0];
    c[2]=b[1];
    }
    if(temp_final1>=100&&temp_final1<=999)
    {
    c[0]=b[0];
    c[1]=b[1];
    c[2]=b[2];
    }

    ltoa(temp_final2,b);
    if(temp_final2>=0&&temp_final2<=9)
    {
    cc[0]='0';
    cc[1]='0';
    cc[2]=b[0];
    }
    if(temp_final2>=10&&temp_final2<=99)
    {
    cc[0]='0';
    cc[1]=b[0];
    cc[2]=b[1];
    }
    if(temp_final2>=100&&temp_final2<=999)
    {
    cc[0]=b[0];
    cc[1]=b[1];
    cc[2]=b[2];
    }
*/
    //char end[3]={'E','N','D'};
    int i;

      /*
       */
//    CRCresult=0;
           for(i=1508;i>=9;i--){
               results1[i]=results1[i-9]>>5;
           }
//           for(i=9;i<1509;i++)
//           {
//               CRCtmp = CRCresult%256;
//               CRCindex = CRCtmp^results1[i];
//               CRCtmp = CRCresult/256;   //除以256
//               CRCresult = CRCtmp;
//               CRCresult = CRCresult^CRC_TA[CRCindex];
//           }
//           a=CRCresult;
//           ltoa(a,b);
           results1[0]='S';
           results1[1]='T';
           results1[2]='A';
           results1[3]='R';
           results1[4]='T';
           results1[5]='B';
           results1[6]='P';
           if(sh>=127){
           results1[7]=0x7F;
           results1[8]=(char)(sh-127);}
           else{
         	  results1[7]=(char)(sh);
         	  results1[8]=0;
           }
           if(re>=127){
           results1[9]=0x7F;
           results1[10]=(char)(re-127);}
           else{
         	  results1[9]=(char)(re);
         	  results1[10]=0;
           }
           results1[1511]='A';
           results1[1512]='A';
           results1[1513]='A';
           results1[1514]='A';
           results1[1515]='A';
           results1[1516]='E';
           results1[1517]='N';
           results1[1518]='D';

    if(transmit_mode==1){
    	bcUartInit();
        bcUartSend_char(results1,1519);//buf_bcuartToUsb
    }


    if(transmit_mode==2){
           hidSendDataInBackground(results1,3038, HID0_INTFNUM,10000);
    }


    if(transmit_mode==3){
    	Init_UART2();

        	 int i;
        	 for(i=0;i<1519;i++)
        	 {
                 UCA0TXBUF = results1[i];

                 while(!(UCTXIFG==(UCTXIFG & UCA0IFG))&&((UCA0STAT & UCBUSY)==UCBUSY));

                 int a,k;
                 for(a=0;a<10;a++)
                 {
                      for(k=0;k<80;k++);
                 }
        	 }
         }

    __no_operation();                       // For debugger

    _EINT();

    Init_UART2();
    UCA0IE |= UCRXIE;

    buttonsPressed=0;
    BUTTON_S4=0;
    while(!(buttonsPressed & BUTTON_S4));
 /***************UART**************************/
 //	 rxByteCount = 1500;//bcUartReceiveBytesInBuffer(buf_bcuartToUsb);
 	// bcUartSend(results1,rxByteCount);//buf_bcuartToUsb
 	 //bcUartSend(results,rxByteCount);
/***************USB**************************/
 /*	 for(i=0;i<1500;i++){
 		 convertTwoDigBinToASCII(results1, str1);
 		 __delay_cycles(110000);
 		 hidSendDataInBackground(str1,5, HID0_INTFNUM,0);
 	 }
 	for(i=0;i<1500;i++){
 	 		 convertTwoDigBinToASCII(results, str1);
 	 		 __delay_cycles(110000);
 	 		 hidSendDataInBackground(str1,5, HID0_INTFNUM,0);
 	 	 }*/
/***************BlueTooth**************************//*
 	long a;
 	char b[20];
 	char c[2];
 	int bb;
 	Init_UART1();
 	for(i=0;i<1500;i++){
 		a=(long)results1[i]/40;
 		if(a>=0&&a<=9){
 			ltoa(a,b);
 			c[0]='0';
 			c[1]=b[0];
 		}
 		 if(a>=10&&a<=99){
 			 ltoa(a,b);
 			 c[0]=b[0];
 			 c[1]=b[1];
 		 }
 		 for(bb=0;bb<2;bb++){
 		 degc=c[bb];
 		UCA0IE |= UCTXIE;
 		for(i=0;i<500;i++){
 			for(j=0;j<100;j++);
 		}
 		 }
 	}
 	*/
}
コード例 #20
0
int main(void) {
    /* Configure Watch dog timer as an interval timer. WDTIFG is
     * set upon expiration of selected time interval, and PUC is not
     * generated, so there is no reset of the device. Also, WDTIE bit
     * remains unchanged, so you don't have to reset the WDT interrupt.
     *
     * WDTCTL is 16 bits and always needs to be accessed with
     * the upper 8 bits as the WDT password, WDTPW (0x5A).
     * Use ACLK for WDTCNT - selected with the WDTSSEL bit
     * Set WDTTMSEL bit to 1 for interval timer mode.
     * WDTIS0 and WDTIS1 set the interval.
     * 00 = WDT clock source/32768 **This is the PUC value
     * 01 = WDT clock source/8192
     * 10 = WDT clock source/512
     * 11 = WDT clock source/64
     * With ACLK = 1.5kHz and dividing it by 32768, we get ~21.8 seconds
     * With ACLK = 1.5kHz and dividing it by 64, we get 42.6mS
     * between WDT interrupts. */
	WDTCTL = WDTPW + WDTHOLD;
	initClocks();

	/* Configure Bluetooth module */
	hc05_init(__baud_to_uca0br(9600));
    hc05_transmit("HC05 init\r\n",11);

    /* Initialize mpu6050 */
	mpu6050_init();
    hc05_transmit("mpu6050 init\r\n",14);

    /* Now we are ready for application code to run. Enable interrupts */
	_BIS_SR(GIE);

	while(1) {

        if(data_received != 0) {
            switch(data_received) {
                case 'T':
                data_received = 0;
                    mpu6050_temp();

                    break;
                case 'A':
                    data_received = 0;

                    mpu6050_accel();
                    break;
                case 'G':
                    data_received = 0;

                    mpu6050_gyro();
                    break;
                case 'g':
                    data_received = 0;
                    mpu6050_calibrate_gyros();
                    break;
                case 'M':
                    data_received = 0;
                    mpu6050_getAddress();
                    break;
                case 'W':
                    data_received = 0;
                    mpu6050_wakeup();
                    break;
                case 'S':
                    data_received = 0;
                    mpu6050_sleep();
                    break;
                case 'R':
                    data_received = 0;
                    dmp_mode = 0;
                    motion_detect_mode = 0;
                    mpu6050_reset();
                    break;
                case 'd':
                    data_received = 0;
                    mpu6050_dmpinit();
                    break;
                case 'E':
                    data_received = 0;
                    motion_detect_mode = 0;
                    dmp_mode = 1;
                    mpu6050_setDMPEnabled(true);
                    P2DIR &= ~MPU6050_INT;  // Input
                    P2SEL &= ~MPU6050_INT;  // Digital IO Psel and psel2 are 0
                    P2SEL2 &= ~MPU6050_INT;
                    P2IES &= ~MPU6050_INT;  // Edge select 0 = low to high
                    P2IFG &= ~MPU6050_INT;  // Clear the interrupt flag before enabling interrupt
                    P2IE |= MPU6050_INT;    // Interrupt enable
                    //mpu6050_resetFIFO();
                    break;
                case 'e':
                    dmp_mode = 0;
                    data_received = 0;
                    mpu6050_setDMPEnabled(false);
                    break;
                case 'm': /* Itseems that I can have motion detect interrupts if I first call the dmpinit() function, then this code is run. I can probably narrow it down
                to a certain function call in the dmpinit() it will just take time */
                    sendAck();
                    motion_detect_mode = 1;
                    dmp_mode = 0;
                    mpu6050_setDMPEnabled(false);
                    i2c_write_reg(MPU6050_RA_INT_PIN_CFG,0x10);//interrupt status cleared on any read
                    //i2c_write_reg(MPU6050_RA_MOT_DETECT_CTRL,0x30); // add the 3 ms delay to accel put
                    mpu6050_setMotionDetectionThreshold(threshold);//not sure... but I'm told it's 2mg per LSB so 0xFF would only be about 0.512g
                    mpu6050_setMotionDetectionDuration(threshold_duration); // This duration will really change the snappiness and responsiveness of the motion detect (duh) so
                    // it should be set to as low as possible, then set detection threshold to the appropriate value for punches or whatever
                    mpu6050_setIntEnabled(0x40);//motion detect... based on the product specification document, I don't think motion detect can generate an interrupt on INT pin,
                    // so we also set the data ready interrupt.
                    mpu6050_configAccel(MPU6050_ACCEL_FS_16<<(MPU6050_ACONFIG_AFS_SEL_BIT-1));
                    data_received = 0;
                    P2DIR &= ~MPU6050_INT;  // Input
                    P2SEL &= ~MPU6050_INT;  // Digital IO Psel and psel2 are 0
                    P2SEL2 &= ~MPU6050_INT;
                    P2IES &= ~MPU6050_INT;  // Edge select 0 = low to high
                    P2IFG &= ~MPU6050_INT;  // Clear the interrupt flag before enabling interrupt
                    P2IE |= MPU6050_INT;    // Interrupt enable
                    /*while(1) {

                        if(mpu6050_getIntStatus() & 0x40) {
                            //motion interrupt
                            hc05_transmit("Motion\r\n",8);
                        }
                    }*/

                    break;
                case 'l':
                    threshold = threshold - 1;
                    mpu6050_setMotionDetectionThreshold(threshold);
                    break;
                case 'p':
                    threshold = threshold + 1;
                    mpu6050_setMotionDetectionThreshold(threshold);
                    break;
                case 'L':
                    threshold_duration = threshold_duration - 5;
                    mpu6050_setMotionDetectionDuration(threshold_duration);
                    break;
                case 'P':
                    threshold_duration = threshold_duration + 5;
                    mpu6050_setMotionDetectionDuration(threshold_duration);
                    break;

              //  case 'h':
                //    hc05_setspeed(115200);
                //    data_received = 0;
                //    break;
                //case 'k':
                //    hc05_key();
                //    data_received = 0;
               //     break;
                default:
                    sendAck();
                    data_received = 0;
                    break;
            }
		}
		if(mpu6050_interrupt) {
            if(dmp_mode) {
                mpuIntStatus = mpu6050_getIntStatus();
                fifoCount = mpu6050_getFIFOCount();
                if(fifoCount > 16) {
                    fifoCount =16;
                }
                mpu6050_getFIFOBytes(mpu6050_buffer,fifoCount);
               /* This seems to keep the fifo operating. I probably need to read the fifo faster so it doesn't 'die' on me */
                mpu6050_resetFIFO();

                /* From J.Rowberg's library, the dmp packet output is:
                bytes 0-15 quaternion (32 bits)  (w,x,y,z) but just use the first two bytes as 16 bit number
                bytes 16-27 gyro (32 bits) (gx,gy,gz) but just use the first two bytes as 16 bit number
                bytes 28-39 acceleration (32 bits) (ax,ay,az) but just use the first two bytes as 16 bit number
                */

                teapotPacket[2] = mpu6050_buffer[0];
                teapotPacket[3] = mpu6050_buffer[1];
                teapotPacket[4] = mpu6050_buffer[4];
                teapotPacket[5] = mpu6050_buffer[5];
                teapotPacket[6] = mpu6050_buffer[8];
                teapotPacket[7] = mpu6050_buffer[9];
                teapotPacket[8] = mpu6050_buffer[12];
                teapotPacket[9] = mpu6050_buffer[13];
                teapotPacket[10] = mpuIntStatus; // I modified the packet to sent the interrupt status in this byte
                hc05_transmit(teapotPacket,14);
                 teapotPacket[11]++;
                mpu6050_interrupt = 0;

            } else if (motion_detect_mode) {
                if(mpu6050_getIntStatus() & 0x40) {
                    // Disable motion interrupts, get accel and gyro values until they aren't interesting
                    // anymore, then quit and enable interrupt.
                    mpu6050_setIntEnabled(0x00);
                    //motion interrupt
                  //  hc05_transmit("Motion\r\n",8);
                    for(uint8_t j = 0; j<100; j++) {
                        mpu6050_accel();
                        delay_ms(2);
                      //  i2c_tx_buffer[0] = 0x3B;
                     //   i2c_tx_buffer_counter = 1;
                    //	i2c_transmit_to_receive();
                     //   i2c_transmit();
                    //    i2c_multireceive(6);
                    //	for(j = 0; j< 6; j++) {
                        //	TXData = i2c_rx_buffer[j];

                        /* These are div 16384 if +/-2g, 8192 if +/-4g, 4096 if +/-8g and 2048 if +/-16g*/
                        //accelX[j] = (i2c_rx_buffer[0]<<8 | i2c_rx_buffer[1]);
                        //accelY[j] = (i2c_rx_buffer[2]<<8 | i2c_rx_buffer[3]);
                        //accelZ[j] = (i2c_rx_buffer[4]<<8 | i2c_rx_buffer[5]);
                        //sprintf(tempbuf,"%d %d %d\r\n",ax,ay,az);
                        //sprintf(tempbuf,"E%d,%d,%d\r\n",ax,ay,az);
                       // hc05_transmit(tempbuf,strlen(tempbuf));
                    //    hc05_transmit((char*)ax,1);
                        //hc05_transmit((char*)ay,1);
                        //hc05_transmit((char*)az,1);
                        //}
                        //__delay_us(1000);
                        //delay_ms(2);

                    }

                   // hc05_transmit((char*)accelX,2*ACCELBUFSIZE);
                   // hc05_transmit((char*)accelY,2*ACCELBUFSIZE);
                   // hc05_transmit((char*)accelZ,2*ACCELBUFSIZE);
                   // mpu6050_getIntStatus();
                    mpu6050_setIntEnabled(0x40);
                } else {
                  //  sprintf(tempbuf,"Unknown interrupt\r\n");
                  //  hc05_transmit(tempbuf,strlen(tempbuf));
                }
            } else {
//                mpu6050_getIntStatus(); // Clear any other interrupts
               // sprintf(tempbuf,"Unknown mode & interrupt\r\n");
               // hc05_transmit(tempbuf,strlen(tempbuf));
            }
		}
		  __bis_SR_register(LPM0_bits + GIE);
	}
}