欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
51單片機(jī)控制SIM900a發(fā)送短信
[打印本頁]
作者:
與你同行
時(shí)間:
2017-4-14 19:55
標(biāo)題:
51單片機(jī)控制SIM900a發(fā)送短信
各位大神,我需要51單片機(jī)控制SIM900a發(fā)送短信的程序
作者:
zqy181818
時(shí)間:
2017-4-14 23:36
我在網(wǎng)上找的你看看是否合適
0.png
(99.82 KB, 下載次數(shù): 116)
下載附件
2017-4-15 00:12 上傳
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit Send_SMS_PDU_key=P1^1; //發(fā)PDU格式短信按鍵
sbit LED0=P0^0;
sbit LED1=P0^1;
sbit LED2=P0^2;
sbit LED3=P0^3;
#define MAXCHAR 81
uchar aa[MAXCHAR];
code uchar ATE0[]="ATE0\r\n";
code uchar CREG_CMD[]="AT+CREG?\r\n";
code uchar SMS_send[]="AT+CMGS=18\r\n";
code uchar ATCN[]="AT+CNMI=2,1\r\n";
code uchar CMGF[]="AT+CMGF=0\r\n";
code uchar CMGR[12]="AT+CMGR=1\r\n";
code uchar CMGD[12]="AT+CMGD=1\r\n";
/*-----------------------------------------------------------------------
1.如果你的晶振是11.0592M
只需要修改下面的號(hào)碼就可以了,給成你手上拿著的手機(jī)的號(hào)碼
修改方法 在下面這段字符中找到 5129021411F5
其實(shí)5129021411F5 --> 15922041115
18622044083 8126924480F3
看明白了嗎 電話是兩位兩位顛倒 將您手上的手機(jī)號(hào)碼替換即可
-----------------------------------------------------------------------*/
uchar code Sms2_Pdu[]="0891683108200205F011000B818126924480F30008A704521B601D";
/*-----------------------------------------------------------------------
1.如果你的晶振不是11.0592M
則修改 Ini_UART 函數(shù) 波特率 9600
其他都不用動(dòng)
-----------------------------------------------------------------------*/
uchar a,j=0,flag=0;
void delay(uint ms)// 延時(shí)子程序
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
/***********************************************************
函數(shù)名稱:Print_Char
函數(shù)功能:發(fā)送單個(gè)字符
入口參數(shù):ch 出口參數(shù):無
***********************************************************/
Print_Char(uchar ch)//發(fā)送單個(gè)字符
{
SBUF=ch; //送入緩沖區(qū)
while(TI!=1); //等待發(fā)送完畢
TI=0; //軟件清零
}
/***********************************************************
函數(shù)名稱:Print_Str
函數(shù)功能:發(fā)送字符串
入口參數(shù):*str 出口參數(shù):無
***********************************************************/
Print_Str(uchar *str)//發(fā)送字符串
{
while(*str!='\0')
{
Print_Char(*str);
delay(2);
str++;
}
}
/***********************************************************
函數(shù)名稱:Ini_UART
函數(shù)功能:串口初始化、定時(shí)器初始化
入口參數(shù):無 出口參數(shù):無
***********************************************************/
Ini_UART(void)//串口初始化、定時(shí)器初始化
{
SCON = 0x50 ; //SCON: serail mode 1, 8-bit UART, enable ucvr
//UART為模式1,8位數(shù)據(jù),允許接收
TMOD |= 0x20 ; //TMOD: timer 1, mode 2, 8-bit reload
//定時(shí)器1為模式2,8位自動(dòng)重裝
PCON |= 0x80 ; //SMOD=1;
TH1 = 0xFA ; //Baud:19200 fosc="11".0592MHz
TL1=0xFA;
IE |= 0x90 ; //Enable Serial Interrupt
TR1 = 1 ; // timer 1 run
TI=1;
ES=1;
}
void clearBuff(void)
{
for(j=0;j<MAXCHAR;j++)
{
aa[j]=0x00;
}
j=0;
}
void led(int i)
{
P2 |= i;
delay(20);
P2 &= ~i;
delay(20);
P2 |= i;
delay(20);
P2 &= ~i;
}
void AT(void)
{
while(1)
{
Print_Str(ATE0);
delay(50);
Print_Str(ATCN);
delay(50);
Print_Str(CMGF);
delay(100);
clearBuff();
Print_Str(CREG_CMD);
delay(50);
if(((aa[9]=='0')&&(aa[11]=='1'))||((aa[9]=='0')&&(aa[11]=='5')))
{
clearBuff();
led(0x02);
break;
}
else
{
clearBuff();
led(0x01);
delay(50);
}
}
}
void main()
{
Ini_UART(); //初始化串口
AT(); //初始化模塊
delay(10);
Print_Str(SMS_send); //發(fā)送中文短信
delay(500);
led(0x04);
Print_Str(Sms2_Pdu); //發(fā)短信內(nèi)容
delay(500);
led(0x08);
Print_Char(0x1A); //發(fā)送結(jié)束符號(hào)
delay(500);
Print_Str("ATD18622944083;\r\n"); //打電話
while(1);
}
void ser() interrupt 4
{
if(RI==1)
{ aa[j]=SBUF;//命令存到命令數(shù)組
RI=0; //軟件清除接收中斷
j++;
}
}
復(fù)制代碼
0.png
(57.09 KB, 下載次數(shù): 89)
下載附件
2017-4-15 00:12 上傳
下載:
SIM900A 的 51 52單片機(jī)驅(qū)動(dòng).zip
(1.5 MB, 下載次數(shù): 117)
2017-4-14 23:36 上傳
點(diǎn)擊文件名下載附件
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1