Пример #1
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /* CLK configuration -------------------------------------------*/
  CLK_Config();

  /* Initialize Leds mounted on STM8L1526-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* Turn on LED1 and LED3 */
  STM_EVAL_LEDOn(LED1);
  STM_EVAL_LEDOn(LED3);

   /* TIM4 configuration -------------------------------------------*/
  TIM4_Config();
  
  while (1)
  {
    /* Toggle LED2 and LED4 */
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED4);

    /* Insert 50 ms delay */
    Delay(50);

    /* Toggle LED1 and LED3 */
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED3);

    /* Insert 100 ms delay */
    Delay(100);
  }
}
Пример #2
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /* CLK configuration -------------------------------------------*/
  CLK_Config(); 

  /* ADC configuration -------------------------------------------*/
  ADC_Config(); 

  /* DMA configuration -------------------------------------------*/
  DMA_Config(); 

  /* TIM1 configuration -------------------------------------------*/
  TIM1_Config(); 

  /* Enable ADC1 DMA requests*/
  ADC_DMACmd(ADC1, ENABLE);

  /* Enable TIM1 DMA requests*/
  TIM1_DMACmd(TIM1_DMASource_Update, ENABLE);

  /* Start ADC1 Conversion using Software trigger*/
  ADC_SoftwareStartConv(ADC1);

  while (1)
  {}
}
Пример #3
0
/*主程序*/
void main()
{	
	CLK_Config();

	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE);	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER3, ENABLE);	

	/* Check if the system has resumed from IWDG reset */
	if (RST_GetFlagStatus(RST_FLAG_IWDGF) != RESET)
	{
	  /* Clear IWDGF Flag */
	  RST_ClearFlag(RST_FLAG_IWDGF);
	}
	
	/*通信串口初始化*/
	DBG_Config();
	
	IR_Init();
	
	printf("starting...\n");

	/*打开全局中断*/
	enableInterrupts();    

	while (1)
	{
		IR_Process();
	}
		
}
Пример #4
0
int main(void)
{
		TIME  time;
		
		 /*时钟初始化*/
		CLK_Config();
			
		/*初始化电源控制*/
		GPIO_DeInit(GPIOD); 
		GPIO_Init(GPIOD,GPIO_PIN_3,GPIO_MODE_OUT_PP_LOW_FAST);
		GPIO_DeInit(GPIOC); 
		GPIO_Init(GPIOC,GPIO_PIN_1,GPIO_MODE_OUT_PP_LOW_FAST);	
	
		/*上电,3.3V/12V*/
		VDD3V3_ON();
		VDD12_ON();
	
		RTC_Init();


		while (1)
		{
			RTC_ReadDate(&time);

		  
		}
			

	


	return 0;
}
Пример #5
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /* CLK configuration -------------------------------------------*/
  CLK_Config(); 

  /* Init TIM2 to generate 1 ms time base update interrupt */
  TimingDelay_Init();

  /* Enable Interrupts */
  enableInterrupts();

  /* Initialize LEDs mounted on STM8L152X-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* Turn on LED1 and LED3 */
  STM_EVAL_LEDOn(LED1);
  STM_EVAL_LEDOn(LED3);

  /* Initialize push-buttons mounted on STM8L152X-EVAL board */
  STM_EVAL_PBInit(BUTTON_RIGHT, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_LEFT, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_EXTI);

  /* Init the Eval board LCD */
  STM8_EVAL_LCD_Init();

  /* Clear LCD */
  LCD_Clear();

  /* Enable general interrupts */
  enableInterrupts();

  LCD_SetCursorPos(LCD_LINE1, 0);
  LCD_Print("  System Clock  ");
  LCD_SetCursorPos(LCD_LINE2, 0);
  LCD_Print("  Source:  HSE  ");

  while (1)
  {
    /* Toggle LED2 and LED4 */
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED4);

    /* Insert a delay */
    Delay(10);

    /* Toggle LED1 and LED3 */
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED3);

    /* Insert a delay */
    Delay(10);
  }
}
Пример #6
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    /* GPIO Configuration  -----------------------------------------*/
    GPIO_Config();  
    
    /* Clock configuration -----------------------------------------*/
    CLK_Config();    
    
    while (1)
    {
    }
}
Пример #7
0
/**
  * @brief Example  main entry point.
  * @param  None
  * @retval None
  */
void main(void)
{
    uint8_t state = 0x00;

    /* GPIO Configuration  -----------------------------------------------------*/
    GPIO_Config();

    /* Configure LCD mounted on STM8-128 EVAL board ----------------------------*/
    LCD_Config();

    /* Clock configuration -----------------------------------------------------*/
    CLK_Config();

    enableInterrupts();

    while (1)
    {
        while(state == OscillatorStatus)
        {}
        state = OscillatorStatus; /* Update the selected master clock oscillator */

        /* joystick right */
        if(OscillatorStatus == 0x00)
        {
            CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);

            /* Print on LCD line2*/
            LCD_SetCursorPos(LCD_LINE2, 0);
            LCD_Print("   CLK = HSI    ");
        }

        /* joystick up */
        if(OscillatorStatus == 0x01)
        {
            CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);

            /* Print on LCD line2*/
            LCD_SetCursorPos(LCD_LINE2, 0);
            LCD_Print("   CLK = HSE    ");
        }

        /* joystick down */
        if(OscillatorStatus == 0x02)
        {
            CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_LSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);

            /* Print on LCD line2*/
            LCD_SetCursorPos(LCD_LINE2, 0);
            LCD_Print("   CLK = LSI    ");
        }
    }
}
Пример #8
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{

   /* CLK configuration -------------------------------------------*/
  CLK_Config(); 

  /* Init the Eval board LCD */
  STM8_EVAL_LCD_Init();

  /* Clear  LCD */
  LCD_Clear();

  /* Print the Voltage on the LCD*/
  LCD_SetCursorPos(LCD_LINE1, 0);
  LCD_Print("  POT      BNC  ");

   /* ADC configuration -------------------------------------------*/
  ADC_Config();

   /* DMA configuration -------------------------------------------*/
  DMA_Config();
    
  /* Enable ADC1 DMA requests*/
  ADC_DMACmd(ADC1, ENABLE);

  /* Start ADC1 Conversion using TIM1 TRGO*/
  ADC_ExternalTrigConfig(ADC1, ADC_ExtEventSelection_Trigger2,
                         ADC_ExtTRGSensitivity_Rising);

  /* Master Mode selection: Update event */
  TIM1_SelectOutputTrigger(TIM1_TRGOSource_Update);

  /* Enable TIM1 */
  TIM1_Cmd(ENABLE);

  /* Enable Interrupts */
  enableInterrupts();

  /* Infinite loop*/
  while (1)
  {
    if (DisplayStatus != DISABLE)
    {
      /* Display Potentiometer RV and BNC voltage values on LCD*/
      ShowVoltages(PotVoltage, BNCVoltage);
      /* Disable displaying voltages on LCD until next DMA Channel0 Transfer complete occurs */
      DisplayStatus = DISABLE;
    }
  }
}
Пример #9
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /* CLK configuration -------------------------------------------*/
  CLK_Config(); 

   /* GPIO configuration -------------------------------------------*/
  GPIO_Config(); 
  
   /* TIM configuration -------------------------------------------*/
  TIM_Config();

  while (1)
  {}
}
Пример #10
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /* CLK configuration -------------------------------------------*/
  CLK_Config(); 

   /* GPIO configuration -------------------------------------------*/
  GPIO_Config(); 
  
   /* TIM1 configuration -------------------------------------------*/
  TIM1_Config();
  
  /* Infinite loop */
  while (1)
  {}
}
Пример #11
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    /* Clock configuration -----------------------------------------*/
    CLK_Config();
    
    /* GPIO Configuration ------------------------------------------*/
    GPIO_Config();

		
   /***********************SPI and MSD Card initialization******************/

    while (SD_Detect() == SD_NOT_PRESENT);
    {
      /* Wait MicroSD card insertion */
    }

    Delay(0xFFFF);
    /* Init the flash micro SD*/
    Status = SD_Init();

  /***************************Block Read/Write******************************/
  /* Write block of 512 bytes on address 0 */
  SD_WriteBlock(TxBuffer, 0, BUFFER_SIZE);

  /* Read block of 512 bytes from address 0 */
  SD_ReadBlock(RxBuffer, 0, BUFFER_SIZE);

  /* Check data */
  TransferStatus = Buffercmp(TxBuffer, RxBuffer, BUFFER_SIZE);
  if (TransferStatus != SUCCESS)
  {
    while (1) /* Go to infinite loop when there is mismatch in data programming*/
    {
      STM_EVAL_LEDToggle(LED1);
      Delay((uint16_t)0xFFFF);
      Delay((uint16_t)0xFFFF);
    }
  }
  while (1)
  {
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);
    Delay((uint16_t)0xFFFF);
    Delay((uint16_t)0xFFFF);
  }
}
Пример #12
0
void main(void)
{
    /* Clock configuration -----------------------------------------*/
    CLK_Config();  
    /* GPIO configuration ------------------------------------------*/
    GPIO_Config_Init();
    
    TIM3_Config();
    TIM4_Config();
    UART1_Config();
    UART3_Config();
    
    enableInterrupts();
    DeviceStatus.workState = 16;
    Delay(200);
    //beep
    Set_Beep_OptionByte();
    Beep_Init(BEEP_FREQUENCY_4KHZ);
    BEEP_LSICalibrationConfig(LSI_128kHz);
    
    showAll();
    PowerOnBeep();
    clear();
    TIM2_Config();
    
    showTemp(Temperature[DeviceStatus.workState], ON);
    showSymbol(SYMBOL_DEFAULT);
    FunctionReport(DeviceStatus.workState);
    while (1)
    {
        if(DeviceStatus.Time_100ms == 1)
        {
            if(UART1_GetFlagStatus(UART1_FLAG_IDLE) == SET)
            {
                if(DataSize != 0)
                {
                    DataResolve(RxRecvBuffer, DataSize); 
                    DataSize = 0;
                }
            }
            DeviceStatus.Time_100ms = 0;
        }
    }
  
}
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
	static u16 i=0;
	
	CLK_Config();

	UART_Config();

	TIM2_Config();
	enableInterrupts();

	printF("TIM2_Config finish !\n",FALSE,0);

    /* Infinite loop */
    while (1)
    {
    	_Delay(100);
		printF("LOG MSG (%4d) !\n",TRUE,i++);
    }
}
Пример #14
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /* Clock configuration -----------------------------------------*/
  CLK_Config();  

  /* GPIO configuration -----------------------------------------*/
  GPIO_Config();  

  /* UART1 configuration -----------------------------------------*/
  UART1_Config();  


  while (1)
  {
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);
    Delay((uint32_t)0xFFFF);
  }
}
Пример #15
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /* CLK configuration -------------------------------------------*/
  CLK_Config(); 

  /* Init TIM2 to generate 1 ms time base update interrupt */
  TimingDelay_Init();

  /* Enable Interrupts */
  enableInterrupts();

  /* 1s delay to ensure proper LCD Init*/
  Delay(1000);

  /* Init the Eval board LCD */
  STM8_EVAL_LCD_Init();

  /* Clear LCD */
  LCD_Clear();

  /* print "Pot ADC Voltage" on LCD line1*/
  LCD_SetCursorPos(LCD_LINE1, 0);
  LCD_Print("Pot ADC Voltage");

   /* ADC configuration -------------------------------------------*/
  ADC_Config();

  /* Infinite loop*/
  while (1)
  {
    /* Calculate voltage value*/
    PotVoltage = (uint16_t)((uint32_t)((uint32_t)ADCdata * (uint32_t)ADC_RATIO) / (uint32_t)1000);

    /* Display voltage value on LCD*/
    ShowVoltage((uint16_t)PotVoltage);
  }

}
Пример #16
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   uint16_t i = 0;

   /* Init GPIO for LED  */
   GPIO_Config();

   /* CLK configuration --------------------------------------------*/
   CLK_Config();

   while (1)
   {
     /*  Toggle the LEDs  */
     STM_EVAL_LEDToggle(LED1);
     STM_EVAL_LEDToggle(LED2);
     STM_EVAL_LEDToggle(LED3);
     STM_EVAL_LEDToggle(LED4);
     for (i = 0; i < 2; i++)
     {
         Delay((uint16_t)60000);
     }
   }
}
Пример #17
0
/*主程序*/
void main()
{
	CLK_Config();
	
	/*通信串口初始化*/
#ifdef __DEBUG__
	DBG_Config();
#endif

	/*打开全局中断*/
	enableInterrupts();    
	while (1)
	{
		u16 i = 1000;
		
		printf("Hello, world! my name is %s\n", "gaozhengdong");
		for(; i > 0; i--)
		{
			Delay_1ms();
		}
	}
		
}
Пример #18
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /* CLK configuration -------------------------------------------*/
  CLK_Config(); 
  
  /* Init TIM2 to generate 1 ms time base update interrupt */
  TimingDelay_Init();

  /* Key button configuration */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);

  /* Initialize Leds mounted on STM8L152X-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

   /* COMP configuration -------------------------------------------*/
  COMP_Config(); 

  /* Enable Interrupts */
  enableInterrupts();

  /* Infinite loop */
  while (1)
  {
    /* Toggle LDE1..4 */
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);

    /* Insert delay */
    Delay(50);
  }
}
Пример #19
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    /* CLK configuration -------------------------------------------*/
    CLK_Config();

    /* GPIO configuration -------------------------------------------*/
    GPIO_Config();

    /* TIM1 configuration -------------------------------------------*/
    TIM1_Config();

    /* DAC configuration -------------------------------------------*/
    DAC_Config();

    /* COMP configuration -------------------------------------------*/
    COMP_Config();

    /* TIM1 counter enable */
    TIM1_Cmd(ENABLE);

    /* Infinite loop */
    while (1)
    {}
}
Пример #20
0
void main(void)
{
    /* Clock configuration -----------------------------------------*/
    CLK_Config();  
    /* GPIO configuration ------------------------------------------*/
    GPIO_Config_Init();
    UART1_Config();
    UART3_Config();
    PWM_Config();
    TIM2_Config();
    TIM3_Config();
    TIM4_Config();
    
    I2C_RTC_Init();
    /* Enable general interrupts */  
    enableInterrupts();
                  //【秒, 分, 时, 日, 星期, 月, 年】
    uint8_t time[] = {00, 12, 10, 1, 1, 6, 15};
    //Set_RT8563(time, 2, 7);
    ResetNetMode();
#if 0
    uint8_t Alarm[5][3] = {1, 16, 31, 1, 16, 33, 1, 16, 35};
    uint8_t Time[7] = {0};
    uint8_t AlarmState = 0;
    uint8_t AlarmDelay = 1;
    unsigned int NET_AUTO_SEND = 0;
#endif
    
    while (1)
    {
#if 0
        Delay(1000);
        Send_BAT_Voltage(Get_BAT_Value());
        UART3_SendString("\n", 1);
        AQI2PM25(Get_DS_Value());
#endif      
        if(DeviceStatus.Time_30ms == 1)
        {
            TouchKey_Read();
            DeviceStatus.Time_30ms = 0;
        }
        if(DeviceStatus.Time_100ms == 1)
        {
            if(UART1_GetFlagStatus(UART1_FLAG_IDLE) == SET)
            {
                if(DataSize != 0)
                {
                    DataResolve(RxRecvBuffer, DataSize); 
                    NetProcess();
                    DataSize = 0;
                }
            }
            DeviceStatus.Time_100ms = 0;
        }
        if(DeviceStatus.Time_1_s == 1)
        {
            Get_RT8563(time, 2, 7);
#if 0
            ArrayCopy((uint8_t *)&NetMode.SendData, time, 7);
            UART3_SendString((uint8_t *)&NetMode.SendData, 7);
            if(NetMode.Status & NET_CONNECT)    
            {
                NET_LED_FLASH;
                NET_AUTO_SEND++;
                if(NET_AUTO_SEND == 10)//自动发送数据
                {
                    NetSendDataLength();
                    
                    NET_AUTO_SEND = 0;
                }
            }
            else NET_AUTO_SEND = 0;
#endif
            
            DeviceStatus.Time_1_s = 0;
        }

        if(DeviceStatus.Time_30_s == 1)
        {
            NetModeErrorFix();
            DeviceStatus.Time_30_s = 0;
        }
#if 0
        GetTime(Time);
        if(ArrayCMP(Alarm, Time, 3) == 0 && AlarmState == 0) 
        {
            GPIO_WriteHigh(GPIOF, GPIO_PIN_5);
            FAN_SPEED_HIGH; //高速
            Alarm[2] += AlarmDelay;
            AlarmState = 1;
        }
        else if(ArrayCMP(Alarm, Time, 3) == 0 && AlarmState == 1)
        {
            GPIO_WriteLow(GPIOF, GPIO_PIN_5);
            FAN_SPEED_OFF;
            AlarmState = 0;
            Alarm[2] -= AlarmDelay;
        }
#endif
    }
  
}
Пример #21
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  uint32_t index = 0;

   /* CLK configuration -------------------------------------------*/
  CLK_Config(); 
 
  /* Set the MOSI and SCK at high level */
  GPIO_ExternalPullUpConfig(GPIOB, GPIO_Pin_6 | GPIO_Pin_5, ENABLE);

#ifdef USE_STM8L1526_EVAL
  /* Set USART CK at high level */
  GPIO_ExternalPullUpConfig(GPIOC, GPIO_Pin_4, ENABLE);
#else /* USE_STM8L1528_EVAL is defined */
  /* Set USART CK at high level */
  GPIO_ExternalPullUpConfig(GPIOH, GPIO_Pin_6, ENABLE);
#endif  /* USE_STM8L1526_EVAL */

   /* USART configuration -------------------------------------------*/
  USART_Config(); 
  
   /* SPI configuration -------------------------------------------*/
  SPI_Config(); 
  
  /*Disable USART the master*/
  USART_Cmd(EVAL_COM1, DISABLE);

   /* DMA configuration -------------------------------------------*/
  DMA_Config(); 
 
  /* Enable USART */
  USART_Cmd(EVAL_COM1, ENABLE);

  /* Insert Delay to ensure Synchro w/ SPI */
  for (index = 0; index < 0xFF; index++);

  /* Enable SPI */
  SPI_Cmd(SPI1, ENABLE);

  USART_ITConfig(EVAL_COM1, USART_IT_TC, ENABLE);

  /* Wait until Data transmitted to SPI*/
  while (UsartTransferStatus != 2);
  /* Wait the SPI DMA Rx transfer complete */
  while (DMA_GetFlagStatus((DMA_FLAG_TypeDef)SPI_DMA_FlagTCRx) == RESET);


  /* Check the correctness of written dada */
  TransferStatus1 = Buffercmp((uint8_t*)RxBuffer1, SPIBuffer_Rx, RX_BUFFER_SIZE);
  /* TransferStatus1 = PASSED, if the received data by USART and received data
    by SPI1 are the same */
  /* TransferStatus1 = FAILED, if the received data by USART and received data
     by SPI1 are different */

  if (TransferStatus1 != FAILED)
  {
    for (index = 0; index < MESSAGE2_SIZE; index++)
    {
      /* Wait while USART TC = 0 */
      while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET);
      /* Send on byte from stm8l15x USART to HyperTerminal */
      USART_SendData8(EVAL_COM1, Message2[index]);
    }
  }
  else
  {
    for (index = 0; index < MESSAGE3_SIZE; index++)
    {
      /* Wait while USART TC = 0 */
      while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET);
      /* Send on byte from stm8l15x USART to HyperTerminal */
      USART_SendData8(EVAL_COM1, Message3[index]);
    }
  }

  while (1)
  {}
}
Пример #22
0
/*主程序*/
void main()
{	
	u8 i = 0;
	
	 /*时钟初始化*/
  	CLK_Config();

#ifdef _IWDG_
	/* Check if the system has resumed from IWDG reset */
	if (RST_GetFlagStatus(RST_FLAG_IWDGF) != RESET)
	{
	  /* Clear IWDGF Flag */
	  RST_ClearFlag(RST_FLAG_IWDGF);
	}

	/* get measured LSI frequency */
	LsiFreq = LSIMeasurment();
	
	/* IWDG Configuration */
	IWDG_Config();
#endif
	
	/*初始化电源控制*/
	GPIO_DeInit(GPIOD);	
	GPIO_Init(GPIOD,GPIO_PIN_3,GPIO_MODE_OUT_PP_LOW_FAST);
	GPIO_DeInit(GPIOC);	
	GPIO_Init(GPIOC,GPIO_PIN_1,GPIO_MODE_OUT_PP_LOW_FAST);	
	
#ifdef __DEBUG__
	/*底板MCU调试串口配置*/
	DBG_Config();
#endif

	/*按键初始化*/
	KEY_Init();

	/*串口初始化*/
	COMM_Init();

	/*遥控器硬件初始化*/
	IR_Init();
	
	/*初始化CAN*/
	CAN_Initialize();

	/*打开全局中断*/
	enableInterrupts();    
	
	/*上电,3.3V/12V*/
	VDD3V3_ON();
	VDD12_ON();


	while (1)
	{
		/*按键检测*/
		KEY_Process();

		/*红外遥控器处理*/
		IR_Process();
		
		/*CAN通信处理*/
		CAN_Process();
		
#ifdef _IWDG_		
		/*独立看门狗喂狗*/
		IWDG_ReloadCounter();  
#endif
	}
		
}
Пример #23
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
	CLK_Config();
	FlashInit();

	sim();									// disable interrupts

	GPIO_Init(GPIOA, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOB, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOC, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOE, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOF, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
	GPIO_Init(GPIOG, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);

	delay1s(5);

	#ifdef DEBUG
		AppTrace_Init();
    	printf("\r\nSTM8L152 Start ...\r\n");
	#endif
	
	LED_Init();
    LED1_ON();
	scheduler_init();

	// Build count init event 
	count_event.eCount_event = COUNT_INIT;
	app_sched_event_put(&count_event,sizeof(count_event),count_event_handler);
	
	// Build key init event 
	key_event.eKey_event = KEY_INIT;
	app_sched_event_put(&key_event,sizeof(key_event),key_event_handler);
	
	// Build the valve standby event 
	valve_event.eValve_event = VALVE_STANDBY_EVENT;
	app_sched_event_put(&valve_event,sizeof(valve_event),valve_event_handler);
    
    // Build the LCD init event 
	lcd_event.eLcd_event = LCD_INIT;
	app_sched_event_put(&lcd_event,sizeof(lcd_event),lcd_event_handler);

	// Build the beeper init event 
	beeper_event.eBeeper_event = BEEPER_INIT;
	app_sched_event_put(&beeper_event,sizeof(beeper_event),beeper_event_handler);

	// Build the cc1120 Init event 
	cc112x_event.eCC112x_event = CC112X_INIT_EVENT;
	app_sched_event_put(&cc112x_event,sizeof(cc112x_event),cc112x_event_handler);

	// Build the IC card Init event 
	ic_card_event.eIC_event = IC_CARD_INIT;
	app_sched_event_put(&ic_card_event,sizeof(ic_card_event),ic_event_handler);

	// Build the IC card Init event 
	battery_event.eBattery_event = INT_BATTERY_EVENT;
	app_sched_event_put(&battery_event,sizeof(battery_event),battery_event_handler);

    // enable interrupts 
	rim();
    LED1_OFF();
	 
	// Infinite loop 
  	while (1)
  	{
		app_sched_execute();
		app_evt_wait();
  	}
}
Пример #24
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /*************** Initialize LEDs available on STM8L15X-EVAL board ***********/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);

  /* CLK configuration -------------------------------------------*/
  CLK_Config(); 
  
  /* ADC configuration -------------------------------------------*/
  ADC_Config(); 

  /* COMP configuration -------------------------------------------*/
  COMP_Config(); 

  while (1)
  {
    if (State != STATE_UNDER_THRESHOLD) /* Input voltage is over the threshold VREFINT */
    {
      /* LD1 ON and LD2 OFF: MCU in run mode */
      STM_EVAL_LEDOn(LED1);
      STM_EVAL_LEDOff(LED2);

      /* Disable global Interrupts */
      disableInterrupts();
      /* Disable COMP clock */
      CLK_PeripheralClockConfig(CLK_Peripheral_COMP, DISABLE);

      /* Enable ADC1 clock */
      CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
      /* Enable end of conversion ADC1 Interrupt */
      ADC_ITConfig(ADC1, ADC_IT_EOC, DISABLE);
      /* Enable ADC1 */
      ADC_Cmd(ADC1, ENABLE);

      /* Start ADC1 Software Conversion */
      ADC_SoftwareStartConv(ADC1);
      /* Wait for first end of conversion */
      while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
      ADCVal = ADC_GetConversionValue(ADC1);
      /* Enable global Interrupts */
      enableInterrupts();

      /* Enable end of conversion ADC1 Interrupt */
      ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);

      while (State == STATE_OVER_THRESHOLD)
      {}
    }
    else /* Input voltage is under the threshold */
    {
      /* LD1 OFF and LD2 ON: MCU in halt mode */
      STM_EVAL_LEDOff(LED1);
      STM_EVAL_LEDOn(LED2);

      /* Disable global Interrupts */
      disableInterrupts();
      /* Clear EOC and OVR flags */
      ADC_ClearFlag(ADC1, (ADC_FLAG_TypeDef) (ADC_FLAG_EOC | ADC_FLAG_OVER));
      /* Disable ADC1 */
      ADC_Cmd(ADC1, DISABLE);
      /* Disable ADC1 clock */
      CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);

      /* Enable COMP clock */
      CLK_PeripheralClockConfig(CLK_Peripheral_COMP, ENABLE);
      /* Enable COMP2 Interrupt */
      COMP_ITConfig(COMP_Selection_COMP2, ENABLE);

      /* Enable global Interrupts */
      enableInterrupts();
      /* Check COMP2 output level before entering halt mode */
      if (COMP_GetOutputLevel(COMP_Selection_COMP2) == COMP_OutputLevel_Low)
      {
        /* Enter halt mode */
        halt();
      }
    }
  }
}
Пример #25
0
void main(void)
{
    CAN_TxStatus_TypeDef status = CAN_TxStatus_Failed;

    /* Transmit Parameters */
    CAN_Id_TypeDef Tx_IDE = CAN_Id_Standard;
    CAN_RTR_TypeDef Tx_RTR = CAN_RTR_Data;
    uint8_t Tx_DLC = 0;
    uint8_t Tx_Data[8] = {0};
    uint32_t Tx_Id = 0;

    /* Clock configuration --------------------------------------*/
    CLK_Config();

    /* GPIO Configuration ---------------------------------------*/
    GPIO_Config();

    /* Configure LCD mounted on STM8-128 EVAL board -------------*/
    LCD_Config();

    /* CAN configuration ----------------------------------------*/
    CAN_Config();

    /* Enable Interrupts*/
    enableInterrupts();

    /* Infinite loop*/
    while(1)
    {
        while(Key_status != Key_NoPressed)
        {

            if(Key_Pressed_Number == 0x0)
            {
                Key_Pressed_Number = 0x03;
            }
            else
            {
                Key_Pressed_Number--;
            }

            /* Sender Display*/
            LED_Display(Key_Pressed_Number);
            LCD_Display(Key_Pressed_Number);
            Delay(TIME);

            /* Transmit Parameters*/
            Tx_Id = 0x321;
            Tx_IDE = CAN_Id_Standard;
            Tx_RTR = CAN_RTR_Data;
            Tx_DLC = 1;
            Tx_Data[0] = Key_Pressed_Number;

            /* Sender send Frame */
            status = CAN_Transmit(Tx_Id,Tx_IDE,Tx_RTR,Tx_DLC,Tx_Data);

            /* while key is not pressed, loop*/
            Key_status= Key_NoPressed;
        }
    }
}