找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

nrf24l01无线输液监测系统 单片机程序与原理图

查看数: 2638 | 评论数: 1 | 收藏 1
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2017-8-7 22:01

正文摘要:

nrf24l01芯片做的单片机无线输液监测系统的全部资料分享给大家 程序和原理图 单片机源程序如下: /*-----------------------------------------------   名称:外部中断0电平触发  &nbs ...

回复

ID:1 发表于 2017-8-7 23:35
一对二数据中转
  1. /****************************************Copyright (c)****************************************************
  2. **                                       辽宁科技大学
  3. **                                    
  4. **                                         电子协会
  5. **
  6. **--------------File Info---------------------------------------------------------------------------------
  7. ** File Name:           main.c
  8. ** Last modified Date:
  9. ** Last Version:
  10. ** Description:         主函数
  11. **
  12. **--------------------------------------------------------------------------------------------------------
  13. ** Created By:          王恺
  14. ** Created date:        2013/03/28
  15. ** Version:             V1.0
  16. ** Descriptions:                 NRF24L01无线模块测试程序
  17. **                                                波特率:4800
  18. **--------------------------------------------------------------------------------------------------------
  19. ** Modified by:
  20. ** Modified date:
  21. ** Version:
  22. ** Description:
  23. **
  24. *********************************************************************************************************/


  25. /*********************************************************************************************************
  26.   包含头文件
  27. *********************************************************************************************************/
  28. #include "reg51.h"
  29. #include "intrins.h"
  30. #include "nrf24l01.h"
  31. #include "main.h"

  32.   bit no1 = 0,no2 = 0;
  33.   sbit key1 = P3^2;
  34.         unsigned char rx_buf1[4]={0x99,0x99,0x99,0x99};        //必须是4位数组
  35.         unsigned char rx_buf2[4]={0x99,0x99,0x99,0x99};        //必须是4位数组
  36.         unsigned char rx_buf[4]={0x00,0x00,0x00,0x00};        //必须是4位数组

  37. void UART_Send_Str(unsigned char *s);
  38. void SendByte(unsigned char dat);

  39. /*------------------------------------------------
  40.                     串口初始化
  41. ------------------------------------------------*/
  42. void UART_Init(void)
  43. {

  44.     SCON  = 0x50;                        // SCON: 模式 1, 8-bit UART, 使能接收  
  45.     TMOD |= 0x20;               // TMOD: timer 1, mode 2, 8-bit 重装
  46.     TH1   = 0xFD;               // TH1:  重装值 9600 波特率 晶振 11.0592MHz  
  47.     TR1   = 1;                  // TR1:  timer 1 打开                        
  48.     EA    = 1;                  //打开总中断
  49.    // ES    = 1;                  //打开串口中断
  50. }  
  51. void Delay10ms()                //@12.000MHz
  52. {
  53.         unsigned char i, j;

  54.         i = 117;
  55.         j = 184;
  56.         do
  57.         {
  58.                 while (--j);
  59.         } while (--i);
  60. }



  61. /*********************************************************************************************************
  62. ** Function name:       main
  63. ** Descriptions:        主函数(接收)
  64. ** input parameters:    无
  65. ** output parameters:   无
  66. ** Returned value:                无
  67. //*********************************************************************************************************/
  68. void main()
  69. {
  70.          
  71.         uchar number = 0,i = 1,j=0,k = 0;

  72.          uchar number1 = 0;
  73.    uchar data1[20] = {0};

  74.         NRF24L01Int();
  75.         UART_Init();
  76.         /*
  77.          *        接收
  78.          */
  79.         while (1)
  80.         {


  81.                         if(no1 == 0)
  82.                         {
  83.                           s_dizhi(0);//设置地址
  84.                                 NRF24L01Int();
  85.                 NRFSetRXMode();//设置为接收模式
  86.                 if (NRFRevDate(rx_buf))//开始接受数
  87.                   {       

  88.                           SendByte(65); //A
  89.                                 SendByte(70); //F
  90.                           SendByte(rx_buf[0]); //此为数据       
  91.                                 SendByte(rx_buf[1]); //此为数据       
  92.                                 SendByte(rx_buf[2]); //从机编码               
  93.                                 SendByte(rx_buf[3]);   //从机发送的次数       
  94.                                 SendByte(70); //F
  95.                           SendByte(65); //A
  96.                                 NRF24L01Int();//进行初始化并且切换地址扫描
  97. //                                 if(dizhi == 1)no1 = 1;
  98. //                                 if(dizhi == 2)no2 = 1;

  99.             }
  100.                         }
  101.                 if(no2 == 0)
  102.                         {
  103.                           s_dizhi(1);//设置地址
  104.                                 NRF24L01Int();
  105.                  NRFSetRXMode();//设置为接收模式
  106.                 if (NRFRevDate(rx_buf))//开始接受数
  107.                   {       
  108.                           SendByte(65); //A
  109.                                 SendByte(70); //F
  110.                           SendByte(rx_buf[0]);  //此为数据               
  111.                                 SendByte(rx_buf[1]);  //此为数据               
  112.                                 SendByte(rx_buf[2]);  //从机编码               
  113.                                 SendByte(rx_buf[3]);  //从机发送的次数       
  114.                                 SendByte(70); //F
  115.                           SendByte(65); //A
  116.         NRF24L01Int();
  117. //                                 if(dizhi == 1)no1 = 1;
  118. //                                 if(dizhi == 2)no2 = 1;

  119.             }
  120.                         }
  121.        
  122.         }
  123. }

  124.    void SendByte(unsigned char dat)
  125. {
  126. SBUF = dat;
  127. while(!TI);
  128.       TI = 0;
  129. }
  130. /*------------------------------------------------
  131.                     发送一个字符串
  132. ------------------------------------------------*/
  133. void UART_Send_Str(unsigned char *s)
  134. {
  135. while(*s!='\0')// \0 表示字符串结束标志,通过检测是否字符串末尾
  136.   {
  137.   SendByte(*s);
  138.   s++;
  139.   }
  140. }
  141. /*------------------------------------------------
  142.                      串口中断程序
  143. ------------------------------------------------*/
  144. void UART_SER (void) interrupt 4 //串行中断服务程序
  145. {
  146.     unsigned char Temp;          //定义临时变量
  147.    
  148.    if(RI)                        //判断是接收中断产生
  149.      {
  150.           RI=0;                      //标志位清零
  151.           Temp=SBUF;                 //读入缓冲区的值
  152.           P1=Temp;                   //把值输出到P1口,用于观察
  153.       SBUF=Temp;                 //把接收到的值再发回电脑端
  154.          }
  155.    if(TI)                        //如果是发送标志位,清零
  156.      TI=0;
  157. }
复制代码

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表