找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2279|回复: 0
收起左侧

蓝牙发送频率给单片机,单片机进行显示 附e4a源码

[复制链接]
ID:582867 发表于 2020-1-1 16:31 | 显示全部楼层 |阅读模式
51hei.png

单片机源程序如下:
  1. #include<reg52.h>
  2. #include <stdio.h>
  3. typedef unsigned char uchar;
  4. typedef unsigned int uint;
  5. typedef unsigned char uint8;
  6. typedef unsigned int uint16;
  7. #define LCD1602_DATAPINS P0          //仅用高4位
  8. sbit LCD1602_E=P3^4;   //         使能端(0有效)
  9. sbit LCD1602_RW=P3^6;         //         读(1)写(0)端口
  10. sbit LCD1602_RS=P3^5;        //         数据(1)命令(0)选择端口
  11. unsigned char zuigao,shiwei,gewei,rh, USART_RX_BUF[3],i,ii;
  12. unsigned char Rx_buf,temp,rcount;
  13. uint8 code num[10]="0123456789";                                                                                                                                                                                                                                                                                                                                                                                           
  14. //sbit sin=P3^2;
  15. //sbit ten=P3^1;
  16. //sbit hund=P3^0;
  17. //temp1=0x00;
  18.         //temp2=0x00;
  19. //   uchar  dd  ;
  20. uchar table[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
  21. //
  22. //uchar  re_buf =0;
  23. unsigned char temp1=0xff;       
  24. unsigned char temp2=0xff;       


  25. void Lcd1602_Lcd1602_Delay1ms1ms(uint c)   //误差 0us          
  26. {
  27.     uchar a,b;
  28.         for (; c>0; c--)
  29.         {
  30.                  for (b=199;b>0;b--)
  31.                  {
  32.                           for(a=1;a>0;a--);
  33.                  }      
  34.         }
  35.            
  36. }

  37. void LcdWriteCom(uchar com)          //写入命令
  38. {
  39.         LCD1602_E = 0;         //使能清零
  40.         LCD1602_RS = 0;         //选择写入命令
  41.         LCD1602_RW = 0;         //选择写入

  42.         LCD1602_DATAPINS = com;        //由于4位的接线是接到P0口的高四位,所以传送高四位不用改
  43.         Lcd1602_Lcd1602_Delay1ms1ms(1);

  44.         LCD1602_E = 1;         //写入时序
  45.         Lcd1602_Lcd1602_Delay1ms1ms(5);
  46.         LCD1602_E = 0;

  47.         LCD1602_DATAPINS = com << 4; //发送低四位
  48.         Lcd1602_Lcd1602_Delay1ms1ms(1);

  49.         LCD1602_E = 1;         //写入时序
  50.         Lcd1602_Lcd1602_Delay1ms1ms(5);
  51.         LCD1602_E = 0;
  52. }

  53. void LcdWriteData(uchar dat)                        //写入数据
  54. {
  55.         LCD1602_E = 0;          //使能清零
  56.         LCD1602_RS = 1;          //选择写入数据
  57.         LCD1602_RW = 0;          //选择写入

  58.         LCD1602_DATAPINS = dat;        //由于4位的接线是接到P0口的高四位,所以传送高四位不用改
  59.         Lcd1602_Lcd1602_Delay1ms1ms(1);

  60.         LCD1602_E = 1;          //写入时序
  61.         Lcd1602_Lcd1602_Delay1ms1ms(5);
  62.         LCD1602_E = 0;

  63.         LCD1602_DATAPINS = dat << 4; //写入低四位
  64.         Lcd1602_Lcd1602_Delay1ms1ms(1);

  65.         LCD1602_E = 1;          //写入时序
  66.         Lcd1602_Lcd1602_Delay1ms1ms(5);
  67.         LCD1602_E = 0;
  68. }

  69. void LcdInit()                                                  //LCD初始化子程序
  70. {
  71.         LcdWriteCom(0x32);         //将8位总线转为4位总线
  72.         LcdWriteCom(0x28);         //在四位线下的初始化
  73.         LcdWriteCom(0x0c);  //开显示不显示光标
  74.         LcdWriteCom(0x06);  //写一个指针加1
  75.         LcdWriteCom(0x01);  //清屏        LcdWriteCom(0x80);  //设置数据指针起点

  76.         LcdWriteCom(0x80);       
  77.         LcdWriteData('F');
  78.                
  79.         LcdWriteData('r');
  80.                
  81.         LcdWriteData('e');
  82.                
  83.         LcdWriteData(':');
  84.         LcdWriteCom(0x89);       
  85.         LcdWriteData('K');
  86.                
  87.         LcdWriteData('h');
  88.                
  89.         LcdWriteData('z');               

  90. }



  91. void Lcd1602_Delay1ms(int i)

  92. {
  93.         int j=0;
  94. for(;i>0;i--)
  95.         {
  96.         for(j=0;j<125;j++);
  97.         }
  98. }       


  99. void InitUART(void)                                 //这是串口的基本配置,配置他的波特率是9600.这些参数都是标准的。
  100. {
  101.     TMOD = 0x20;
  102.     SCON = 0x50;
  103.     TH1 = 0xFD;
  104.     TL1 = TH1;
  105.     PCON = 0x00;
  106.     EA = 1;
  107.     ES = 1;
  108.     TR1 = 1;
  109. }
  110. void main()

  111. {
  112.          

  113. InitUART()        ;
  114. LcdInit();
  115.          
  116. while(1)
  117.                 {       

  118.                 LcdWriteCom(0x85);
  119.                                    LcdWriteData(USART_RX_BUF[0]);
  120.                                           LcdWriteData(USART_RX_BUF[1]);
  121.         LcdWriteData(USART_RX_BUF[2]);       
  122. }
  123.          }
  124. void UARTInterrupt(void) interrupt 4
  125. {       
  126.         ES=0;                                                                        //关闭中断
  127.     if(RI)                                                                          //接收到数据
  128.     {                                         Rx_buf=SBUF;

  129.         if(rcount!=0)                        //         date!='\0' 没有数据传输了     rcount!=0  收到@后的数据
  130.                                 {
  131.                                         USART_RX_BUF[i]=Rx_buf;
  132.                                 i++;
  133.                                         if(i>2)
  134.                                         {
  135.                                         i=0;
  136.                                                 rcount=0;
  137.                                 }                                                                          
  138.                                         }        
  139.                          if(Rx_buf=='@')
  140.                                 {rcount=1;       
  141.                                         USART_RX_BUF[3]="000"        ;
  142.                                  }

  143.     RI=0;
  144.            ES=1;                                                                          //关闭中断
  145. }
  146.                 }
复制代码
51hei.png
所有资料51hei提供下载:
蓝牙发送文本框.zip (199.6 KB, 下载次数: 66)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

Powered by 单片机教程网

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