Beispiel #1
0
/*******************************************************************************
 * 名称: UART1_SendByte
 * 功能: UART1发送一个字节
 * 形参: data -> 要发送的字节
 * 返回: 无
 * 说明: 无 
 ******************************************************************************/
void UART1_SendByte(u8 data)
{
	UART1_SendData8((unsigned char)data);
	
	/* 等待传输结束 */
	while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
}
Beispiel #2
0
//发送字节
void Send(uint8_t dat)
{
  //检查并等待发送寄存器是否为空
  while(( UART1_GetFlagStatus(UART1_FLAG_TXE)==RESET));
  //发送字节
  UART1_SendData8(dat);
}
Beispiel #3
0
/*******************************************************************************
 * 名称: UART1_ReceiveByte
 * 功能: UART1接收一个字符
 * 形参: 无
 * 返回: 接收到的字符
 * 说明: 无 
 ******************************************************************************/
u8 UART1_ReceiveByte(void)
{
	u8 USART1_RX_BUF; 
	
	/* 等待接收完成 */
	while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET)
	  	;
	
	USART1_RX_BUF = UART1_ReceiveData8();
	
	return  USART1_RX_BUF;
}
Beispiel #4
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;
        }
    }
  
}
Beispiel #5
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /*High speed internal clock prescaler: 1*/
   CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

   /* UART1 configuration -------------------------------------------------------*/
   /* UART1 configured as follow:
          - Word Length = 8 Bits
          - 1 Stop Bit
          - No parity
          - BaudRate = 9600 baud
          - UART1 Clock enabled
          - Polarity Low
          - Phase Middle
          - Last Bit enabled
          - Receive and transmit enabled
   */
  UART1_DeInit();
  
  UART1_Init((uint32_t)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, 
              (UART1_SyncMode_TypeDef)(UART1_SYNCMODE_CLOCK_ENABLE | UART1_SYNCMODE_CPOL_LOW |UART1_SYNCMODE_CPHA_MIDDLE |UART1_SYNCMODE_LASTBIT_ENABLE),
              UART1_MODE_TXRX_ENABLE);
  UART1_Cmd(DISABLE);

  /* SPI configuration */
  SPI_DeInit();
  /* Initialize SPI in Slave mode  */
  SPI_Init(SPI_FIRSTBIT_LSB, SPI_BAUDRATEPRESCALER_2, SPI_MODE_SLAVE, SPI_CLOCKPOLARITY_LOW,
           SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT,(uint8_t)0x07);

  /* Enable the UART1*/
  UART1_Cmd(ENABLE);
  
	Delay(0xFFF);
  
	/* Enable the SPI*/
  SPI_Cmd(ENABLE);
  
    while (NbrOfDataToRead--)
    {
        /* Wait until end of transmit */
        while (SPI_GetFlagStatus(SPI_FLAG_TXE)== RESET)
        {
        }
        /* Write one byte in the SPI Transmit Data Register */
        SPI_SendData(TxBuffer2[TxCounter]);
        /* Write one byte in the UART1 Transmit Data Register */
        UART1_SendData8(TxBuffer1[TxCounter++]);
        /* Wait until end of transmit */
        while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET)
        {
        }
        /* Wait the byte is entirely received by UART1 */
        while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET)
        {
        }
        /* Store the received byte in the RxBuffer1 */
        RxBuffer1[RxCounter] = UART1_ReceiveData8();
        /* Wait the byte is entirely received by SPI */
        while (SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET)
        {
        }
        /* Store the received byte in the RxBuffer2 */
        RxBuffer2[RxCounter++] = SPI_ReceiveData();
    }

    /* Check the received data with the sent ones */
    TransferStatus1 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1);
    /* TransferStatus = PASSED, if the data transmitted from UART1 and received by SPI are the same */
    /* TransferStatus = FAILED, if the data transmitted from UART1 and received by SPI are different */
    TransferStatus2 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2);
    /* TransferStatus = PASSED, if the data transmitted from SPI and received by UART1 are the same */
    /* TransferStatus = FAILED, if the data transmitted from SPI and received by UART11 are different */

    while (1);
}
Beispiel #6
0
/**
  * @brief  Send Data.
  * @param  Data: Data.
  * @retval None
  */
void UART1_SendByte(uint8_t Data)
{
    UART1_SendData8((uint8_t)Data);
    /* Loop until the end of transmission */
    while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
}
Beispiel #7
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    uint32_t i = 0;
    /* Configure the multiplexer on the evalboard to select the smartCard*/
    Multiplexer_EvalBoard_Config();

    /* Configure the GPIO ports */
    GPIO_Config();
    
    /*High speed internal clock prescaler: 1*/
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    /* Enable general interrupts */
    enableInterrupts();

    UART1_DeInit();
    /* UART1 configuration -------------------------------------------------------*/
    /* UART1 configured as follow:
          - Word Length = 9 Bits
          - 1.5 Stop Bit
          - Even parity
          - BaudRate = 10752 baud
          - Receive and transmit enabled
          - UART1 Clock enabled
    */
  UART1_Init((uint32_t)10752, UART1_WORDLENGTH_9D, UART1_STOPBITS_1_5, UART1_PARITY_EVEN,
              UART1_SYNCMODE_CLOCK_ENABLE, UART1_MODE_TXRX_ENABLE);

    /* UART1 Clock set to 4MHz (frequence master 16 MHZ / 4) */
    UART1_SetPrescaler(0x02);

    /* UART1 Guard Time set to  Bit */
    UART1_SetGuardTime(0x2);

    /* Enable the UART1 Parity Error Interrupt */
    UART1_ITConfig(UART1_IT_PE, ENABLE);

    /* Enable the NACK Transmission */
    UART1_SmartCardNACKCmd(ENABLE);

    /* Enable the Smart Card Interface */
    UART1_SmartCardCmd(ENABLE);

    /* Loop while no smart card is detected */
    while ((GPIO_ReadInputData(GPIOE)& 0x01) == 0x00)
    {
    }
    
    /* PG7 - SmartCard_/CMDVCC: low */
    GPIO_WriteLow(GPIOG, GPIO_PIN_7);  

    /* release SmartCard_RESET signal */
    GPIO_WriteLow(GPIOG, GPIO_PIN_5);  

    for (i = 0; i < 6000; i++)
    {
    }
    /* set SmartCard_RESET signal */
    GPIO_WriteHigh(GPIOG, GPIO_PIN_5);  


    /* Read Smart Card ATR response */
    for (index = 0; index < 40; index++)
    {
        Counter = 0;
        while ((UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET) && (Counter != SC_Receive_Timeout))
        {
            Counter++;
        }

        if (Counter != SC_Receive_Timeout)
        {
            DST_Buffer[index] = UART1_ReceiveData8();
        }
    }

    /* Decode ATR */
    CardProtocol = SC_decode_Answer2reset(DST_Buffer);

    /* Test if the inserted card is ISO7816-3 T=0 compatible */
    if (CardProtocol == 0)
    {
        /* Inserted card is ISO7816-3 T=0 compatible */
        ATRDecodeStatus = PASSED;
    }
    else
    {
        /* Inserted smart card is not ISO7816-3 T=0 compatible */
        ATRDecodeStatus = FAILED;
    }

    while (1)
  {}
}
Beispiel #8
0
/**
  * @brief Example firmware main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{
    /* Configures the Multiplexer on the evalboard to select the IrDA*/
    Multiplexer_EvalBoard_Config();

    /* Initialize I/Os in Output Mode */
    GPIO_Init(LEDS_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);

    UART1_DeInit();
    /* UART1 configuration ----------------------------------------------------*/
    /* UART1 configured as follow:
          - Word Length = 8 Bits
          - One Stop Bit
          - No parity
          - BaudRate = 9600 baud
          - Tx and Rx enabled
          - UART1 Clock disabled
    */
    UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);

		/* Set Prescaler*/
    UART1_SetPrescaler(0x1);

    UART1_IrDAConfig(UART1_IRDAMODE_NORMAL);

    UART1_IrDACmd(ENABLE);
    while (1)
    {
        /* Wait until a byte is received */
        while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET)
        {
        }
        /* Read the received byte */
        ReceivedData = UART1_ReceiveData8();

        switch (ReceivedData)
        {
            /* Led connected to PH.0 (LED4) toggle */
        case UP:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_0);
            break;
            /* Led connected to PH.1 (LED3) toggle */
        case DOWN:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_1);
            break;
            /* Led connected to PH.2 (LED2) toggle */
        case LEFT:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_2);
            break;
            /* Led connected to PH.3 (LED1) toggle */
        case RIGHT:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_3);
            break;

        case SEL:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_0|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1);
            break;
        default:
            break;
        }
    }

}
Beispiel #9
0
void Send(uint8_t dat)
{
  while(( UART1_GetFlagStatus(UART1_FLAG_TXE)==RESET));	
    UART1_SendData8(dat);	
}
Beispiel #10
0
/************************************************************************
 * 函数名:UART1_printf
 * 描述  :格式化输出,类似于C库中的printf,但这里没有用到C库
 * 输入  :-UARTx 串口通道,这里只用到了串口1,即UART1
 *		     -Data   要发送到串口的内容的指针
 *			   -...    其他参数
 * 输出  :无
 * 返回  :无 
 * 调用  :外部调用
 *         典型应用	 UART1_printf( "\r\n this is a demo \r\n" );
 *            		 UART1_printf(  "\r\n %d \r\n", i );
 *            		 UART1_printf(  "\r\n %s \r\n", j );
 ***************************************************************************/
void UART1_printf( uint8_t *Data,...)
{
	const char *s;
	int d;   
	char buf[16];
	va_list ap;
	va_start(ap, Data);
	
	while ( *Data != 0)     // 判断是否到达字符串结束符
	{				                          
		if ( *Data == 0x5c )  //'\'
		{									  
			switch ( *++Data )
			{
				case 'r':							          //回车符
					UART1_SendData8(0x0d);
					Data ++;
				break;
	
				case 'n':							          //换行符
					UART1_SendData8(0x0a);	
					Data ++;
				break;
	
				default:
					Data ++;
				break;
			}			 
		}
		else if ( *Data == '%')
		{					//
			switch ( *++Data )
			{				
				case 's':						//字符串
				s = va_arg(ap, const char *);
				for ( ; *s; s++) 
				{
					UART1_SendData8(*s);
					while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
				}
				Data++;
				break;
	
				case 'd':	//十进制
					d = va_arg(ap, int);
					itoa(d, buf, 10);
				for (s = buf; *s; s++) 
				{
					UART1_SendData8(*s);
					while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
				}
				Data++;
				break;
				
				default:
					Data++;
				break;
			}		 
		} /* end of else if */
		else UART1_SendData8(*Data++);
	
		while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
	}
Beispiel #11
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
    }
  
}