Ejemplo n.º 1
0
void      RCC_INIT(void)
{
	 CLK->ICKR |= CLK_ICKR_HSIEN;
//	CLK_HSICmd(ENABLE);
	CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
	CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
//	CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1,ENABLE);  //串口1时钟开
//	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1,ENABLE);  //定时器时钟1开	
//	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2,  ENABLE);  
	CLK->PCKENR1 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_PERIPHERAL_UART1 & (uint8_t)0x0F));
	CLK->PCKENR1 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_PERIPHERAL_TIMER1 & (uint8_t)0x0F));
	CLK->PCKENR1 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_PERIPHERAL_TIMER2 & (uint8_t)0x0F));

}
Ejemplo n.º 2
0
int main()
{
    __disable_interrupt();
    //InitQueue(&uart_rx_cirqueue);
    //InitQueue(&uart_tx_cirqueue);

    CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
    //GPIO_Init(GPIOD, GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_SLOW);
    GPIO_INIT();//led
    GPIO_Init(GPIOD, GPIO_PIN_2,GPIO_MODE_OUT_PP_HIGH_FAST);//开启U10的控制引脚
    pir_RI_io_init();//pir中断
    T4_Init();
    //Uart_Init();

    CommInit();
    /*AWU configuration --------------------------------------------*/
    AWU_Config();


    OSInit();
    CommBufInit();//创建信号量的操作不能再OSInit();之前,也就是不能在OS_InitEventList();之前


    OSTaskCreate( task0, (void *)OS_TASK_0_STK_SIZE, &Task0Stack[OS_TASK_0_STK_SIZE-1], OS_TASK_0_PRIO );
    OSTaskCreate( task1, (void *)OS_TASK_1_STK_SIZE, &Task1Stack[OS_TASK_1_STK_SIZE-1], OS_TASK_1_PRIO );
    //OSTaskCreate( task2, (void *)OS_TASK_2_STK_SIZE, &Task2Stack[OS_TASK_2_STK_SIZE-1], OS_TASK_2_PRIO );

    OSStart();
    return	0;
}
Ejemplo n.º 3
0
int main(void) {

	// Initialise the clock to have a /1 prescaler and use the external crystal clock source for accuracy.
	CLK_DeInit();
	CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
	CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
	
	// Reset ("de-initialise") GPIO port D.
	GPIO_DeInit(GPIOD);
	// Initialise pin 0 of port D by setting it as:
	// - an output pin,
	// - using a push-pull driver,
	// - at a low logic level (0V), and
	// - 10MHz.
	GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
	
	LCDInit(); // Init the LCD
	DecodeInit(); // Init the GPS decoding
	DrawScreen(); // Setup Screen and Buffer
	
	// Infinite loop.
	for(;;) {
		// Blink Debug LED
		GPIO_WriteReverse(GPIOD, GPIO_PIN_0);
		
		DrawDemo();	
	}
}
Ejemplo n.º 4
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  uint8_t i = 0;
  
  /* Select fCPU = 16MHz */
  CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
  
  /* Init the Eval board LCD */
  STM8S_EVAL_LCD_Init();

  /* Clear LCD */
  LCD_Clear();

  LCD_SetCursorPos(LCD_LINE1, 0);
  LCD_Print("SPI-LCD example");		
  
  /* Display "moving" ST logo */
  for (i = 1; i < 8; i++)
  {
    PrintLogo();
    Delay(0xFFFF);
  }
  
  LCD_SetCursorPos(LCD_LINE2, 0);
  LCD_Print("               ");

  LCD_DisplayLogo(0x93);
  Delay(600);
  while(1)
  {}

}
Ejemplo n.º 5
0
//设置内部时钟16M为主时钟 
//输入参数:无
//输出参数:无
void Set_HSI(void)  
{
  //CLK_DeInit();     //恢复默认设置 
  CLK_HSICmd(ENABLE);   //内部时钟开
  while(SET != CLK_GetFlagStatus(CLK_FLAG_HSIRDY)); //等待内部时钟稳定
  CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);  //不分频,16M
  CLK_ClockSwitchCmd(ENABLE);   //时钟切换使能
  //切换配置
  CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO,CLK_SOURCE_HSI,DISABLE,CLK_CURRENTCLOCKSTATE_DISABLE);
}
Ejemplo n.º 6
0
void clockInit(void)
{
  /* Turn on internal high speed clock and use it */
  CLK_HSICmd(ENABLE);
  CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
  CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, 
                        CLK_SOURCE_HSI, 
                        ENABLE, 
                        CLK_CURRENTCLOCKSTATE_ENABLE);
  CLK_LSICmd(DISABLE);
}
Ejemplo n.º 7
0
// 初始化系统时钟
void system_config_clk_init(void)
{
    //clock_config(16); // 内部时钟16M    
    clock_config(8); // 内部时钟8M

#if 0
    CLK_DeInit();
    CLK_FastHaltWakeUpCmd(ENABLE);
    CLK_HSECmd(DISABLE);
    CLK_HSICmd(ENABLE);
    CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV4);
#endif
}
Ejemplo n.º 8
0
/**
  * @brief  Configure system clock to run at Maximum clock speed and output the 
  *         system clock on CCO pin
  * @param  None
  * @retval None
  */
static void CLK_Config(void)
{
    ErrorStatus status = FALSE;

    CLK_DeInit();

    /* Configure the Fcpu to DIV1*/
    CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
    
    /* Configure the HSI prescaler to the optimal value */
    CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);

    /* Output Fcpu on CLK_CCO pin */
    CLK_CCOConfig(CLK_OUTPUT_CPU);
        
    /* Configure the system clock to use HSE clock source and to run at 24Mhz */
    status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
    
    while (ButtonPressed == FALSE)
    {
    }
    /* Configure the system clock to use HSI clock source and to run at 16Mhz */
    status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
}
Ejemplo n.º 9
0
/**
  * @brief  Configure system clock to run at 16Mhz
  * @param  None
  * @retval None
  */
void CLK_Config(void)
{
    /* Initialization of the clock */
    /* Clock divider to HSI/1 */
	CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
	CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
	CLK_HSICmd(ENABLE);
	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, ENABLE);	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE);	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER3, ENABLE);	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4, ENABLE);	
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, ENABLE);
	#ifdef __DEBUG__
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART3, ENABLE);
	#endif
}
Ejemplo n.º 10
0
/********************************************************************************
* clk_setup																		*
********************************************************************************/
void _Device_System_clk_setup(void)
{
	CLK_HSIPrescalerConfig(dSourceFreqDivided); // fMaster, speed 16MHz / 4 = 4MHz, for peripheral device
	CLK_SYSCLKConfig(dMCUFreqDivided); // CPU speed, 4MHz / 1 = 4MHz
    
    // I2C 
	//CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, ENABLE);
	// V_BAT, T_SENSOR, I_CHARGE, I_DISCHARGE
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, ENABLE);
	// LED 1 ~ 4, PWM
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, ENABLE);
	// LED 0, PWM
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE);
	// tick
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4, ENABLE);
	// UART
	CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART2, ENABLE);
    
//  GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
//  CLK_CCOConfig(CLK_OUTPUT_CPUDIV8);
//    CLK_CCOConfig(CLK_OUTPUT_CPU);
//  CLK_CCOCmd(ENABLE); 
    /* Output Fcpu on CLK_CCO pin */
    //CLK_CCOConfig(CLK_OUTPUT_CPU);
    
//    
//    //Lsi
//    unsigned char status;
//    CLK_ClockSwitchCmd(ENABLE);
//    status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_LSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE); 
//    
//    while(status == 0);
    //CLK_ClockSwitchConfig(CLK_SWITCHMODE_MANUAL, CLK_SOURCE_LSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);    
    //CLK_LSICmd(ENABLE);
    //CLK_HSECmd(DISABLE);
    
//    //hsi
//    CLK_ClockSwitchCmd(ENABLE);
//    CLK_HSICmd(ENABLE);
//    CLK_LSICmd(DISABLE);
//    CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);	
    
}
Ejemplo n.º 11
0
void dev_clkInit(void)
{
	CLK_DeInit();
	CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
		
	/*
	#if (STM8_FREQ_MHZ > 16)
		// Set High Speed External 24MHz
		CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, DISABLE); 
	#else
		// Set High Speed Internal 16MHz
		CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
	#endif
	*/
	
	// tolto sopra
	// usa HSE anche se = 16
	// nel nostro caso quarzo esterno da 16 MHz
	CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, DISABLE); 
}
Ejemplo n.º 12
0
void main(void)
{ 
  /* select Clock = 4 MHz */
  CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV4);
  CLK_HSICmd(ENABLE);
  
  
  /* The counter value is initialized to 0.*/
  counter = 0;
  LoadValueIntoSinStruct();           
  
  /* TIM1 configuration -----------------------------------------*/
  TIM1_Config();

  /* Enable interrupts*/
  enableInterrupts();        
  
  while(1)
  {}
}  
Ejemplo n.º 13
0
void main(void)
{
  //CFG->GCR |= 0x01; //disable swim pin
  
  /* Configure the Fcpu to DIV1*/
  CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
  
   /* select Clock = 16 MHz */
  CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
  
  /* Configure the system clock to use HSI clock source and to run at 16Mhz */
  CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
  
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
  
  CLK_HSICmd(ENABLE);
  
  FLASH_Config();
  
  EXTI_DeInit();
  
//You should add:
// Define FLASH programming time 
//FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);

//optbyte1 = FLASH_ReadOptionByte(0x4803); //255 by def
//optbyte2 = FLASH_ReadOptionByte(0x4804); //255 by def
/*
if (optbyte != 765)
{
FLASH_Unlock(FLASH_MEMTYPE_DATA);     // unlock data memory by passing the RASS key in the proper order
FLASH_ProgramOptionByte(0x4803, 0xFD);     // byte OPT2 resides at address x4803, write a 1 to bit 7.  This will also write to the NOPT2 complement byte
FLASH_Lock(FLASH_MEMTYPE_DATA);       // re-lock data memory
}
  */
  
  //General purpose timer
  TIM4_Config(); 

  #ifdef DFS_90
  HotAir_Config();
  #endif
  
  #ifndef DFS_90
  GPIO_Init(CONTROL_GPIO_PORT, CONTROL_GPIO_PIN, GPIO_MODE_OUT_PP_LOW_FAST);
  #endif
  
  Temperature_ADC_Config();  
  
  STM_EVAL_SEGInit(SEG1);
  STM_EVAL_SEGInit(SEG2);
  STM_EVAL_SEGInit(SEG3);
  
  STM_EVAL_LEDInit(LEDA);
  STM_EVAL_LEDInit(LEDB);
  STM_EVAL_LEDInit(LEDC);
  STM_EVAL_LEDInit(LEDD);
  STM_EVAL_LEDInit(LEDE);
  STM_EVAL_LEDInit(LEDF);
  STM_EVAL_LEDInit(LEDG);
  STM_EVAL_LEDInit(LEDP);

#ifndef SOLDERING_VAR2
  //STM_EVAL_LEDInit(LEDP);
#endif
//  STM_EVAL_SEGOn(SEG1);
//  STM_EVAL_SEGOn(SEG2);
//  STM_EVAL_SEGOn(SEG3);
//  
//  STM_EVAL_LEDOn(LEDA);
//  STM_EVAL_LEDOn(LEDB);
//  STM_EVAL_LEDOn(LEDC);
//  STM_EVAL_LEDOn(LEDD);
//  STM_EVAL_LEDOn(LEDE);
//  STM_EVAL_LEDOn(LEDF);
//  STM_EVAL_LEDOn(LEDG);
//  
//  STM_EVAL_LEDOff(LEDA);
//  STM_EVAL_LEDOff(LEDB);
//  STM_EVAL_LEDOff(LEDC);
//  STM_EVAL_LEDOff(LEDD);
//  STM_EVAL_LEDOff(LEDE);
//  STM_EVAL_LEDOff(LEDF);
//  STM_EVAL_LEDOff(LEDG);
//  STM_EVAL_LEDOff(LEDP);
//  
//  STM_EVAL_SEGOff(SEG1);
//  STM_EVAL_SEGOff(SEG2);
//  STM_EVAL_SEGOff(SEG3);
  
  
  //STM_EVAL_LEDOn(LEDP);
  //GPIO_Init(ENC_DN_BUTTON_PORT, ENC_DN_BUTTON_PIN, GPIO_MODE_IN_PU_NO_IT);
  //GPIO_Init(ENC_UP_BUTTON_PORT, ENC_UP_BUTTON_PIN, GPIO_MODE_IN_PU_NO_IT);
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);
  STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_GPIO);
  STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_GPIO);
  STM_EVAL_PBInit(BUTTON_REED, BUTTON_MODE_GPIO);
  
  ssegInit();
  
  ssegWriteStr("1.0.1", 5, SEG1);
  
  enableInterrupts();
  
  #ifdef DFS_90
  HotAir_Main();
  #endif
  
  #ifdef SOLDERING_HAKKO_A1321
  Soldering_Main();
  #endif
  
  while(1)
  {
    /*
    #if 0
     for (level = 0; level < calUpperLimit; level +=5)
     {
       Delayms(1);
     }
     
          for (level = calUpperLimit; level > 0; level -=5)
     {
       Delayms(1);
     }
    #else   
    RawData  = GetAdcValue(ADC_SOLDER_TEMP_CHANNEL);
    SmoothData = SmoothData - (LPF_Beta * (SmoothData - RawData));
    level = ((int)SmoothData)*26;
    #endif
    */
  }
}