资源描述:
《51单片机与蓝牙串口通信程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#include#include"LCD1602.h"#include"matrix_key.h"#defineuintunsignedint#defineucharunsignedchar#defineNop()_nop_()sbitP10=P1^0;/*定义独立对地按键端口*/sbitP11=P1^1;/*定义独立对地按键端口*/sbitP12=P1^2;/*定义独立对地按键端口*/sbitP13=P1^3;/*定义独立对地按键端口*///shift键bitshift_flag;
2、bitcall_flag;bitCallIn_flag=0;bitreci_flag;bitreci_flag1;sbitsled_en_port=P3^6;/*定义数码管数据锁存器控制端口*/sbitled_en_port=P2^5;/*定义发光二极管数据锁存器控制端口*/sbitds1302_en_port=P2^2;/*定义时钟的选片脚*/ucharCallIn_Num[15];//={"00000000000"};ucharCallOut_Num[15]={""};ucharm=0;//拨号指针uchartemp='?';ucharcodeclr[16]={""}
3、;ucharcodelcd_table[16]={"Ky:Cm:Re:"};//ucharsend_buff[15];ucharreci_buff[15]={""};ucharz;//接收缓冲区指针uchartime;//定时器中断次数ucharcodemun_to_char[]={"0123456789ABCDEF"};/*1MS为单位的延时程序*/voidinit();voidsend(ucharcc);voidsend_f(ucharccc);voidinterrupt_pro();voidkey_pro();voidcall_out();voidmain(){uc
4、hari,j;delay_1ms(5);init();//定时器初始化lcd_system_reset();/*LCD1602初始化*/for(i=0;i<16;i++)lcd_char_write(i,1,lcd_table[i]);/*显示标题*/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();//扫描键盘,按键盘处理i
5、f(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_buff[i]>=0x30&&reci_buff[i]<=0x39{if(reci_buff[i]>='0'&&reci_buff[i]<='9'
6、
7、reci_buff[i]==''){CallIn_Num[j]=reci_buff[i];j++;}reci_buff[i]='';}strin
8、g_write(0,1,clr);string_write(0,1,CallIn_Num);}if(call_flag==1)//拨号状态{TR0=1;if(time>100&&CallOut_Num[0]>='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_Num[i]='';//清
9、空time=0;TR0=0;call_flag=0;string_write(0,0,clr);string_write(3,0,"Welcome!");}//elseif(time>222){time=0;gotostart;}//elsem=0;}}}voidinit()/*串口定时器外部中断初始化*/{TMOD=0X21;//
10、=0x20;//定时器1为模式2,8位自动重装TH1=0xfd;//Baud:19200fosc="11".0592MHzTL1=0XFD;TH0=0;TL0=0;TR1=1;//timer1ru