51单片机控制TC35发送短信.docVIP

  • 5
  • 0
  • 约1.88千字
  • 约 3页
  • 2018-05-05 发布于河南
  • 举报
51单片机控制TC35发送短信

#include reg52.h #define uint unsigned int #define uchar unsigned char sbit A=P1^0; //**********函数定义**********// void main(void); //主函数 void Ini_UART(void); //串口初始化 void Delay(void); //延时 void Delay1(uint z); void CMGF(void); //设置发送数据为TXET格式 void CMGS(void); //设置目的手机号码 void SEND(void); //发送字符串 void main(void) { Ini_UART(); //串口初始化 Delay(); if(A==0) { CMGF(); Delay1(3000); CMGS(); Delay1(3000); SEND(); Delay1(3000); } } void Ini_UART(void) { SCON=0x50; //UART方式1:8位UART; REN=1:允许接收 PCON=0x00; //SMOD=0:波特率不加倍 TMOD=0x20; //T1方式2,用于UART波特率 TH1=0xFD; TL1=0xFD; //UART波特率设置:9600 TR1=1; } void Delay(void) { uint i,j; for(i=0;i10;i++) { for(j=0;j1000;j++); } } void Delay1(uint z) { uint x,y; for(x=z;x0;x--) for(y=110;y0;y--); } void CMGF(void) { uchar code mode[10]= {0x41,0x54,0x2B,0x43,0x4D,0x47,0x46,0x3D,0x31,0x0D}; //AT+CMGF=1回车 uint i; for(i=0;i10;i++) { SBUF=mode[i]; while(TI==0); TI=0; } } void CMGS(void) { uchar code mode[20]= {0x41,0x54,0x2B,0x43,0x4D,0x47,0x53,0x3D,0x31,0x33,0x38,0x33,0x39,0x31,0x31,0x30,0x34,0x31,0x35,0x0D}; //AT+CMGS车 uint i; for(i=0;i20;i++) { SBUF=mode[i]; while(TI==0); TI=0; } } void SEND(void) //发送字符串 { uchar code mode[10]={0x48,0x69,0x21,0x6E,0x69,0x68,0x61,0x6F,0x2E,0x1a}; //hi!nihao. uint i; for(i=0;i10;i++) { SBUF=mode[i]; while(TI==0); TI=0; } }

文档评论(0)

1亿VIP精品文档

相关文档