欢迎来到三一文库! | 帮助中心 三一文库31doc.com 一个上传文档投稿赚钱的网站
三一文库
全部分类
  • 研究报告>
  • 工作总结>
  • 合同范本>
  • 心得体会>
  • 工作报告>
  • 党团相关>
  • 幼儿/小学教育>
  • 高等教育>
  • 经济/贸易/财会>
  • 建筑/环境>
  • 金融/证券>
  • 医学/心理学>
  • ImageVerifierCode 换一换
    首页 三一文库 > 资源分类 > DOCX文档下载  

    51单片机与蓝牙模块的串口通信.docx

    • 资源ID:13548490       资源大小:15.36KB        全文页数:12页
    • 资源格式: DOCX        下载积分:4
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录   微博登录  
    二维码
    微信扫一扫登录
    下载资源需要4
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    51单片机与蓝牙模块的串口通信.docx

    #include <reg51.h>#include <intrins.h>#include<stdio.h>#include "LCD1602.h"#include "matrix_key.h"#define uint unsigned int#define uchar unsigned char#define Nop() _nop_()sbit P10 =P1A0;/*定义独立对地按键端口*/sbit P11 =P1A1;/*定义独立对地按键端口*/sbit P12 =P1A2;/*定义独立对地按键端口*/sbit P13 =P1A3;/*定义独立对地按键端口*/ /shift 键bit shift_flag;bit call_flag ;bit CallIn_flag=0;bit reci_flag;bit reci_flag1;sbit sled_en_port = P3A6; /* 定义数码管数据锁存器控制端口 */sbit led_en_port = P2A5; /* 定义发光二极管数据锁存器控制端口 */sbit ds1302_en_port = P2A2; /* 定义时钟的选片脚 */ uchar CallIn_Num15;/="00000000000"uchar CallOut_Num15=""uchar m=0;/ 拨号指针uchar temp='?'uchar code clr16=""uchar code lcd_table16 = "Ky: Cm: Re: "/uchar send_buff15;uchar reci_buff15=""uchar z; / 接收缓冲区指针uchar time;/ 定时器中断次数uchar code mun_to_char="0123456789ABCDEF"/*1MS 为单位的延时程序*/ void init();void send(uchar cc);void send_f(uchar ccc);void interrupt_pro();void key_pro();void call_out();void main() uchar i,j;delay_1ms(5);init();/ 定时器初始化lcd_system_reset(); /*LCD1602 初始化 */for(i=0;i<16;i+)lcd_char_write(i,1,lcd_tablei); /* 显示标题 */string_write(0,0,clr);string_write(0,0," Welcome! ");sled_en_port = 0; /* 关闭数码管显示*/led_en_port = 0; /* 关闭发光二极管显示*/ds1302_en_port = 0;/* 关闭时钟通讯*/while(1)key_pro(); / 扫描键盘,按键盘处理if(reci_flag) / 串口有数据过来interrupt_pro();/ 分析处理reci_flag=0;reci_flag1=1;if(CallIn_flag=1) / 有电话打进来。 CallIn_flag=0;for(i=0,j=0;i<15;i+)/&&reci_buffi>=0x30 &&reci_buffi<=0x39 if(reci_buffi>='0'&&reci_buffi<='9'|reci_buffi=' ') CallIn_Numj=reci_buffi;j+;reci_buffi=' 'string_write(0,1,clr);string_write(0,1,CallIn_Num);if(call_flag=1)/ 拨号状态TR0=1;if(time>100&&CallOut_Num0>='0') call_out();for(i=16;i>1;i-) string_write(2,0,CallOut_Num);delay_1ms(222);delay_1ms(222);string_write(2,0,"");delay_1ms(222);delay_1ms(222); for(i=0;i<15;i+) CallOut_Numi=' ' / 清空time=0;TR0=0;call_flag=0;string_write(0,0,clr);string_write(3,0,"Welcome!");/ else if(time>222)time=0;goto start;/else m=0; void init() /* 串口定时器外部中断初始化 */ TMOD =0X21;/|= 0x20; / 定时器 1 为模式 2,8 位自动重装TH1 = 0xfd; /Baud:19200 fosc="11".0592MHzTL1=0XFD ;TH0=0;TL0=0;TR1 = 1;/ timer 1 runSCON = 0x50;/UART为模式1, 8位数据,允许接收PCON |= 0x80 ; /SMOD=1; Baud 加倍IE |= 0x90 ; /Enable Serial InterruptTR1 = 1 ;/ timer 1 runEA=1;ET0=1; void send(uchar cc)SBUF=cc;while(TI=0);TI=0;void send_f(uchar ccc)send(' ');send('<');send('F');send(ccc);send('>');void call_out()uchar i;send('(');for(i=0;i<m;i+)send(CallOut_Numi);send(')');m=0;void interrupt_pro()string_write(0,1,reci_buff);lcd_char_write(14,1,mun_to_chartemp/10); /for testlcd_char_write(15,1,mun_to_chartemp%10); /for testif(temp=')') CallIn_flag=1;/|temp='$' |temp='%'else if(temp='$') lcd_delay(5);/if(temp='$')string_write(0,0,clr);string_write(0,0,reci_buff);else switch(temp)case 'X':string_write(0,0,clr);string_write(0,0,"Disconnet");break;case 'P':string_write(0,0,clr);string_write(0,0,"Pairing"); break;case 'S':string_write(0,0,clr);string_write(0,0,"Linking"); break;case 'O':string_write(0,0,clr);string_write(0,0,"Connect"); break;case 'R':string_write(0,0,clr);string_write(0,0,"Ring");/string_write(5,0,CallIn_Num);break;case 'D':string_write(0,0,clr);string_write(0,0,"Ding");/ string_write(5,0,CallIn_Num);break;case 'I':string_write(0,0,clr);string_write(0,0,"Talking"); break;case 'L':string_write(0,0,clr);string_write(0,0,"Call failed"); break;case 'A':string_write(0,0,clr);string_write(0,0,"MP3 playing");break;case 'E':string_write(0,0,clr);string_write(0,0,"Call release"); break;case 'H':string_write(0,0,clr);string_write(0,0,"A2DP connected ");break;case 'V':string_write(0,0,clr);string_write(0,0,"A2DP disconnected");break;/ case ')':x=0; break; /for(i=0;i<16;i+) lcd_char_write(i,1,lcd_tablei); /*显示标题 */default:break;/temp='?' /for testvoid key_pro()uchar i,key_value_buff;key_value_buff = key_scan();if(key_value_buff != 0)/ 有按键动作switch(key_value_buff)/* 显示按键 */case 0x18: /0if(call_flag) CallOut_Numm='0'lcd_char_write(m+2,0,'0');m+; else if(!shift_flag) send(' ');send('A'); /Answer lcd_char_write(3,1,'0'); / 可以不显示出来 lcd_char_write(8,1,'A');lcd_char_write(9,1,' ');else send_f('P');lcd_char_write(3,1,'0');lcd_char_write(8,1,'F');lcd_char_write(9,1,'P'); break;case 0x28:/1if(call_flag) CallOut_Numm='1'lcd_char_write(m+2,0,'1');m+; else if(!shift_flag) send(' ');send('H'); /Hang uplcd_char_write(3,1,'1');lcd_char_write(8,1,'H');lcd_char_write(9,1,' ');else send_f('L');lcd_char_write(3,1,'1');lcd_char_write(8,1,'F');lcd_char_write(9,1,'L'); break;case 0x48:/2if(call_flag) CallOut_Numm='2'lcd_char_write(m+2,0,'2');m+; else if(!shift_flag) send(' ');send('R'); /Rejectlcd_char_write(3,1,'2');lcd_char_write(8,1,'R');lcd_char_write(9,1,' ');else send_f('U');lcd_char_write(3,1,'2');lcd_char_write(8,1,'F');lcd_char_write(9,1,'U');break;case 0x88:/3if(call_flag) CallOut_Numm='3'lcd_char_write(m+2,0,'3');m+; else if(!shift_flag) send(' ');send('L'); /Rediallcd_char_write(3,1,'3');lcd_char_write(8,1,'L');lcd_char_write(9,1,' ');else send_f('F');lcd_char_write(3,1,'3');lcd_char_write(8,1,'F');lcd_char_write(9,1,'F');break;case 0x14:/4if(call_flag) CallOut_Numm='4'lcd_char_write(m+2,0,'4');m+; else if(!shift_flag) send(' ');send('U'); /Vol uplcd_char_write(3,1,'4');lcd_char_write(8,1,'U');lcd_char_write(9,1,' ');else send_f('B');lcd_char_write(3,1,'4');lcd_char_write(8,1,'F');lcd_char_write(9,1,'B');break;case 0x24:/5if(call_flag) CallOut_Numm='5'lcd_char_write(m+2,0,'5');m+; else if(!shift_flag) send(' ');send('D');/Vol down lcd_char_write(3,1,'5');lcd_char_write(8,1,'D'); lcd_char_write(9,1,' ');else send_f('S');lcd_char_write(3,1,'5');lcd_char_write(8,1,'F');lcd_char_write(9,1,'S');break;case 0x44:/6if(call_flag) CallOut_Numm='6'lcd_char_write(m+2,0,'6');m+; else if(!shift_flag) send(' ');send('0'); / lcd_char_write(3,1,'6');lcd_char_write(8,1,'0');lcd_char_write(9,1,' ');else send(' ');send('G');send('x');lcd_char_write(3,1,'6');lcd_char_write(8,1,'G');lcd_char_write(9,1,'x');break;case 0x84:/7if(call_flag) CallOut_Numm='7'lcd_char_write(m+2,0,'7');m+; else if(!shift_flag) send(' ');send('V'); /Voice dial lcd_char_write(3,1,'7');lcd_char_write(8,1,'V'); lcd_char_write(9,1,' ');else send(' ');send('n');lcd_char_write(3,1,'7');lcd_char_write(8,1,'n');lcd_char_write(9,1,' ');break;case 0x12:/8if(call_flag) CallOut_Numm='8'lcd_char_write(m+2,0,'8');m+; else if(!shift_flag) send(' ');send('Z');/Call transferlcd_char_write(3,1,'8');lcd_char_write(8,1,'Z');lcd_char_write(9,1,' ');else send(' ');send('p');lcd_char_write(3,1,'8');lcd_char_write(8,1,'p');lcd_char_write(9,1,' ');break;case 0x22:/9if(call_flag) CallOut_Numm='9'lcd_char_write(m+2,0,'9');m+;else if(!shift_flag) send(' ');send('Q'); /Disconnectlcd_char_write(3,1,'9');lcd_char_write(8,1,'Q');lcd_char_write(9,1,' ');else send(' ');send('z'); /Call transferlcd_char_write(3,1,'9');lcd_char_write(8,1,'z');lcd_char_write(9,1,' ');break;case 0x42:/A *if(call_flag) CallOut_Numm='*'lcd_char_write(m+2,0,'*');m+; else send(' ');send('Y');/Versionlcd_char_write(3,1,'A');lcd_char_write(8,1,'Y');lcd_char_write(9,1,' ');break;case 0x82:/B #if(call_flag) CallOut_Numm='#'lcd_char_write(m+2,0,'#');m+;else send(' ');send('T'); /Set auto answerlcd_char_write(3,1,'B');lcd_char_write(8,1,'T');lcd_char_write(9,1,' '); break;case 0x11: if(!call_flag)send(' ');send('t'); /Clr auto answer lcd_char_write(3,1,'C');lcd_char_write(8,1,'t');lcd_char_write(9,1,' '); break;case 0x21: if(!call_flag)send(' ');send('M');/Set volume setlcd_char_write(3,1,'D');lcd_char_write(8,1,'M');lcd_char_write(9,1,' ');break;case 0x41:if(!call_flag)send(' ');send('m'); /Clr volume setlcd_char_write(3,1,'E');lcd_char_write(8,1,'m');lcd_char_write(9,1,' ');break;case 0x81:if(!call_flag)send(' ');send('N'); /Set auto linklcd_char_write(3,1,'F');lcd_char_write(8,1,'N');lcd_char_write(9,1,' ');break;default:break;while(key_scan()!=0);/* 等待按键放开*/scan_key_port = 0xff; /* 释放矩阵按键端口 */delay_1ms(5);if(P10=0)|(P11=0)|(P12=0)|(P13=0)delay_1ms(10); /* 延时去抖动*/if(P10=0)|(P11=0)|(P12=0)|(P13=0)if(P10=0)lcd_char_write(3,1,'a');send(');send('S');lcd_char_write(8,1,'S'); /Linkelse if(P11=0) call_flag=call_flag;if(call_flag) string_write(0,0,clr);lcd_char_write(0,0,0); / 显示拨号状态符号else for(i=0;i<16;i+)CallOut_Numi=''string_write(0,0,clr);string_write(3,0,"Welcome!"); else if(P12=0) lcd_char_write(3,1,'c');send(');send('P');lcd_char_write(8,1,'P'); /Pairelse if(P13=0)shift_flag=shift_flag;if(shift_flag) lcd_char_write(15,0,'s');else lcd_char_write(15,0,' ');while(P10=0)|(P11=0)|(P12=0)|(P13=0);/* 等待按键放开*/delay_1ms(5);void Timer0Interrupt() interrupt 1 / 定时器 0 中断服务函数TH0 =0;TL0 =0;TR0=0; if(reci_flag1=1) reci_flag=1;z=0;if(call_flag=1) time+;/ 串口接收中断函数void serial () interrupt 4 using 3if (RI)RI = 0 ;temp=SBUF; / if(temp!=10)reci_buffz=temp;z+;if(z>15) z=0;TR0=1;reci_flag1=1;/*void serial () interrupt 4 using 3/ 串口接收字符串if (RI)RI = 0 ;temp=SBUF;if(temp='R')CallIn_flag=1;reci_flag=1;bool RIwait(uint i)/ 等待时间到,返回 1while(i-)if(RI) return 0;/等待时间内 RI = 1 ,返回 0return 1;/ 串行接收停止位的中间时, RI 置 1 uchar ReadSbuf(void)/ 从 SBUF 读数据,可得到接收的数据uchar TmpSbuf;TmpSbuf=SBUF;SCON=0x50;return TmpSbuf;void ComService(void) interrupt 4uchar TmpSBUF,i=0;EA=0;ES=0;if(RIwait(RiWaitTimer) goto ExitCom;switch(ReadSbuf()case 'R':/current callfor(i=0;i<20;i+) if(RIwait(RLongiWaitTimer) break;/goto ExitCom;BlueTooth.TelNumi=ReadSbuf();TelTmpNumi=BlueTooth.TelNumi; / new add 09.4.08if(BlueTooth.TelNumi='r')break; BlueTooth.TelNumi='n'TelTmpNumi='n' / new add 09.4.08 if(StandbyStatus=IsStandby) BlueTooth._bIRKey=IR_BLUETOOTHPOWERON; else if(BlueTooth.WorkMode=BlueToothWorkInCalling)BlueTooth._bIRKey=IR_BLUETOOTHINTEL; else/BlueTooth._bIRKey=IR_BLUETOOTHIN;_bIRKey= IR_BTPHONECAllIN;/ BlueTooth._bIRKey=IR_BTPHONECAllIN; break;ExitCom:SCON = 0x50;/模式 1 , REN = 1 ,允许接收数据ES=1;EA=1;/Enable UART*/* if(call_flag=1&&key_value_buff=0)/ 拨号状态 n+;if(n>555) for(time=18;call_flag=1&&time>0&&CallOut_Num0>='#'time-) if(P11!=0)delay_1ms(222);delay_1ms(222);string_write(2,0,CallOut_Num);delay_1ms(222);delay_1ms(222);delay_1ms(222);delay_1ms(222);string_write(2,0,"");delay_1ms(222);delay_1ms(222);else call_flag=0;string_write(0,0,clr);string_write(3,0,"Welcome!"); call_flag=0;n=0;string_write(0,0,clr); / goto start string_write(3,0,"Welcome!");*/

    注意事项

    本文(51单片机与蓝牙模块的串口通信.docx)为本站会员(scccc)主动上传,三一文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    经营许可证编号:宁ICP备18001539号-1

    三一文库
    收起
    展开