コード例 #1
0
/*******************************************************************************
* Function Name  : UARTConfiguration
* Description    : Configures the UART.
*                : Configures the HCLK division factor and RTCHSE clock for UART.
* Output         : None
* Return         : None
*******************************************************************************/
static void UARTConfiguration(void)
{
  /* Enable the RTCHSE clock on UART */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_UART, ENABLE);

  /* Set the UART HCLK division factor */
  UART_BRGInit(UART, UART_HCLKdiv16);

  UART_DeInit(UART);

#if defined (USE_MDR32F9Q1_Rev0) || defined (USE_MDR32F9Q1_Rev1)
  /* Configure PORTF pins for data transfer to/from UART */
  PortInitStructure.PORT_Pin   = PORT_Pin_0 | PORT_Pin_1;
  PortInitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PortInitStructure.PORT_FUNC  = PORT_FUNC_OVERRID;
  PortInitStructure.PORT_SPEED = PORT_SPEED_MAXFAST;
  PORT_Init(MDR_PORTF, &PortInitStructure);
#else
#if defined (USE_MDR32F9Q2_Rev0) && !defined (USE_MDR32F9Q2_Rev1)
  PORTBSaveConfig();
#endif /* defined (USE_MDR32F9Q2_Rev0) && !defined (USE_MDR32F9Q2_Rev1) */
  /* Configure PORTB pins for data transfer to/from UART */
  PortInitStructure.PORT_Pin   = PORT_Pin_5 | PORT_Pin_6;
  PortInitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PortInitStructure.PORT_FUNC  = PORT_FUNC_ALTER;
  PortInitStructure.PORT_SPEED = PORT_SPEED_MAXFAST;
  PORT_Init(MDR_PORTB, &PortInitStructure);
#endif /* defined (USE_MDR32F9Q1_Rev0) || defined (USE_MDR32F9Q1_Rev1) */

  /* Enable interrupt on UART */
  NVIC_EnableIRQ(UART_IRQn);
}
コード例 #2
0
void main(void)
#endif
{
  /* Enables the HSI clock for PORTB */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTB, ENABLE);

  /* Configure all unused PORT pins to low power consumption */

  PORT_StructInit(&PORT_InitStructure);
  PORT_InitStructure.PORT_Pin = (PORT_Pin_All & ~(PORT_Pin_0));
  PORT_Init(MDR_PORTB, &PORT_InitStructure);

  /* Configure PORTB pin 10 for output to switch LEDs on/off */

  PORT_InitStructure.PORT_Pin   = PORT_Pin_0;
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;

  PORT_Init(MDR_PORTB, &PORT_InitStructure);

  /* Enables the HSI clock for WWDG */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_WWDG,ENABLE);

  NVIC_EnableIRQ(WWDG_IRQn);

  /* Set WWDG Prescaler value*/
  WWDG_SetPrescaler	(WWDG_Prescaler_8);

  /* Enable WWDG and load start counter value*/
  WWDG_Enable(0x7F);

  /* Enables the WWDG Early Wakeup interrupt */
  WWDG_EnableIT();

  /* Infinite loop */
  for(NumBlink =  0; NumBlink < 15;)
  {
    if (wwdg_flag == SET)
    {
      BlinkLED1(1,30000);
      wwdg_flag = RESET;
    }
  }
  LEDOn(LED1);
  NVIC_DisableIRQ(WWDG_IRQn);
  while(1);
}
コード例 #3
0
void main(void)
#endif
{
  /* Enables the HSI clock for PORTC */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTC, ENABLE);

  /* Configure all unused PORT pins to low power consumption */
  PORT_StructInit(&PORT_InitStructure);
  PORT_InitStructure.PORT_Pin = (PORT_Pin_All & ~(PORT_Pin_0));
  PORT_Init(MDR_PORTC, &PORT_InitStructure);

  /* Configure PORTC pin 0 for output to switch LEDs on/off */
  PORT_InitStructure.PORT_Pin   = PORT_Pin_0;
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;

  PORT_Init(MDR_PORTC, &PORT_InitStructure);

  /* Enables the HSI clock for IWDG */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_IWDG,ENABLE);

  /* Enable IWDG */
  IWDG_Enable();

  /* Enables write access to IWDG_PR,IWDG_RLR registers */
  IWDG_WriteAccessEnable();

  /* Set IWDG Prescaler value */
  IWDG_SetPrescaler(IWDG_Prescaler_128);

  /* Wait when Prescaler Value was updated */
  while (IWDG_GetFlagStatus(IWDG_FLAG_PVU) != 1)
  {
  }

  /* Set IWDG Reload value */
  IWDG_SetReload(0xFFF);

  /* Infinite loop */
  while (1)
  {
    /* Load counter value and blink LED after delay */
    Delay(1000000);
    IWDG_ReloadCounter();
    BlinkLED1(1,30000);
  }
}
コード例 #4
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
uint32_t main(void)
{
  RST_CLK_DeInit();
  /* Select HSI/2 as CPU_CLK source*/
  RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSIdiv2,0);
  /* Periph clocks enable */
  RST_CLK_PCLKcmd((RST_CLK_PCLK_RST_CLK | RST_CLK_PCLK_CAN1),ENABLE);
  RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTD,ENABLE);

  /* Reset PORTD settings */
  PORT_DeInit(MDR_PORTD);

  /* Configure PORTD pins 10,11 for output to switch LED on/off */
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
  PORT_InitStructure.PORT_Pin   = PORT_Pin_10 | PORT_Pin_11;
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;
  PORT_Init(MDR_PORTD, &PORT_InitStructure);

/* CAN transmit at 125Kb/s and receive by polling in loopback mode */
  TestRx = CAN_Polling();
  if (TestRx == FAILED)
  {
    /* Turn on led LED2 */
    LEDOn(LED2);
  }
  else
  {
    /* Turn on led LED1 */
    LEDOn(LED1);
  }

  while(1);
}
コード例 #5
0
ファイル: serial.c プロジェクト: robots/Tgypytool
void main (void)
{
	char ch;       // Used to store character from UART
	unsigned char c;       // Used to store character from UART
	FLADDR bla;

	PCA0MD &= ~0x40;                    // WDTE = 0 (clear watchdog timer
                                       // enable)
	PORT_Init();                        // Initialize Port I/O
	SYSCLK_Init ();                     // Initialize Oscillator
	UART0_Init();

	P3_0 = 1;
	P3_2 = 1;

	EA = 0;

	bla = 0x0000;
	while (1) {
		ch = FLASH_ByteRead(bla);
		c = FLASH_ByteRead(bla);

		printf ("\n0x%x: 0x%x %d", bla , c, c+1);

		bla ++;
		if (bla == 0x3e00) break;
	}

	P3_0 = 1;
	P3_2 = 0;

	 while (1);
}
/* Called from cstartup.s before the kernel is started. */
void LowLevelInitialisation(void)
{
	/* Chip configuration functions from IAR. ********************************/
	/* Disable MMU, enable ICache */
	CP15_Mmu(FALSE);
	CP15_ICache(FALSE);
	CP15_SetVectorBase( (uint32_t )__section_begin( ".intvec" ) );

	/* Set Low vectors mode in CP15 Control Register */
	CP15_SetHighVectors(FALSE);


	/* Chip and board specific configuration functions from Renesas. *********/
	Peripheral_BasicInit();
	STB_Init();
	PORT_Init();
    R_BSC_Init( ( uint8_t ) ( BSC_AREA_CS2 | BSC_AREA_CS3 ) );
    R_INTC_Init();


	CP15_ICache(TRUE);

	/* Start with interrupts enabled. */
    __enable_irq();
    __enable_fiq();
}
コード例 #7
0
/***********************************************************
*   函数说明:系统硬件初始化函数                           *
*   输入:    无                                           *
*   输出:    无                                           *
*   调用函数:Port_Init()  RCC_Configuration()             *
***********************************************************/
void Device_Init(void)
{
	RCC_Configuration();
	get_sig_cfg_param(1);

	PORT_Init();/*此处需要修改  malooei  2012/11/14*/

	USART2_Configuration(); /* 用于连接pc */

	USART1_Configuration(); /* 用于向光纤传输数据 */
	DMA_USART1_Configuration( );

	adc1_dma_cfg();
	ADC1_Configuration();

	//box_tmper_ctrl_init();

#if !USE_PVD_CHECK_POWEROFF
	Exti_Init();
#else
	Exti_Pvd_Init();
#endif

	spi1_cfg4ads8329();
	delay_us(500*1000); /* 240ms, cpu最低工作电压为2.0V, ads8329最低工作电压为2.7V, David */
	init_ads8329();

	TIM3_Configuration();

	NVIC_Configuration();

	return;
}
コード例 #8
0
ファイル: CG_systeminit.c プロジェクト: 634351070/rt-thread
/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	This function initializes each macro.
**
**  Parameters:
**	None
**
**  Returns:
**	None
**
**-----------------------------------------------------------------------------
*/
void systeminit(void)
{
	DI();	/* disable interrupt */
	CG_ReadResetSource();
	PORT_Init();
	TAB0_Init();
	EI();	/* enable interrupt */
}
コード例 #9
0
void main (void) 
{
	float period;
	
	PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer enable)
	PORT_Init();     // Initialize Port I/O
	SYSCLK_Init ();  // Initialize Oscillator
	UART0_Init();    // Initialize UART0
	TIMER0_Init();

	printf("\x1b[2J"); // Clear screen using ANSI escape sequence.

	printf ("Period measurement at pin P0.1 using Timer 0.\n"
	        "File: %s\n"
	        "Compiled: %s, %s\n\n",
	        __FILE__, __DATE__, __TIME__);

    while (1)
    {
    	// Reset the counter
		TL0=0; 
		TH0=0;
		TF0=0;
		overflow_count=0;
		
		while(P0_1!=0); // Wait for the signal to be zero
		while(P0_1!=1); // Wait for the signal to be one
		TR0=1; // Start the timer
		while(P0_1!=0) // Wait for the signal to be zero
		{
			if(TF0==1) // Did the 16-bit timer overflow?
			{
				TF0=0;
				overflow_count++;
			}
		}
		while(P0_1!=1) // Wait for the signal to be one
		{
			if(TF0==1) // Did the 16-bit timer overflow?
			{
				TF0=0;
				overflow_count++;
			}
		}
		TR0=0; // Stop timer 0, the 24-bit number [overflow_count-TH0-TL0] has the period!
		period=(overflow_count*65536.0+TH0*256.0+TL0)*(12.0/SYSCLK);
		// Send the period to the serial port
		printf( "\rf=%fs" , period);
		
		heart_rate = 1.0/(period/60.0); 
		bpm = (int) heart_rate; 
		
		LCDprint(bpm, 1, 5); //print heart rate bpm to LCD display
		
    }
  
	
}
コード例 #10
0
ファイル: systeminit.c プロジェクト: jumbotk/02_itou
/*
**-----------------------------------------------------------------------------
**
**	Abstract:
**		This function  initializes every macro.
**
**	Parameters:
**		None
**
**	Returns:
**		None
**
**-----------------------------------------------------------------------------
*/
void SystemInit( void )
{
	WDTM = 0x77;	/* stops watch dog timer */
	/*Process of reset*/
	CG_ReadResetSource();
	/*Initialize the clock generator*/
	CLOCK_Init();
	/*Initialize the I/O ports*/
	PORT_Init();
	/*Initialize TM00 function*/
	TM00_Init();
}
コード例 #11
0
ファイル: basic_func.c プロジェクト: chrisworld/aut
void Basic_Init(void)
{
  Watchdog_Init();            //WatchdogInig
  Clock_Init();               //CLKInit
  TC0_Wait_msWhile(5);        //wait
  PORT_Init();                //PortInit
  CAN_Init();                 //CANInit
  TC0_Wait_msWhile(5);        //wait
  TC0_Stop();                 //StopTimer

  CAN_RXMOb_SetAddr(0x01);    //SetCANAdress
}
コード例 #12
0
ファイル: frdm_slcd_test.c プロジェクト: Capstone46/Freescale
/*******************************************************************************
 * @brief   main routine
 ******************************************************************************/
int main (void)
{  
  SIM_Init (SIM_MODULE_FRDM_SLCD_CONFIG);
  MCG_LITE_Init (MCG_LITE_HIRC_48MHZ);
  
  // OSC module initialization
  OSC_Init(OSC_MODULE_OSCERCLK_ON_STOPMODE_ON_CONFIG(OSC_SC16P));
  MCG_ExtClkType(OSC_REQST);
  MCG_CrystalMode(LOW_POWER_OSC);
  MCG_CrystalFreqRangeSel(LOW_FREQ_RANGE);
  MCG_WaitOscInit();
  
  // VLLx, VCAPx pins disable
  PORT_Init(PORTC, PORT_MODULE_DISABLED_MODE, PIN_20|PIN_21|PIN_22|PIN_23, 0, NULL);
  // SLCD pin configuration
  PORT_Init(PORTE, PORT_MODULE_ALT0_MODE, PIN_20|PIN_21, 0, NULL);
  PORT_Init(PORTB, PORT_MODULE_ALT0_MODE, PIN_18|PIN_19, 0, NULL);
  PORT_Init(PORTC, PORT_MODULE_ALT0_MODE, PIN_0|PIN_4|PIN_6|PIN_7, 0, NULL);
  PORT_Init(PORTD, PORT_MODULE_ALT0_MODE, PIN_0|PIN_2|PIN_3|PIN_4, 0, NULL);
  // SLCD initialization
  LCD_Init (LCD_FRDM_CONFIG,                                                    \
            LCD_FRONT_PLANE_PINS_FRDM_KL43,                                     \
            LCD_BACK_PLANE_PINS_FRDM_KL43,                                      \
            LCD_ASSIGN_BACK_PLANES_FRDM_KL43);
  //LCD_Write_Segments(LCD_ALL_SEGMENTS_OFF_FRDM_KL43);
  LCD_Delete_Char(0);
  LCD_Delete_Char(1);
  LCD_Delete_Char(2);
  LCD_Delete_Char(3);
  // PIT initialization - CH0 for LCD intro text running 
  PIT_Init (PIT0, CH0, PIT_CH_TIMER_EN_CONFIG, 6000000, 1, pit_callback);
  
  __enable_irq();
  
  while (1)
  {
    
  }
}
コード例 #13
0
ファイル: uart1.c プロジェクト: setarcos/f020-sample
void main()
{
    WDTCN=0XDE;
    WDTCN=0XAD;
    SYSCLK_Init();
    PORT_Init();
    UART0_Init();
    while(1)
    {
        SBUF0 = 'A';
        while(!TI0);
        TI0=0;
    }
}
コード例 #14
0
/*******************************************************************************
 * @brief   main routine
 ******************************************************************************/
int main (void)
{  
  SIM_Init (SIM_MODULE_FRDM_RTC_WATCH_CONFIG);
  MCG_LITE_Init (MCG_LITE_HIRC_48MHZ);
  
  // OSC module initialization
  OSC_Init(OSC_MODULE_OSCERCLK_ON_STOPMODE_ON_CONFIG(OSC_SC16P));
  MCG_ExtClkType(OSC_REQST);
  MCG_CrystalMode(LOW_POWER_OSC);
  MCG_CrystalFreqRangeSel(LOW_FREQ_RANGE);
  MCG_WaitOscInit();
  
  // LEDs initialization
  PORT_Init (PORTD, PORT_MODULE_ALT1_MODE, PIN_5, 0, NULL);
  GPIO_Init (GPIOD, GPIO_PIN_OUTPUT, PIN_5);
  GPIO_Set (GPIOD, PIN_5);
  PORT_Init (PORTE, PORT_MODULE_ALT1_MODE, PIN_31, 0, NULL);
  GPIO_Init (GPIOE, GPIO_PIN_OUTPUT, PIN_31);
  GPIO_Set (GPIOE, PIN_31);
  
  // VLLx, VCAPx pins disable
  PORT_Init(PORTC, PORT_MODULE_DISABLED_MODE, PIN_20|PIN_21|PIN_22|PIN_23, 0, NULL);
  // SLCD pin configuration
  PORT_Init(PORTE, PORT_MODULE_ALT0_MODE, PIN_20|PIN_21, 0, NULL);
  PORT_Init(PORTB, PORT_MODULE_ALT0_MODE, PIN_18|PIN_19, 0, NULL);
  PORT_Init(PORTC, PORT_MODULE_ALT0_MODE, PIN_0|PIN_4|PIN_6|PIN_7, 0, NULL);
  PORT_Init(PORTD, PORT_MODULE_ALT0_MODE, PIN_0|PIN_2|PIN_3|PIN_4, 0, NULL);
  // SLCD initialization
  LCD_Init (LCD_FRDM_CONFIG,                                                    \
            LCD_FRONT_PLANE_PINS_FRDM_KL43,                                     \
            LCD_BACK_PLANE_PINS_FRDM_KL43,                                      \
            LCD_ASSIGN_BACK_PLANES_FRDM_KL43);
  LCD_Delete_Char(0);
  LCD_Delete_Char(1);
  LCD_Delete_Char(2);
  LCD_Delete_Char(3);
  
  // Set the time according to system clock
  BUILD_DATE_TIME(time);
  // RTC initialization
  RTC_Init (RTC_MODULE_FRDM_RTC_WATCH_CONFIG, RTC_MkTime (&time), 3, rtc_callback);
  RTC_SetAlarm (RTC_GetTime ()+alarm_interval);
  // Write time to the LCD
  lcd_settime(&time);
  
  __enable_irq();
  
  while (1)
  {
    
  }
}
コード例 #15
0
int main()
{
	PORT_Init();
	UART_Init(19200);
	while (1)
	{
		PrintWelcome();

		while (1)
		{
			AcceptCommands();
			EvaluateStatus(UPDATE_ONLY_ON_CHANGE);
		}			
	}
	return 0;
}
コード例 #16
0
ファイル: vs1003.c プロジェクト: setarcos/f020-sample
void main()
{
    unsigned int i;
    WDTCN=0xDE;
    WDTCN=0xAD;
    SYSCLK_Init();
    PORT_Init();
    SPI0_Init();

    Mp3Reset();
    P7 &= ~0x40;
    for (i = 0; i < 15000; ++i)
        send_dat(music[i]);
    flush_buffer();
    while(1);
}
コード例 #17
0
ファイル: led.c プロジェクト: davel/minimus32_demo
int main(void)
{
    PORT_Init();
    asm("WDR");                     //Watchdog Timer Reset
    WDTCSR = 0x00;                  // Disable the watchdog
    WDTCKD = 0x00;                  // No early warnings either

    while (1)
    {
        if (PIND &  0b10000000) {
            PORTD = 0b00100000;
        }
        else {
            PORTD = 0b01000000;
        }
    }
    return 0;
}
コード例 #18
0
/**
  * @brief
  * @param	None
  * @retval	None
  */
void DebugUARTInit()
{
	UART_InitTypeDef UART_InitStructure;
	uint32_t BaudRateStatus;
#if defined (USE_MDR1986VE3)
	RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTD | RST_CLK_PCLK_UART2), ENABLE);
#elif defined (USE_MDR1986VE9x)
	RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTF | RST_CLK_PCLK_UART2), ENABLE);
#elif defined (USE_MDR1986VE1T)
	RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTC | RST_CLK_PCLK_UART1), ENABLE);
#endif

	/* Port Init Struture */
	PORT_InitStructure.PORT_Pin = DEBUG_UART_PINS;
	PORT_InitStructure.PORT_FUNC = DEBUG_UART_PINS_FUNCTION;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_SPEED = PORT_SPEED_MAXFAST;
	PORT_InitStructure.PORT_PD = PORT_PD_DRIVER;

	PORT_Init(DEBUG_UART_PORT, &PORT_InitStructure);

	UART_DeInit(DEBUG_UART);

  	/* UART	Init Structure */
	UART_InitStructure.UART_BaudRate            = DEBUG_BAUD_RATE;
	UART_InitStructure.UART_WordLength          = UART_WordLength8b;
	UART_InitStructure.UART_StopBits            = UART_StopBits1;
	UART_InitStructure.UART_Parity              = UART_Parity_No;
	UART_InitStructure.UART_FIFOMode            = UART_FIFO_ON;
	UART_InitStructure.UART_HardwareFlowControl = ( UART_HardwareFlowControl_RXE |
											   UART_HardwareFlowControl_TXE );

	/* ----- Инициализация UART ----- */
	UART_BRGInit(DEBUG_UART, UART_HCLKdiv1);
        BaudRateStatus = UART_Init(DEBUG_UART, &UART_InitStructure);
	if(BaudRateStatus == BaudRateValid){
		UART_Cmd(DEBUG_UART,ENABLE);
	}
	else{
		while(1);
	}
	DEBUG_PRINTF("==============System startup==============\n\r");
	DEBUG_PRINTF("Init Debug UART ... Ok\r\n");
}
コード例 #19
0
void PowerMonitor_Init(void) {
    uint32_t temp32u;
	
    COMP_InitTypeDef COMP_InitStructure;
    COMP_CVRefInitTypeDef COMP_CVRefInitStructure;
    PORT_InitTypeDef PORT_InitStructure;
    
    COMP_StructInit(&COMP_InitStructure);
    COMP_InitStructure.COMP_PlusInputSource = COMP_PlusInput_CVREF;  
    COMP_InitStructure.COMP_MinusInputSource = COMP_MinusInput_IN1;
    COMP_Init(&COMP_InitStructure);
    
    COMP_CVRefStructInit(&COMP_CVRefInitStructure);
    COMP_CVRefInitStructure.COMP_CVRefSource = COMP_CVREF_SOURCE_AVdd;
    COMP_CVRefInitStructure.COMP_CVRefRange = COMP_CVREF_RANGE_Up;
    COMP_CVRefInitStructure.COMP_CVRefScale = COMP_CVREF_SCALE_14_div_32;
    COMP_CVRefInit(&COMP_CVRefInitStructure);
    
    COMP_Cmd(ENABLE); 
    COMP_CVRefCmd(ENABLE);    
    while(COMP_GetCfgFlagStatus(COMP_CFG_FLAG_READY) != SET);
    
    // Setup GPIO
    PORT_StructInit(&PORT_InitStructure);
    PORT_InitStructure.PORT_Pin = (1 << POWER_MONITOR_PIN);
	PORT_Init(POWER_MONITOR_PORT, &PORT_InitStructure);
    
	// Wait until power supply is stable
	temp32u = DWT_StartDelayUs(50000);
	while (DWT_DelayInProgress(temp32u)) {
		if (COMP_GetFlagStatus(COMP_STATUS_FLAG_SY) == SET) {
			// False triggering - restart delay
			temp32u = DWT_StartDelayUs(50000);
		}
	}
    // Read and clear comparator result latch
    COMP_GetResultLatch();
	
    COMP_ITConfig(ENABLE);
	
	NVIC_EnableIRQ(COMPARATOR_IRQn);
}
コード例 #20
0
ファイル: exam.c プロジェクト: bigclean/wzupwm
/*!
 * \fn main()
 * \brief just to test PWM module
 * \return none
 */
int main()
{
	PCA0MD = 0x00;
	PORT_Init();
	OSCILLATOR_Init();
	PCA0_Init();
	timer_0_1_init();
	timer2_init();
	IN1 = 0;
	IN2 = 1;
	IN3 = 0;
	IN4 = 1;
	EA = 1;
	//set_pwm_0_duty_cycle(20);
	//set_pwm_1_duty_cycle(16);
	while (1)
	{
		//set_pwm_0_duty_cycle(700);
		//set_pwm_1_duty_cycle(660);
		set_wheel_1_speed(50);
		set_wheel_0_speed(50);
	}
}
コード例 #21
0
ファイル: Zoetrope.c プロジェクト: iburol/Arduino-C
void main(void)
{
	PORT_Init ();
	TIMER1_Init();
	ADC_Init();
	INT0_Init ();
	INT1_Init ();
	
	//Habilitación de interrupciones
	sei();
	
	while(1)
	{
		if (cont_INT0 == 1 || cont_INT1 == 1)
		{
			//Nueva conversión
			startConversion();
		}
		//No interrupción externa INT0
		if (FlagINT == false)
		{
			//Habilitación de interrupción externa INT0
			EIMSK |= (1 << INT0);
			//Habilitación de interrupción externa INT1
			EIMSK |= (1 << INT1);
		}
		//Interrupción externa INT0
		else
		{
			//Espera de 40 ms
			_delay_ms(40);
			//Terminación de atención interrupción externa INT0
			FlagINT = false;
		}
	}
}
コード例 #22
0
void main (void)
{
    SFRPAGE = ACTIVE_PAGE;              // Change for PCA0MD

    PCA0MD &= ~0x40;                    // Disable watchdog timer

    PORT_Init ();                       // Initialize Port I/O
    SYSCLK_Init ();                     // Initialize Oscillator
    UART0_Init ();                      // Initialize UART

    EA = 1;                             // Enable global interrutpts

    while (1)
    {
        // If the complete word has been entered via the terminal followed by
        // carriage return

        if((TX_Ready == 1) && (UART_Buffer_Size != 0) && (Byte == 13))
        {
            TX_Ready = 0;                 // Set the flag to zero
            TI0 = 1;                      // Set transmit flag to 1
        }
    }
}
コード例 #23
0
void main(void)
#endif
{
  RST_CLK_DeInit();
  RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSIdiv2,0);
  /* Enable peripheral clocks --------------------------------------------------*/
  RST_CLK_PCLKcmd((RST_CLK_PCLK_RST_CLK | RST_CLK_PCLK_SSP1 | RST_CLK_PCLK_SSP2 | RST_CLK_PCLK_DMA),ENABLE);
  RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTF | RST_CLK_PCLK_PORTD), ENABLE);

  /* Init NVIC */
  SCB->AIRCR = 0x05FA0000 | ((uint32_t)0x500);
  SCB->VTOR = 0x08000000;
  /* Disable all interrupt */
  NVIC->ICPR[0] = 0xFFFFFFFF;
  NVIC->ICER[0] = 0xFFFFFFFF;

  /* Disable all DMA request */
  MDR_DMA->CHNL_REQ_MASK_CLR = 0xFFFFFFFF;
  MDR_DMA->CHNL_USEBURST_CLR = 0xFFFFFFFF;

  /* Reset PORTD settings */
  PORT_DeInit(MDR_PORTD);
  /* Reset PORTF settings */
  PORT_DeInit(MDR_PORTF);

  /* Configure SSP2 pins: FSS, CLK, RXD, TXD */

  /* Configure PORTD pins 2, 3, 5, 6 */
  PORT_InitStructure.PORT_Pin   = (PORT_Pin_2 | PORT_Pin_3 | PORT_Pin_5);
  PORT_InitStructure.PORT_OE    = PORT_OE_IN;
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_ALTER;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_FAST;
  PORT_Init(MDR_PORTD, &PORT_InitStructure);
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_Pin   = (PORT_Pin_6);
  PORT_Init(MDR_PORTD, &PORT_InitStructure);

  /* Configure SSP1 pins: FSS, CLK, RXD, TXD */

  /* Configure PORTF pins 0, 1, 2, 3 */
  PORT_InitStructure.PORT_Pin   = (PORT_Pin_3);
  PORT_InitStructure.PORT_OE    = PORT_OE_IN;
  PORT_Init(MDR_PORTF, &PORT_InitStructure);
  PORT_InitStructure.PORT_Pin   = (PORT_Pin_0 | PORT_Pin_1 | PORT_Pin_2);
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_Init(MDR_PORTF, &PORT_InitStructure);


  /* Init RAM */
  Init_RAM (DstBuf1, BufferSize);
  Init_RAM (SrcBuf1, BufferSize);
  Init_RAM (DstBuf2, BufferSize);
  Init_RAM (SrcBuf2, BufferSize);

  /* Reset all SSP settings */
  SSP_DeInit(MDR_SSP1);
  SSP_DeInit(MDR_SSP2);

  SSP_BRGInit(MDR_SSP1,SSP_HCLKdiv16);
  SSP_BRGInit(MDR_SSP2,SSP_HCLKdiv16);

  /* SSP1 MASTER configuration ------------------------------------------------*/
  SSP_StructInit (&sSSP);

  sSSP.SSP_SCR  = 0x10;
  sSSP.SSP_CPSDVSR = 2;
  sSSP.SSP_Mode = SSP_ModeMaster;
  sSSP.SSP_WordLength = SSP_WordLength16b;
  sSSP.SSP_SPH = SSP_SPH_1Edge;
  sSSP.SSP_SPO = SSP_SPO_Low;
  sSSP.SSP_FRF = SSP_FRF_SPI_Motorola;
  sSSP.SSP_HardwareFlowControl = SSP_HardwareFlowControl_SSE;
  SSP_Init (MDR_SSP1,&sSSP);

  /* SSP2 SLAVE configuration ------------------------------------------------*/
  sSSP.SSP_SPH = SSP_SPH_1Edge;
  sSSP.SSP_SPO = SSP_SPO_Low;
  sSSP.SSP_CPSDVSR = 12;
  sSSP.SSP_Mode = SSP_ModeSlave;
  SSP_Init (MDR_SSP2,&sSSP);

  /* Enable SSP1 DMA Rx and Tx request */
  SSP_DMACmd(MDR_SSP1,(SSP_DMA_RXE | SSP_DMA_TXE), ENABLE);
  /* Enable SSP2 DMA Rx and Tx request */
  SSP_DMACmd(MDR_SSP2,(SSP_DMA_RXE | SSP_DMA_TXE), ENABLE);

  /* Reset all DMA settings */
  DMA_DeInit();
  DMA_StructInit(&DMA_InitStr);

  /* DMA_Channel_SSP1_RX configuration ---------------------------------*/
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)(&(MDR_SSP1->DR));
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)DstBuf1;
  DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncNo;
  DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncHalfword;
  DMA_PriCtrlStr.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_PriCtrlStr.DMA_Mode = DMA_Mode_Basic;
  DMA_PriCtrlStr.DMA_CycleSize = BufferSize;
  DMA_PriCtrlStr.DMA_NumContinuous = DMA_Transfers_4;
  DMA_PriCtrlStr.DMA_SourceProtCtrl = DMA_SourcePrivileged;
  DMA_PriCtrlStr.DMA_DestProtCtrl = DMA_DestPrivileged;
  /* Set Channel Structure */
  DMA_InitStr.DMA_PriCtrlData = &DMA_PriCtrlStr;
  DMA_InitStr.DMA_Priority = DMA_Priority_High;
  DMA_InitStr.DMA_UseBurst = DMA_BurstClear;
  DMA_InitStr.DMA_SelectDataStructure = DMA_CTRL_DATA_PRIMARY;
  /* Init DMA channel */
  DMA_Init(DMA_Channel_SSP1_RX, &DMA_InitStr);

  /* DMA_Channel_SSP2_RX configuration ---------------------------------*/
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)(&(MDR_SSP2->DR));
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)DstBuf2;
  /* Init DMA channel */
  DMA_Init(DMA_Channel_SSP2_RX, &DMA_InitStr);

  /* DMA_Channel_SSP1_TX configuration ---------------------------------*/
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)SrcBuf1;
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)(&(MDR_SSP1->DR));
  DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncHalfword;
  DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncNo;
  DMA_InitStr.DMA_Priority = DMA_Priority_Default;
  /* Init DMA channel */
  DMA_Init(DMA_Channel_SSP1_TX, &DMA_InitStr);

  /* DMA_Channel_SSP2_TX configuration ---------------------------------*/
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)SrcBuf2;
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)(&(MDR_SSP2->DR));
  /* Init DMA channel */
  DMA_Init(DMA_Channel_SSP2_TX, &DMA_InitStr);

  /* Enable SSP1 */
  SSP_Cmd(MDR_SSP1, ENABLE);
  /* Enable SSP2 */
  SSP_Cmd(MDR_SSP2, ENABLE);

  /* Transfer complete */
  while((SSP_GetFlagStatus(MDR_SSP1, SSP_FLAG_BSY)))
  {
  }
  while((SSP_GetFlagStatus(MDR_SSP2, SSP_FLAG_BSY)))
  {
  }

  /* Check the corectness of written dada */
  TransferStatus1 = Verif_mem ((BufferSize), SrcBuf1, DstBuf2);
  TransferStatus2 = Verif_mem ((BufferSize), SrcBuf2, DstBuf1);
  /* TransferStatus1, TransferStatus2 = PASSED, if the data transmitted and received
     are correct */
  /* TransferStatus1, TransferStatus2 = FAILED, if the data transmitted and received
     are different */

  while(1)
  {
  }
}
コード例 #24
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main (void)
{
uint32_t Address;
uint32_t BankSelector;
uint32_t Data;
int i;
uint8_t EraseErrMM=0;
uint8_t WriteErrMM=0;
uint8_t EraseErrIM=0;
uint8_t WriteErrIM=0;

  /* Enables the clock on PORTD */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTD, ENABLE);

  /* Enables the  clock on EEPROM */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_EEPROM, ENABLE);

  /* Configure PORTD pins 10..14 for output to switch LEDs on/off */
  PORT_InitStructure.PORT_Pin   = (PORT_Pin_10 | PORT_Pin_11 | PORT_Pin_12 | PORT_Pin_13 | PORT_Pin_14);
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;
  PORT_Init(MDR_PORTD, &PORT_InitStructure);

  /* Erase main memory page 0 */
  Address = 0x08000000;
  BankSelector = 0;
  EEPROM_ErasePage (Address,BankSelector);

  /* Check main memory page 0 */
  Data = 0xFFFFFFFF;
  for (i=0;i<1024;i++)
  {
    if (EEPROM_ReadWord (Address+i*4,BankSelector) != Data) EraseErrMM = 1;
  }

  /* Indicate status of erasing main memory page 0*/
  if (EraseErrMM == 0)
  {
    PORT_SetBits(MDR_PORTD, PORT_Pin_10);
  }

  /* Fill main memory page 0 */
  Address = 0x08000000;
  BankSelector = 0;
  for (i=0;i<1024;i++)
  {
    Data = Pseudo_Rand (Address+i*4);
    EEPROM_ProgramWord (Address+i*4,BankSelector,Data);
  }

  /* Check main memory page 0 */
  Address = 0x08000000; BankSelector = 0;
  for (i=0;i<1024;i++)
  {
    Data = Pseudo_Rand (Address+i*4);
    if (EEPROM_ReadWord (Address+i*4,BankSelector) != Data)
    {
      WriteErrMM = 1;
    }
  }

  /* Indicate status of writing main memory page 0*/
  if (WriteErrMM == 0)
  {
    PORT_SetBits(MDR_PORTD, PORT_Pin_11);
  }

  /* Full Erase information memory */
  Address = 0x08000000;
  BankSelector = 1;
  EEPROM_EraseAllPages (BankSelector);

  /* Check information memory */
  Data = 0xFFFFFFFF;
  for (i=0;i<1024;i++)
  {
    if (EEPROM_ReadWord (Address+i*4,BankSelector) != Data)
    {
      EraseErrIM = 1;
    }
  }
  /* Indicate status of erasing information memory */
  if (EraseErrIM == 0)
  {
    PORT_SetBits(MDR_PORTD, PORT_Pin_12);
  }

  /* fill information memory */
  Address = 0x08000000;
  BankSelector = 1;
  for (i=0;i<1024;i++)
  {
    Data = Pseudo_Rand (Address+i*4);
    EEPROM_ProgramWord (Address+i*4,BankSelector,Data);
  }

  /* Check information memory */
  Address = 0x08000000;
  BankSelector = 1;
  for (i=0;i<1024;i++)
  {
    Data = Pseudo_Rand (Address+i*4);
    if(EEPROM_ReadWord (Address+i*4,BankSelector) != Data)
    {
      WriteErrIM = 1;
    }
  }

  /* Indicate status of writing information memory */
  if (WriteErrIM == 0)
  {
    PORT_SetBits(MDR_PORTD, PORT_Pin_13);
  }

  while (1)
  {
  }
}
コード例 #25
0
/*******************************************************************************
* Function Name  : Demo_Init
* Description    : Initializes the demonstration application
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Demo_Init(void)
{
  ClockConfigure();

/************************ LCD Initialization *************************/

  /* Configure LCD_DATA_PORT for data transfer to/from LCD */
  PortInitStructure.PORT_Pin = LCD_DATA_BAS_8_0;
  PortInitStructure.PORT_FUNC = PORT_FUNC_PORT;
  PortInitStructure.PORT_OE = PORT_OE_IN;
  PortInitStructure.PORT_SPEED = PORT_SPEED_SLOW;
  PortInitStructure.PORT_MODE = PORT_MODE_DIGITAL;

  PORT_Init(LCD_DATA_PORT_0, &PortInitStructure);
  PortInitStructure.PORT_Pin = LCD_DATA_BAS_8_1;
  PORT_Init(LCD_DATA_PORT_1, &PortInitStructure);

  /* Configure LCD_RD_WR_PORT for read/write control */
  /* Switch LCD into data output mode */
  PORT_SetBits(LCD_RD_WR_PORT, LCD_RD_WR_PIN);

  PortInitStructure.PORT_Pin = LCD_RD_WR_PIN;
  PortInitStructure.PORT_OE = PORT_OE_OUT;

  PORT_Init(LCD_RD_WR_PORT, &PortInitStructure);

  /* Configure LCD_CLOCK_PORT for CLOCK signal control*/
  /* Set LCD CLOCK signal to its initial value (0) */
  PORT_ResetBits(LCD_CLOCK_PORT, LCD_CLOCK_PIN);

  PortInitStructure.PORT_Pin = LCD_CLOCK_PIN;
  PortInitStructure.PORT_SPEED = PORT_SPEED_FAST;

  PORT_Init(LCD_CLOCK_PORT, &PortInitStructure);

  /* Configure LCD_CRYSTAL_PORT for LCD crystal control */
  /* De-select both LCD crystals*/
  PORT_ResetBits(LCD_CRYSTAL_PORT, LCD_CRYSTAL_PINs);

  PortInitStructure.PORT_Pin = LCD_CRYSTAL_PINs;
  PortInitStructure.PORT_SPEED = PORT_SPEED_SLOW;

  PORT_Init(LCD_CRYSTAL_PORT, &PortInitStructure);

  /* Configure LCD_CMD_DATA_PORT for data/command mode switching */
  PortInitStructure.PORT_Pin = LCD_CMD_DATA_PIN;

  PORT_Init(LCD_CMD_DATA_PORT, &PortInitStructure);

  /* Configure LCD_RESET_PORT for RESET signal control */
  /* Zeroing LCD RES signal (initial state) */
  PORT_ResetBits(LCD_RESET_PORT, LCD_RESET_PIN);

  PortInitStructure.PORT_Pin = LCD_RESET_PIN;
  PortInitStructure.PORT_SPEED = PORT_SPEED_FAST;

  PORT_Init(LCD_RESET_PORT, &PortInitStructure);

  LCD_INIT();

/************************ Joystick Initialization *************************/

  /* Configure SEL_PORT for input to handle joystick event SEL */
  PortInitStructure.PORT_Pin   = SEL_PIN;
  PortInitStructure.PORT_OE    = PORT_OE_IN;
  PortInitStructure.PORT_FUNC  = PORT_FUNC_PORT;
  PortInitStructure.PORT_SPEED = PORT_SPEED_SLOW;

  PORT_Init(SEL_PORT, &PortInitStructure);

  /* Configure UP_PORT for input to handle joystick event UP */
  PortInitStructure.PORT_Pin   = UP_PIN;

  PORT_Init(UP_PORT, &PortInitStructure);

  /* Configure DOWN_PORT for input to handle joystick event DOWN */
  PortInitStructure.PORT_Pin   = DOWN_PIN;

  PORT_Init(DOWN_PORT, &PortInitStructure);

  /* Configure LEFT_PORT for input to handle joystick event LEFT */
  PortInitStructure.PORT_Pin   = LEFT_PIN;

  PORT_Init(LEFT_PORT, &PortInitStructure);

  /* Configure RIGHT_PORT for input to handle joystick event RIGHT */
  PortInitStructure.PORT_Pin   = RIGHT_PIN;

  PORT_Init(RIGHT_PORT, &PortInitStructure);

/************************ LEDs Initialization *************************/

  /* Configure LEDs_PORT for output to switch LEDs on/off */
  PortInitStructure.PORT_Pin   = LEDs_PINs;
  PortInitStructure.PORT_OE    = PORT_OE_OUT;
  PortInitStructure.PORT_FUNC  = PORT_FUNC_PORT;

  PORT_Init(LEDs_PORT, &PortInitStructure);

  /* All LEDs switch off */
  PORT_ResetBits(LEDs_PORT, LEDs_PINs);
}
コード例 #26
0
void main(void)
#endif
{
  /* Enables the HSI clock on PORTD */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTD, ENABLE);

  /* Configure all unused PORT pins to low power consumption */
  PORT_StructInit(&PORT_InitStructure);
  PORT_InitStructure.PORT_Pin = (PORT_Pin_All & ~(PORT_Pin_10 | PORT_Pin_11));
  PORT_Init(MDR_PORTD, &PORT_InitStructure);


  /* Configure PORTD pins 10..11 for output to switch LEDs on/off */
  PORT_InitStructure.PORT_Pin   = (PORT_Pin_10 | PORT_Pin_11);
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;

  PORT_Init(MDR_PORTD, &PORT_InitStructure);

  /* Enables the HSI clock for BKP control */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_BKP,ENABLE);

  /* RTC reset */
  BKP_RTC_Reset(ENABLE);
  BKP_RTC_Reset(DISABLE);

#ifdef RTC_HSI_CLK
  /* Configure RTCHSI as RTC clock source */
  RST_CLK_HSIadjust(25);
  RST_CLK_HSIclkPrescaler(RTCHS_PRESC);
  BKP_RTCclkSource(BKP_RTC_HSIclk);
  RST_CLK_RTC_HSIclkEnable(ENABLE);
#endif
#ifdef RTC_HSE_CLK
  /* Configure RTCHSE as RTC clock source */
  RST_CLK_HSEconfig(RST_CLK_HSE_ON);
  while (RST_CLK_HSEstatus()!=SUCCESS);
  RST_CLK_RTC_HSEclkEnable(ENABLE);
  RST_CLK_HSEclkPrescaler(RTCHS_PRESC);
  BKP_RTCclkSource(BKP_RTC_HSEclk);
#endif
#ifdef RTC_LSI_CLK
  /* Configure LSI as RTC clock source */
  RST_CLK_LSIadjust(12);
  BKP_RTCclkSource(BKP_RTC_LSIclk);
  while (RST_CLK_LSIstatus()!=SUCCESS);
#endif
#ifdef RTC_LSE_CLK
  /* Configure LSE as RTC clock source */
  RST_CLK_LSEconfig(RST_CLK_LSE_ON);
  while (RST_CLK_LSEstatus()!=SUCCESS);
  BKP_RTCclkSource(BKP_RTC_LSEclk);
#endif

  /* Set the RTC prescaler value */
  BKP_RTC_WaitForUpdate();
#ifdef RTC_HSI_CLK
  BKP_RTC_SetPrescaler(PRESC_VALUE_HS);
#endif
#ifdef RTC_HSE_CLK
  BKP_RTC_SetPrescaler(PRESC_VALUE_HS);
#endif
#ifdef RTC_LSI_CLK
  BKP_RTC_SetPrescaler(PRESC_VALUE_LS);
#endif
#ifdef RTC_LSE_CLK
  BKP_RTC_SetPrescaler(PRESC_VALUE_LS);
#endif

  /* Set the RTC alarm value */
  BKP_RTC_WaitForUpdate();
  BKP_RTC_SetAlarm(ALARM_VALUE);

  /* Set the RTC counter value */
  BKP_RTC_WaitForUpdate();
  BKP_RTC_SetCounter(COUNT_VALUE);

  /* Enable all RTC interrupts */
  BKP_RTC_ITConfig(BKP_RTC_IT_ALRF | BKP_RTC_IT_SECF | BKP_RTC_IT_OWF,ENABLE);
  NVIC_EnableIRQ(BKP_IRQn);

  /* RTC enable */
  BKP_RTC_WaitForUpdate();
  BKP_RTC_Enable(ENABLE);

  while(1)
  {
  }
}
コード例 #27
0
void main(void)
#endif
{
uint32_t i;

  RST_CLK_DeInit();
  RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSIdiv2,0);
  /* Enable peripheral clocks --------------------------------------------------*/
  RST_CLK_PCLKcmd((RST_CLK_PCLK_RST_CLK | RST_CLK_PCLK_TIMER1 | RST_CLK_PCLK_DMA),ENABLE);
  RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTA), ENABLE);

  /* Init NVIC */
  SCB->AIRCR = 0x05FA0000 | ((uint32_t)0x500);
  SCB->VTOR = 0x08000000;
  /* Disable all interrupt */
  NVIC->ICPR[0] = 0xFFFFFFFF;
  NVIC->ICER[0] = 0xFFFFFFFF;

  /* Disable all DMA request */
  MDR_DMA->CHNL_REQ_MASK_CLR = 0xFFFFFFFF;
  MDR_DMA->CHNL_USEBURST_CLR = 0xFFFFFFFF;

  /* Reset PORTB settings */
  PORT_DeInit(MDR_PORTB);
  /* Reset PORTF settings */
  PORT_DeInit(MDR_PORTF);

  /* Configure TIMER1 pins: CH1, CH2 */

  /* Configure PORTA pins 1, 3 */
  PORT_InitStructure.PORT_Pin   = PORT_Pin_1;
  PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
  PORT_InitStructure.PORT_FUNC  = PORT_FUNC_ALTER;
  PORT_InitStructure.PORT_MODE  = PORT_MODE_DIGITAL;
  PORT_InitStructure.PORT_SPEED = PORT_SPEED_FAST;
  PORT_Init(MDR_PORTA, &PORT_InitStructure);
  PORT_InitStructure.PORT_Pin   = PORT_Pin_3;
  PORT_InitStructure.PORT_OE    = PORT_OE_IN;
  PORT_Init(MDR_PORTA, &PORT_InitStructure);

  /* Init RAM */
  Init_RAM (DstBuf, BufferSize);

  /* Reset all TIMER1 settings */
  TIMER_DeInit(MDR_TIMER1);

  TIMER_BRGInit(MDR_TIMER1,TIMER_HCLKdiv1);

  /* TIM1 configuration ------------------------------------------------*/
  /* Initializes the TIMERx Counter ------------------------------------*/
  sTIM_CntInit.TIMER_Prescaler                = 0x10;
  sTIM_CntInit.TIMER_Period                   = 0x200;
  sTIM_CntInit.TIMER_CounterMode              = TIMER_CntMode_ClkFixedDir;
  sTIM_CntInit.TIMER_CounterDirection         = TIMER_CntDir_Up;
  sTIM_CntInit.TIMER_EventSource              = TIMER_EvSrc_None;
  sTIM_CntInit.TIMER_FilterSampling           = TIMER_FDTS_TIMER_CLK_div_1;
  sTIM_CntInit.TIMER_ARR_UpdateMode           = TIMER_ARR_Update_Immediately;
  sTIM_CntInit.TIMER_ETR_FilterConf           = TIMER_Filter_1FF_at_TIMER_CLK;
  sTIM_CntInit.TIMER_ETR_Prescaler            = TIMER_ETR_Prescaler_None;
  sTIM_CntInit.TIMER_ETR_Polarity             = TIMER_ETRPolarity_NonInverted;
  sTIM_CntInit.TIMER_BRK_Polarity             = TIMER_BRKPolarity_NonInverted;
  TIMER_CntInit (MDR_TIMER1,&sTIM_CntInit);

  /* Initializes the TIMER1 Channel1 -------------------------------------*/
  TIMER_ChnStructInit(&sTIM_ChnInit);

  sTIM_ChnInit.TIMER_CH_Number              = TIMER_CHANNEL1;
  sTIM_ChnInit.TIMER_CH_Mode                = TIMER_CH_MODE_PWM;
  sTIM_ChnInit.TIMER_CH_REF_Format          = TIMER_CH_REF_Format3;

  TIMER_ChnInit(MDR_TIMER1, &sTIM_ChnInit);

  TIMER_SetChnCompare(MDR_TIMER1, TIMER_CHANNEL1, 0x100);

  /* Initializes the TIMER1 Channel1 Output -------------------------------*/

  TIMER_ChnOutStructInit(&sTIM_ChnOutInit);

  sTIM_ChnOutInit.TIMER_CH_Number                   = TIMER_CHANNEL1;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Polarity          = TIMER_CHOPolarity_NonInverted;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Source            = TIMER_CH_OutSrc_REF;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Mode              = TIMER_CH_OutMode_Output;

  TIMER_ChnOutInit(MDR_TIMER1, &sTIM_ChnOutInit);

  /* Initializes the TIMER1 Channel2 -------------------------------------*/
  TIMER_ChnStructInit(&sTIM_ChnInit);

  sTIM_ChnInit.TIMER_CH_Number              = TIMER_CHANNEL2;
  sTIM_ChnInit.TIMER_CH_Mode                = TIMER_CH_MODE_CAPTURE;

  TIMER_ChnInit(MDR_TIMER1, &sTIM_ChnInit);

  /* Initializes the TIMER1 Channel2 Output -------------------------------*/

  TIMER_ChnOutStructInit(&sTIM_ChnOutInit);

  sTIM_ChnOutInit.TIMER_CH_Number                   = TIMER_CHANNEL2;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Polarity          = TIMER_CHOPolarity_NonInverted;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Source            = TIMER_CH_OutSrc_Only_0;
  sTIM_ChnOutInit.TIMER_CH_DirOut_Mode              = TIMER_CH_OutMode_Input;

  TIMER_ChnOutInit(MDR_TIMER1, &sTIM_ChnOutInit);

  /* Enable TIMER1 DMA request */
  TIMER_DMACmd(MDR_TIMER1,(TIMER_STATUS_CCR_CAP_CH2), ENABLE);

  /* Reset all DMA settings */
  DMA_DeInit();
  DMA_StructInit(&DMA_InitStr);

  /* DMA_Channel_TIM1 configuration ---------------------------------*/
  /* Set Primary Control Data */
  DMA_PriCtrlStr.DMA_SourceBaseAddr = (uint32_t)(&(MDR_TIMER1->CCR2));
  DMA_PriCtrlStr.DMA_DestBaseAddr = (uint32_t)DstBuf;
  DMA_PriCtrlStr.DMA_SourceIncSize = DMA_SourceIncNo;
  DMA_PriCtrlStr.DMA_DestIncSize = DMA_DestIncHalfword;
  DMA_PriCtrlStr.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_PriCtrlStr.DMA_Mode = DMA_Mode_Basic;
  DMA_PriCtrlStr.DMA_CycleSize = BufferSize;
  DMA_PriCtrlStr.DMA_NumContinuous = DMA_Transfers_1;
  DMA_PriCtrlStr.DMA_SourceProtCtrl = DMA_SourcePrivileged;
  DMA_PriCtrlStr.DMA_DestProtCtrl = DMA_DestPrivileged;
  /* Set Channel Structure */
  DMA_InitStr.DMA_PriCtrlData = &DMA_PriCtrlStr;
  DMA_InitStr.DMA_Priority = DMA_Priority_High;
  DMA_InitStr.DMA_UseBurst = DMA_BurstClear;
  DMA_InitStr.DMA_SelectDataStructure = DMA_CTRL_DATA_PRIMARY;
  /* Init DMA channel */
  DMA_Init(DMA_Channel_TIM1, &DMA_InitStr);

  /* Enable TIMER1 */
  TIMER_Cmd(MDR_TIMER1,ENABLE);

  /* Transfer complete */
  while((DMA_GetFlagStatus(DMA_Channel_TIM1, DMA_FLAG_CHNL_ENA)))
  {
  }

  /* Check the corectness of written dada */
  for(i = 0; i < BufferSize; i++)
  {
    if (DstBuf[i] != MDR_TIMER1->CCR1)
    {
      TransferStatus &= FAILED;
      break;
    }
    else
    {
      TransferStatus = PASSED;
    }
  }
  /* TransferStatus = PASSED, if the data transmitted are correct */
  /* TransferStatus = FAILED, if the data transmitted are not correct */

  while(1)
  {
  }
}
コード例 #28
0
ファイル: main.c プロジェクト: maxk9/etro_new
void prvSetupHardware( void )
{
	PORT_InitTypeDef PORT_InitStructure;
	UART_InitTypeDef UART_InitStructure;
	//SSP_InitTypeDef SPI_InitStructure;
	TIMER_CntInitTypeDef sTIM_CntInit;
//	TIMER_ChnInitTypeDef sTIM_ChnInit;
	

//CLK
/* Enable HSE clock oscillator */
	RST_CLK_HSEconfig(RST_CLK_HSE_ON);
	
	while(RST_CLK_HSEstatus() == ERROR);

	RST_CLK_CPUclkSelection(RST_CLK_CPUclkCPU_C3);
	MDR_RST_CLK -> CPU_CLOCK |= 2;//CPU_C1 set HSE
	RST_CLK_HSIcmd(DISABLE);
			
/* Enable the RTCHSE clock on all ports */
	RST_CLK_PCLKcmd(ALL_PORTS_CLK, ENABLE);
	PORT_StructInit(&PORT_InitStructure);//reset struct	
/************************ LCD Initialization *************************/

  /* Configure PORTA pins for data transfer to/from LCD */
	PORT_InitStructure.PORT_Pin = LCD_DATA_BUS_8;
	PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT;
	PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_OE = PORT_OE_IN;

	PORT_Init(MDR_PORTA, &PORT_InitStructure);

	/* Configure PORTE pin4 and pin5 for LCD crystals control */
	PORT_InitStructure.PORT_Pin = KS0108_CS1 | KS0108_CS2 | KS0108_RS;
	PORT_InitStructure.PORT_OE = PORT_OE_OUT;
	PORT_Init(MDR_PORTE, &PORT_InitStructure);

	PORT_Init(MDR_PORTE, &PORT_InitStructure);

	PORT_InitStructure.PORT_Pin = KS0108_EN | KS0108_RW | KS0108_RES;

	PORT_Init(MDR_PORTC, &PORT_InitStructure);
	
	PORT_SetBits(MDR_PORTA, LCD_DATA_BUS_8);
	PORT_SetBits(MDR_PORTE, KS0108_CS1 | KS0108_CS2 | KS0108_RS);
	PORT_SetBits(MDR_PORTC, KS0108_EN | KS0108_RW | KS0108_RES);

//Timer1
	
	// TIMER1
	RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER1,ENABLE);
	/* Reset all TIMER1 settings */
	TIMER_DeInit(MDR_TIMER1);

	TIMER_BRGInit(MDR_TIMER1,TIMER_HCLKdiv1);

	/* TIM1 configuration ------------------------------------------------*/
	/* Initializes the TIMERx Counter ------------------------------------*/
	sTIM_CntInit.TIMER_IniCounter				= 0;
	sTIM_CntInit.TIMER_Prescaler                = 150;//
	sTIM_CntInit.TIMER_Period                   = 82;
	sTIM_CntInit.TIMER_CounterMode              = TIMER_CntMode_ClkFixedDir;
	sTIM_CntInit.TIMER_CounterDirection         = TIMER_CntDir_Up;
	sTIM_CntInit.TIMER_EventSource              = TIMER_EvSrc_None;
	sTIM_CntInit.TIMER_FilterSampling           = TIMER_FDTS_TIMER_CLK_div_1;
	sTIM_CntInit.TIMER_ARR_UpdateMode           = TIMER_ARR_Update_Immediately;
	sTIM_CntInit.TIMER_ETR_FilterConf           = TIMER_Filter_1FF_at_TIMER_CLK;
	sTIM_CntInit.TIMER_ETR_Prescaler            = TIMER_ETR_Prescaler_None;
	sTIM_CntInit.TIMER_ETR_Polarity             = TIMER_ETRPolarity_NonInverted;
	sTIM_CntInit.TIMER_BRK_Polarity             = TIMER_BRKPolarity_NonInverted;
	TIMER_CntInit (MDR_TIMER1,&sTIM_CntInit);

	NVIC_EnableIRQ(Timer1_IRQn);
	TIMER_ITConfig(MDR_TIMER1,TIMER_STATUS_CNT_ARR, ENABLE);
	
	/* TMR1 enable */
	TIMER_Cmd (MDR_TIMER1,ENABLE);

	
	// TIMER2
	RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER2,ENABLE);
	/* Reset all TIMER1 settings */
	TIMER_DeInit(MDR_TIMER2);

	TIMER_BRGInit(MDR_TIMER2,TIMER_HCLKdiv1);

	/* TIM2 configuration ------------------------------------------------*/
	/* Initializes the TIMERx Counter ------------------------------------*/
	sTIM_CntInit.TIMER_IniCounter				= 0;
	sTIM_CntInit.TIMER_Prescaler                = 0xf;//
	sTIM_CntInit.TIMER_Period                   = 0xffff;
	sTIM_CntInit.TIMER_CounterMode              = TIMER_CntMode_ClkFixedDir;
	sTIM_CntInit.TIMER_CounterDirection         = TIMER_CntDir_Up;
	sTIM_CntInit.TIMER_EventSource              = TIMER_EvSrc_None;
	sTIM_CntInit.TIMER_FilterSampling           = TIMER_FDTS_TIMER_CLK_div_1;
	sTIM_CntInit.TIMER_ARR_UpdateMode           = TIMER_ARR_Update_Immediately;
	sTIM_CntInit.TIMER_ETR_FilterConf           = TIMER_Filter_1FF_at_TIMER_CLK;
	sTIM_CntInit.TIMER_ETR_Prescaler            = TIMER_ETR_Prescaler_None;
	sTIM_CntInit.TIMER_ETR_Polarity             = TIMER_ETRPolarity_NonInverted;
	sTIM_CntInit.TIMER_BRK_Polarity             = TIMER_BRKPolarity_NonInverted;
	TIMER_CntInit (MDR_TIMER2,&sTIM_CntInit);

	NVIC_EnableIRQ(Timer2_IRQn);
	TIMER_ITConfig(MDR_TIMER2,TIMER_STATUS_CNT_ARR, ENABLE);
	
	/* TMR2 enable */
	TIMER_Cmd (MDR_TIMER2,ENABLE);
	
	
	// TIMER3
	RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER3,ENABLE);
	/* Reset all TIMER3 settings */
	TIMER_DeInit(MDR_TIMER3);

	TIMER_BRGInit(MDR_TIMER3,TIMER_HCLKdiv1);

  /* TIM3 configuration ------------------------------------------------*/
  /* Initializes the TIMERx Counter ------------------------------------*/
	sTIM_CntInit.TIMER_IniCounter				= 0;
	sTIM_CntInit.TIMER_Prescaler                = 0;
	sTIM_CntInit.TIMER_Period                   = 0xFFFF;
	sTIM_CntInit.TIMER_CounterMode              = TIMER_CntMode_EvtFixedDir;
	sTIM_CntInit.TIMER_CounterDirection         = TIMER_CntDir_Up;
	sTIM_CntInit.TIMER_EventSource              = TIMER_EvSrc_CH1;
	sTIM_CntInit.TIMER_FilterSampling           = TIMER_FDTS_TIMER_CLK_div_1;
	sTIM_CntInit.TIMER_ARR_UpdateMode           = TIMER_ARR_Update_Immediately;
	sTIM_CntInit.TIMER_ETR_FilterConf           = TIMER_Filter_1FF_at_TIMER_CLK;
	sTIM_CntInit.TIMER_ETR_Prescaler            = TIMER_ETR_Prescaler_None;
	sTIM_CntInit.TIMER_ETR_Polarity             = TIMER_ETRPolarity_NonInverted;
	sTIM_CntInit.TIMER_BRK_Polarity             = TIMER_BRKPolarity_NonInverted;
	TIMER_CntInit (MDR_TIMER3,&sTIM_CntInit);

	// 	NVIC_EnableIRQ(Timer3_IRQn);
	// 	TIMER_ITConfig(MDR_TIMER3,TIMER_STATUS_CNT_ARR, ENABLE);
	/* Enable TIMER3 */
	TIMER_Cmd(MDR_TIMER3,ENABLE);	
	
	
	
/************************ UART1 Initialization *************************/
	PORT_StructInit(&PORT_InitStructure);//reset struct

	PORT_InitStructure.PORT_Pin = PORT_Pin_12|PORT_Pin_13;//RX TX
	PORT_InitStructure.PORT_FUNC = PORT_FUNC_OVERRID;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;
	PORT_Init(MDR_PORTE, &PORT_InitStructure);

	PORT_InitStructure.PORT_Pin = PORT_Pin_14;//EN RS485
	PORT_InitStructure.PORT_OE =PORT_OE_OUT;
	PORT_InitStructure.PORT_PD = PORT_PD_OPEN;
	PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT;
	PORT_Init(MDR_PORTE, &PORT_InitStructure);

	RS485_TX_OFF;
//UART1
	
	RST_CLK_PCLKcmd(RST_CLK_PCLK_UART1,ENABLE);
	/* Set the HCLK division factor = 1 for UART1,UART2*/
	UART_BRGInit(MDR_UART1, UART_HCLKdiv1);
	UART_DeInit(MDR_UART1);
	
	/* Disable interrupt on UART1 */
    NVIC_DisableIRQ(UART1_IRQn);
	
	/* Initialize UART_InitStructure */
	UART_InitStructure.UART_BaudRate			= 38400;
	UART_InitStructure.UART_WordLength			= UART_WordLength8b;
	UART_InitStructure.UART_StopBits			= UART_StopBits1;//PKDU2 niobyi
	UART_InitStructure.UART_Parity				= UART_Parity_No;
	UART_InitStructure.UART_FIFOMode			= UART_FIFO_OFF;
	UART_InitStructure.UART_HardwareFlowControl	= UART_HardwareFlowControl_RXE | UART_HardwareFlowControl_TXE;

	/* Configure UART1 parameters*/
	UART_Init(MDR_UART1,&UART_InitStructure);

	NVIC_EnableIRQ(UART1_IRQn);
	UART_ITConfig(MDR_UART1,UART_IT_RX, ENABLE);
	/* Enables UART1 peripheral */
	UART_Cmd(MDR_UART1,ENABLE);
	
	
//PORT
/************************ Joystick Initialization *************************/

  /* Configure PORTC pins 10..14 for input to handle joystick events */
	PORT_StructInit(&PORT_InitStructure);//reset struct
	
	PORT_InitStructure.PORT_Pin   = ( PORT_Pin_10 | PORT_Pin_11 | PORT_Pin_12 |
									PORT_Pin_13 | PORT_Pin_14 );
	PORT_InitStructure.PORT_OE    = PORT_OE_IN;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
	PORT_InitStructure.PORT_SPEED = PORT_OUTPUT_OFF;

	PORT_Init( MDR_PORTC, &PORT_InitStructure );

/************************ LEDs Initialization *************************/
	PORT_StructInit( &PORT_InitStructure );//reset struct
  /* Configure PORTD pins 10..14 for output to switch LEDs on/off */
	PORT_InitStructure.PORT_Pin   = LEDs_PINs;
	PORT_InitStructure.PORT_OE    = PORT_OE_OUT;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_FUNC  = PORT_FUNC_PORT;
	PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW;

	PORT_Init( MDR_PORTD, &PORT_InitStructure );

  /* All LEDs switch off */
	PORT_ResetBits(MDR_PORTD, LEDs_PINs);
}
コード例 #29
0
/**
 * @brief  Main program.
 * @param  None
 * @retval None
 */
void main ( void )
{
	uint8_t DataByte = 0x00;
	static uint8_t ReciveByte = 0x00;

	/* Enables the HSI clock on PORTD */
	RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTD, ENABLE);

	/* Fill PortInit structure*/
	PortInit.PORT_PULL_UP = PORT_PULL_UP_OFF;
	PortInit.PORT_PULL_DOWN = PORT_PULL_DOWN_OFF;
	PortInit.PORT_PD_SHM = PORT_PD_SHM_OFF;
	PortInit.PORT_PD = PORT_PD_DRIVER;
	PortInit.PORT_GFEN = PORT_GFEN_OFF;
	PortInit.PORT_FUNC = PORT_FUNC_MAIN;
	PortInit.PORT_SPEED = PORT_SPEED_MAXFAST;
	PortInit.PORT_MODE = PORT_MODE_DIGITAL;

	/* Configure PORTD pins 13 (UART2_TX) as output */
	PortInit.PORT_OE = PORT_OE_OUT;
	PortInit.PORT_Pin = PORT_Pin_13;
	PORT_Init(MDR_PORTD, &PortInit);
	/* Configure PORTD pins 14 (UART1_RX) as input */
	PortInit.PORT_OE = PORT_OE_IN;
	PortInit.PORT_Pin = PORT_Pin_14;
	PORT_Init(MDR_PORTD, &PortInit);

	/* Select HSI/2 as CPU_CLK source*/
	RST_CLK_CPU_PLLconfig(RST_CLK_CPU_PLLsrcHSIdiv2, 0);

	/* Enables the CPU_CLK clock on UART2 */
	RST_CLK_PCLKcmd(RST_CLK_PCLK_UART2, ENABLE);

	/* Set the HCLK division factor = 1 for UART2*/
	UART_BRGInit(MDR_UART2, UART_HCLKdiv1 );

	/* Initialize UART_InitStructure */
	UART_InitStructure.UART_BaudRate = 9600;
	UART_InitStructure.UART_WordLength = UART_WordLength8b;
	UART_InitStructure.UART_StopBits = UART_StopBits2;
	UART_InitStructure.UART_Parity = UART_Parity_Even;
	UART_InitStructure.UART_FIFOMode = UART_FIFO_OFF;
	UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_RXE
												| UART_HardwareFlowControl_TXE;

	/* Configure UART2 parameters*/
	UART_Init(MDR_UART2, &UART_InitStructure);
	/* Enables UART2 peripheral */
	UART_Cmd(MDR_UART2, ENABLE);

	while (1) {
		/* Check TXFE flag */
		while (UART_GetFlagStatus(MDR_UART2, UART_FLAG_TXFE) != SET);

		/* Send Data from UART2 */
		UART_SendData(MDR_UART2, DataByte);

		/* Check RXFF flag */
		while (UART_GetFlagStatus(MDR_UART2, UART_FLAG_RXFF) != SET);

		/* Recive data*/
		ReciveByte = UART_ReceiveData(MDR_UART2);

		/* Increment Data */
		DataByte++;
	}
}
コード例 #30
0
void main(void)
#endif
{
	RST_CLK_DeInit();
	RST_CLK_CPU_PLLconfig(RST_CLK_CPU_PLLsrcHSIdiv2, 0);
	/* Enable peripheral clocks --------------------------------------------------*/
	RST_CLK_PCLKcmd(
				(RST_CLK_PCLK_RST_CLK |
				 RST_CLK_PCLK_UART1   |
				 RST_CLK_PCLK_UART2   |
				 RST_CLK_PCLK_DMA),
				 ENABLE);
	RST_CLK_PCLKcmd((RST_CLK_PCLK_PORTC | RST_CLK_PCLK_PORTD), ENABLE);

	/* Disable all DMA request */
	MDR_DMA ->CHNL_REQ_MASK_CLR = 0xFFFFFFFF;
	MDR_DMA ->CHNL_USEBURST_CLR = 0xFFFFFFFF;

	/* Reset PORTC settings */
	PORT_DeInit(MDR_PORTC );
	/* Reset PORTC settings */
	PORT_DeInit(MDR_PORTD );

	/* Configure UART1 pins: RXD, TXD */

	/* Configure PORTB pins 3, 4 */
	PORT_InitStructure.PORT_Pin = PORT_Pin_4;
	PORT_InitStructure.PORT_OE = PORT_OE_IN;
	PORT_InitStructure.PORT_FUNC = PORT_FUNC_MAIN;
	PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL;
	PORT_InitStructure.PORT_SPEED = PORT_SPEED_FAST;
	PORT_Init(MDR_PORTC, &PORT_InitStructure);

	PORT_InitStructure.PORT_Pin = PORT_Pin_3;
	PORT_InitStructure.PORT_OE = PORT_OE_OUT;
	PORT_Init(MDR_PORTC, &PORT_InitStructure);

	/* Configure UART2 pins: RXD, TXD */

	/* Configure PORTF pins 13, 14 */
	PORT_InitStructure.PORT_Pin = PORT_Pin_14;
	PORT_InitStructure.PORT_FUNC = PORT_FUNC_MAIN;
	PORT_InitStructure.PORT_OE = PORT_OE_IN;
	PORT_Init(MDR_PORTD, &PORT_InitStructure);

	PORT_InitStructure.PORT_Pin = (PORT_Pin_13);
	PORT_InitStructure.PORT_OE = PORT_OE_OUT;
	PORT_Init(MDR_PORTD, &PORT_InitStructure);

	/* Init RAM */
	Init_RAM(DstBuf1, BufferSize);
	Init_RAM(SrcBuf1, BufferSize);
	Init_RAM(DstBuf2, BufferSize);
	Init_RAM(SrcBuf2, BufferSize);

	/* Reset all UART settings */
	UART_DeInit(MDR_UART1 );
	UART_DeInit(MDR_UART2 );

	UART_BRGInit(MDR_UART1, UART_HCLKdiv1 );
	UART_BRGInit(MDR_UART2, UART_HCLKdiv1 );

	/* UART1 configuration ------------------------------------------------*/
	UART_StructInit(&sUART);

	sUART.UART_BaudRate 			= 1200;
	sUART.UART_WordLength 			= UART_WordLength8b;
	sUART.UART_StopBits 			= UART_StopBits1;
	sUART.UART_Parity 				= UART_Parity_No;
	sUART.UART_FIFOMode 			= UART_FIFO_ON;
	sUART.UART_HardwareFlowControl 	= (UART_HardwareFlowControl_RXE
									| UART_HardwareFlowControl_TXE );
	UART_Init(MDR_UART1, &sUART);
	UART_DMAConfig( MDR_UART1,
					UART_IT_FIFO_LVL_8words,
				    UART_IT_FIFO_LVL_8words );

	/* UART2 configuration ------------------------------------------------*/
	UART_Init(MDR_UART2, &sUART);
	UART_DMAConfig(MDR_UART2,
				   UART_IT_FIFO_LVL_8words,
				   UART_IT_FIFO_LVL_8words );

	/* Enable UART1 DMA Rx and Tx request */
	UART_DMACmd(MDR_UART1, (UART_DMA_RXE | UART_DMA_TXE ), ENABLE);
	/* Enable UART2 DMA Rx and Tx request */
	UART_DMACmd(MDR_UART2, (UART_DMA_RXE | UART_DMA_TXE ), ENABLE);

	/* Reset all DMA settings */
	DMA_DeInit();
	DMA_StructInit(&DMA_InitStr);

	/* DMA_Channel_UART1_RX configuration ---------------------------------*/
	/* Set Primary Control Data */
	DMA_PriCtrlStr.DMA_SourceBaseAddr 	= (uint32_t) (&(MDR_UART1 ->DR));
	DMA_PriCtrlStr.DMA_DestBaseAddr 	= (uint32_t) DstBuf1;
	DMA_PriCtrlStr.DMA_SourceIncSize 	= DMA_SourceIncNo;
	DMA_PriCtrlStr.DMA_DestIncSize 		= DMA_DestIncByte;
	DMA_PriCtrlStr.DMA_MemoryDataSize 	= DMA_MemoryDataSize_Byte;
	DMA_PriCtrlStr.DMA_Mode 			= DMA_Mode_Basic;
	DMA_PriCtrlStr.DMA_CycleSize 		= BufferSize;
	DMA_PriCtrlStr.DMA_NumContinuous 	= DMA_Transfers_8;
	DMA_PriCtrlStr.DMA_SourceProtCtrl 	= DMA_SourcePrivileged;
	DMA_PriCtrlStr.DMA_DestProtCtrl 	= DMA_DestPrivileged;
	/* Set Channel Structure */
	DMA_InitStr.DMA_PriCtrlData 		= &DMA_PriCtrlStr;
	DMA_InitStr.DMA_Priority 			= DMA_Priority_High;
	DMA_InitStr.DMA_UseBurst	 		= DMA_BurstClear;
	DMA_InitStr.DMA_SelectDataStructure = DMA_CTRL_DATA_PRIMARY;
	/* Init DMA channel */
	DMA_Init(DMA_Channel_REQ_UART1_RX, &DMA_InitStr);

	/* DMA_Channel_UART2_RX configuration ---------------------------------*/
	/* Set Primary Control Data */
	DMA_PriCtrlStr.DMA_SourceBaseAddr 	= (uint32_t) (&(MDR_UART2 ->DR));
	DMA_PriCtrlStr.DMA_DestBaseAddr 	= (uint32_t) DstBuf2;
	/* Init DMA channel */
	DMA_Init(DMA_Channel_REQ_UART2_RX, &DMA_InitStr);

	/* DMA_Channel_UART1_TX configuration ---------------------------------*/
	/* Set Primary Control Data */
	DMA_PriCtrlStr.DMA_SourceBaseAddr 	= (uint32_t) SrcBuf1;
	DMA_PriCtrlStr.DMA_DestBaseAddr 	= (uint32_t) (&(MDR_UART1 ->DR));
	DMA_PriCtrlStr.DMA_SourceIncSize 	= DMA_SourceIncByte;
	DMA_PriCtrlStr.DMA_DestIncSize 		= DMA_DestIncNo;
	DMA_InitStr.DMA_Priority 			= DMA_Priority_Default;
	/* Init DMA channel */
	DMA_Init(DMA_Channel_REQ_UART1_TX, &DMA_InitStr);

	/* DMA_Channel_UART2_TX configuration ---------------------------------*/
	/* Set Primary Control Data */
	DMA_PriCtrlStr.DMA_SourceBaseAddr 	= (uint32_t) SrcBuf2;
	DMA_PriCtrlStr.DMA_DestBaseAddr 	= (uint32_t) (&(MDR_UART2 ->DR));
	/* Init DMA channel */
	DMA_Init(DMA_Channel_REQ_UART2_TX, &DMA_InitStr);

	/* Enable UART1 */
	UART_Cmd(MDR_UART1, ENABLE);
	/* Enable UART2 */
	UART_Cmd(MDR_UART2, ENABLE);

	/* Transfer complete */
	while ((DMA_GetFlagStatus(DMA_Channel_REQ_UART1_TX, DMA_FLAG_CHNL_ENA )));
	while ((DMA_GetFlagStatus(DMA_Channel_REQ_UART1_RX, DMA_FLAG_CHNL_ENA )));
	while ((DMA_GetFlagStatus(DMA_Channel_REQ_UART2_TX, DMA_FLAG_CHNL_ENA )));
	while ((DMA_GetFlagStatus(DMA_Channel_REQ_UART2_RX, DMA_FLAG_CHNL_ENA )));

	/* Check the corectness of written dada */
	TransferStatus1 = Verif_mem((BufferSize / 2), SrcBuf1, DstBuf2);
	TransferStatus2 = Verif_mem((BufferSize / 2), SrcBuf2, DstBuf1);
	/* TransferStatus1, TransferStatus2 = PASSED, if the data transmitted and received
	 are correct */
	/* TransferStatus1, TransferStatus2 = FAILED, if the data transmitted and received
	 are different */

	while (1);
}