在代码编程之前 大家必须先手续AT指令并且测试是否能正常接收发短信
AT指令可以找卖家要 按照流程发送即可
注意事项:卡的斜口朝外
稳定1A的电流
使用移动卡
程序功能:按下K2发送短信
发短信
接下来放源码 亲测有效:
//按下K2发送短信
#include "reg52.h"
#include "intrins.h"
#include "stdio.h"
#include "math.h"
#include "stdlib.h"
#include "string.h"
#include "absacc.h"
typedef unsigned char uchar;
typedef unsigned int uint;
sbit LED0=P2^0;
sbit LED1=P2^1;
sbit LED2=P2^2;
sbit LED3=P2^3;
sbit LED4=P2^4;
sbit k1=P3^3; //按键
sbit beep=P1^5; //蜂鸣器
uchar code SMS_send[]="AT+CMGS=";
uchar code SMS_send_AT[]="AT";
uchar code GMS[]="AT+CMGF=1";
uchar code SMS_PDU[]="AT+CSQ";
uchar Byte_num[]="\"+86173*****83\"";
uchar code Sms2_Pdu[]="warning";
//uchar SMS_End[]="\x1a";
uchar date;
void delay(uint n) //延时
{
unsigned int i,j;
for(i=0;i<n;i++);
for(j=0;j<123;j++);
}
void Print_Char(uchar dat) //发送一个字符
{
ES = 0;
TI=0;
SBUF = dat;
while(!TI);
TI = 0;
ES = 1;
}
void Print_Str(uchar *str) //一个字节
{
while(*str!='\0')
{
Print_Char(*str++);
}
}
void Ini_UART() //初始化 设置波特率2400
{
PCON&=0x00;
SCON=0x50;
TMOD=0x20;
TL1=0xf3;
TH1=0xf3;
TF1=1;
ET0=1;
TR1=1;
ES=1;
EA=1;
}
void GSM_PDU()
{
Print_Str(SMS_send_AT);
Print_Str("\r\n")</