Ejemplo n.º 1
0
// 9 ->Light2
//10 LASER
//11 LED
//12 PWM light 1
// the setup routine runs once when you press reset:
void setup() {                
	// initialize the digital pin as an output.
		WDT_Stop();
	digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
	digitalWrite(led2, HIGH);   // turn the LED on (HIGH is the voltage level)
	digitalWrite(light1, LOW);   // turn the LED on (HIGH is the voltage level)
	digitalWrite(light2, LOW);   // turn the LED on (HIGH is the voltage level)
	digitalWrite(laser, LOW);   // turn the LED on (HIGH is the voltage level)

	pinMode(led, OUTPUT);     
	pinMode(led2, OUTPUT);     
	pinMode(laser, OUTPUT);     
	pinMode(btn, INPUT);      
	pinMode(batadc, INPUT);      

        //ADC prescaler
        sbi(ADCSRA,ADPS2);
        sbi(ADCSRA,ADPS1);
        sbi(ADCSRA,ADPS0);
	// digitalWrite(light1, LOW);   // turn the LED on (HIGH is the voltage level)
	if(dosystemtest&&!digitalRead(btn))
            systemtest();
            dosystemtest=0;
        switch_off();  
        sleepcounter=0;
        check_bat();
//        attachInterrupt(0, int0f, FALLING);
	//state=0;
	//int0();
//WDT_Init();
//	        toggle_led(led2,&ledstate2);

}
Ejemplo n.º 2
0
void WDT_Init(WDT_InitTypeDef* WDT_InitStruct)
{
    /* Check the parameters */
    assert_param(IS_WDT_CTRL_RSTEN(WDT_InitStruct->WDTControl_RstEn));
   
    WDT_Stop();
    
    WDT->WDTLoad      = WDT_InitStruct->WDTLoad;
    WDT->WDTControl   = (WDT_InitStruct->WDTControl_RstEn << WDTControl_RstEn_Pos);

    WDT_Lock();
}
Ejemplo n.º 3
0
/******************************************************************************************************************************************
* 函数名称: WDT_Init()
* 功能说明: WDT看门狗初始化
* 输    入: WDT_TypeDef * WDTx      指定要被设置的看门狗,有效值包括WDT
*           uint32_t peroid         取值0--4294967295,单位为单片机系统时钟周期
*           uint32_t mode           WDT_MODE_RESET 超时产生复位    WDT_MODE_INTERRUPT 超时产生中断
* 输    出: 无
* 注意事项: 复位使能时中断不起作用,因为计数周期结束时芯片直接复位了,无法响应中断
******************************************************************************************************************************************/
void WDT_Init(WDT_TypeDef *WDTx, uint32_t peroid, uint32_t mode)
{
    SYS->CLKEN |= (0x01 << SYS_CLKEN_WDT_Pos);

    WDT_Stop(WDTx);     //设置前先关闭

    WDTx->LOAD = peroid;

    if (mode == WDT_MODE_RESET)
    {
        NVIC_DisableIRQ(WDT_IRQn);

        WDTx->CR |= (1 << WDT_CR_RSTEN_Pos);
    }
    else //mode == WDT_MODE_INTERRUPT
    {
        NVIC_EnableIRQ(WDT_IRQn);

        WDTx->CR &= ~(1 << WDT_CR_RSTEN_Pos);
    }
}
Ejemplo n.º 4
0
// the loop routine runs over and over again forever:
void loop() {
  byte lclocktick=0;
 //       int j;
	//    analogWrite(9, 60);
	//  TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
	//  TCCR2B = _BV(CS22);
	//  OCR2A = 180;
	//  OCR2B = 50;

	//  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
	if(!(laserstate||lightstate||command_pending))
	{
              
            if(sleepcounter==0)
            {
                attachInterrupt(0, int0, LOW);

		WDT_Stop();
                set_led(led,&ledstate,0);
               set_led(led2,&ledstate2,0);
//                delay(100);
		go_sleep();
                int0f();
		WDT_Init();
            }
	}
        else
            sleepcounter=SLEEPIDLESECS;
        if(clocktick)
        {
          cli();
            lclocktick=clocktick;
            clocktick=0;
          sei();
       	set_led(led,&ledstate,0);

            wdtcounter+=lclocktick;
            sleepcounter--;
           if(!(wdtcounter%BATCHECKSECS))
               checkbat=1;
            if(laserstate)
            		lasercounter++;
            
             if(lightstate)
			lightcounter++;


        }

	if(command_pending==2)
	{
		btnpress();

		command_pending=0;
            

	}
	if(command_pending==1&&millis()-timepressed>LONGBUTTONPRESS)
		int0r();
//	toggle_led(led2,&ledstate2);

	if(laserstate&&(lasercounter>LASER_MAX_ON))
	{
		set_laser(0);
                laserstate=0;

	}
	if(lightstate&&(lightcounter>LIGHT_MAX_ON))
	{
              set_lights(0);
              lightstate=0;
	}

        if(checkbat)
        {
          check_bat();
          checkbat=0;
        }
        if(volts<VBATTHRESH)
        {
             if(lclocktick)
         	    toggle_led(led2,&ledstate2);   
        }
        else   
            set_led(led2,&ledstate2,0);      
        if(volts<VBATTHRESH_CRIT)
        {
          if(!(wdtcounter%BATCHECKCRITSECS))
          {
   //         for(j=0;j<3;j++)
   //         {
              set_lights(0);
              delay(100);
              set_lights(lightstate);
               delay(100);
   //         }
            
          }
          
        }            


	//delay(100);
	//  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
	//  delay(500);               // wait for a second
}