欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2176|回復: 0
收起左側

51單片機無線模塊

[復制鏈接]
ID:233449 發表于 2017-9-16 15:42 | 顯示全部樓層 |閱讀模式
#include <stc15f2k60s2.h>
#include <intrins.h>
#include "uart.h"
unsigned char serial_data[400];
bit flag_recful=0;
//******************************************************************************************************
//串口初始化   9600波特率 串口1
//*******************************************************************************************************
void Uart_Init()
{
SCON = 0x50;  
AUXR |= 0x04;  
T2L = 0xE0;  
T2H = 0xFE;  
AUXR |= 0x01;
AUXR |= 0x10;  
//IP=0x10;
ES=1;
RI=0;
EA=1;
}
/*=========================================串口1字符串發送函數=====================================
函數名:uart1_send_str
功能介紹:發送字符串
函數參數:*s :發送的字符串首地址
返回值:無
===============================================================================================*/
void uart1_send_str(unsigned char *s) {   
   ES=0;
    while(*s!='\0') {
  SBUF=*s;
  while(!TI);
  TI=0;
  s++;
}
ES=1;
return;
}
/**********************************************
函數功能;串口1接收客戶端發來的數據
數據格式:前:Direction:run!  后:Direction:back! 左:Direction:left! 右:Direction:right!
          速度:Speed:xx     舵機角度:angle:xx
/**********************************************/
void UART_Interrupt_Receive(void) interrupt 4
{
static unsigned int i=0;

    if(RI==1)
    {
      RI  =   0;
     serial_data[i] = SBUF;
   i++;
    if(serial_data[i-1]=='>' || serial_data[i-1]=='!'|| serial_data[i-1]=='K'|| serial_data[i-1]=='R'|| serial_data[i-1]=='k')
   {
     flag_recful=1;
     serial_data[i]='\0';
     i=0;
   }
}
return;
}
//******************************************************************************************************
//串口初始化   9600波特率 串口2
//*******************************************************************************************************
void Uart_Init2(void)  //9600bps@11.0592MHz
{
S2CON = 0x50;  
AUXR |= 0x04;  
T2L = 0xE0;  
T2H = 0xFE;  
AUXR |= 0x10;  
IE2&=0xfe;
IE2|=0x01;
  S2CON|=0x01;
}
/*=========================================串口1字符串發送函數=====================================
函數名:uart1_send_str
功能介紹:發送字符串
函數參數:*s :發送的字符串首地址
返回值:無
===============================================================================================*/
void uart2_send_str(unsigned char *s) {   
   IE2&=0xfe;
    while(*s!='\0') {
  S2BUF=*s;
  while(!(S2CON&0x02));
  S2CON&=0xfd;
  s++;
}
  IE2|=0x01;
return;
}
/**********************************************
函數功能;串口2接收客戶端發來的數據
數據格式:前:Direction:run!  后:Direction:back! 左:Direction:left! 右:Direction:right!
          速度:Speed:xx     舵機角度:angle:xx
/**********************************************/
void UART_Interrupt_Receive2(void) interrupt 8
{
static unsigned int j=0;
    if(S2CON&0x01)
    {
      S2CON&=0xfe;
     serial_data[j] = S2BUF;
   j++;
    if(serial_data[j-1]=='>' || serial_data[j-1]=='!'|| serial_data[j-1]=='K'|| serial_data[j-1]=='z')
   {
     flag_recful=1;
     serial_data[j]='\0';
     j=0;
   }
}
return;
}

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表