zoukankan      html  css  js  c++  java
  • stm32 UART串口

    void USART1_IRQHandler(void)                    //´®¿Ú1ÖжϷþÎñ³ÌÐò
        {
        u8 Res;
    #ifdef OS_TICKS_PER_SEC         //Èç¹ûʱÖÓ½ÚÅÄÊý¶¨ÒåÁË,˵Ã÷ҪʹÓÃucosIIÁË.
        OSIntEnter();    
    #endif
        if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)  //½ÓÊÕÖжÏ(½ÓÊÕµ½µÄÊý¾Ý±ØÐëÊÇ0x0d 0x0a½áβ)
            {
                
            Res =USART_ReceiveData(USART1);//(USART1->DR);    //¶ÁÈ¡½ÓÊÕµ½µÄÊý¾Ý
            
                if(Res==0x31)
                {
                //LED0ÉÁÒ»´Î
                LED0 = 0;    
              delay_ms(300);
                LED0 = 1;
              delay_ms(50);
                LED0 = 0;
                delay_ms(300);
                LED0 = 1;    
                }
            //LED1 ÁÁ
                if(Res==0x32)
                {
                    
                    LED1 = 0;
                    
                }
     
                
            if((USART_RX_STA&0x8000)==0)//½ÓÊÕδÍê³É
                {
                if(USART_RX_STA&0x4000)  //½ÓÊÕµ½ÁË0x0d
                    {
                    if(Res!=0x0a)USART_RX_STA=0;//½ÓÊÕ´íÎó,ÖØпªÊ¼
                    else USART_RX_STA|=0x8000;    //½ÓÊÕÍê³ÉÁË 
                    }
                else //»¹Ã»ÊÕµ½0X0D
                    {    
                    if(Res==0x0d)USART_RX_STA|=0x4000;
                    else
                        {
                        USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
                        USART_RX_STA++;
                        if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//½ÓÊÕÊý¾Ý´íÎó,ÖØпªÊ¼½ÓÊÕ      
                        }         
                    }
                }            
         } 
    while(1)
        {
            if(USART_RX_STA&0x8000)
            {                       
                len=USART_RX_STA&0x3fff;//µÃµ½´Ë´Î½ÓÊÕµ½µÄÊý¾Ý³¤¶È
                printf("
    Äú·¢Ë͵ÄÏûϢΪ:
    
    ");
                for(t=0;t<len;t++)
                {
                    USART_SendData(USART1, USART_RX_BUF[t]);//Ïò´®¿Ú1·¢ËÍÊý¾Ý
                    while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//µÈ´ý·¢ËͽáÊø
                }
                printf("
    
    ");//²åÈë»»ÐÐ
                USART_RX_STA=0;
            } 
             else
                 
            {
                times++;
             if(times%200==0)printf("
    ѧºÅ:14160310317ÐÕÃû:ÕÔ´æµµ µÈ´ýKEY0 KEY1 ±»°´ÏÂ
    "); 
         delay_ms(10);            
             t=KEY_Scan(0);
            if(t)
            {                           
                switch(t)
                {                 
                    case KEY_UP:
                  printf("
    KEY0±»°´ÏÂ
    
    ");
                  break;
                    case KEY_LEFT:
                        BEEP=1;
                      delay_ms(300);
                      BEEP=0;
                    break;
                }            
            }
        }     
     }
  • 相关阅读:
    set用法
    01分数规划
    unique && stl的全排列
    lower_bound() && upper_bound()
    spfa判负环
    倍增求LCA
    数据生成c++程序模板
    samba
    vsftp快速配置
    grub丢失的修复
  • 原文地址:https://www.cnblogs.com/zhaocundang/p/5325401.html
Copyright © 2011-2022 走看看