找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4238|回复: 0
打印 上一主题 下一主题
收起左侧

51单片机利用蓝牙传输数据代码

[复制链接]
跳转到指定楼层
楼主
ID:589878 发表于 2019-7-26 16:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这是我在设计上设计的51单片机(stc98c52)与蓝牙模块(hc-08)连接,利用蓝牙透传模式做的相互通讯系统。

单片机源程序如下:
  1. #include <reg51.h>                         
  2. #define  uint unsigned int  
  3. #define uchar unsigned char
  4. void UsartInit();
  5. void Delay1ms(uint c) ;
  6. uchar receiveData;
  7. uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
  8.                         0xf8,0x80,0x90};
  9. void main()
  10. {       
  11.         UsartInit();
  12.         while(1);               
  13. }

  14. void UsartInit()
  15. {
  16.         SCON=0X50;       
  17.         TMOD=0X20;       
  18.         PCON=0X80;               
  19.         TH1=0XFA;               
  20.         TL1=0XFA;               
  21.         ES=1;                       
  22.         EA=1;                       
  23.         TR1=1;                       
  24. }

  25. void Delay1ms(uint c)
  26. {
  27.     uint a,b;
  28.    for(a=c;a>0;a--)
  29.     for(b=112;b>0;b--);       
  30. }
  31. void Usart() interrupt 4
  32. {
  33.         receiveData=SBUF;   
  34.         RI = 0;        
  35.         SBUF=receiveData;   
  36.         while(!TI);                       
  37.         TI=0;
  38.         if(receiveData=='0')
  39.                 P0=table[0];
  40.         else if(receiveData=='1')
  41.                 P0=table[1];
  42.         else if(receiveData=='2')
  43.                 P0=table[2];
  44.         else if(receiveData=='3')
  45.                 P0=table[3];
  46.         else if(receiveData=='4')
  47.                 P0=table[4];
  48.         else if(receiveData=='5')
  49.                 P0=table[5];
  50.         else if(receiveData=='6')
  51.                 P0=table[6];
  52.         else if(receiveData=='7')
  53.                 P0=table[7];
  54.         else if(receiveData=='8')
  55.                 P0=table[8];
  56.         else if(receiveData=='9')
  57.                 P0=table[9];
  58.         else
  59.            P0=~table[8];
  60.         Delay1ms(1000);
  61. }


复制代码

所有资料51hei提供下载:
STC89C52与蓝牙模块HC-08互通信.zip (38.9 KB, 下载次数: 59)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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