標(biāo)題:
基于GSM的智能家居的單片機(jī)代碼
[打印本頁(yè)]
作者:
qweeewq
時(shí)間:
2018-12-16 10:20
標(biāo)題:
基于GSM的智能家居的單片機(jī)代碼
因?yàn)檗D(zhuǎn)化格式錯(cuò)誤,漢子有點(diǎn)亂碼,但不影響使用!.
不亂的可以看下一個(gè)注釋有,
只可以發(fā)短信,讓后采集溫濕度,火焰,co,co2,光照強(qiáng)度,紅外,屏幕是12864,
沒(méi)有仿真,注釋很詳細(xì),GSM是串口是固定的,
要用的拿
單片機(jī)源碼如下:
/**********************************************************************************
* 工程名 :發(fā)送文本短信
* 描述 :通過(guò)C51開(kāi)發(fā)板控制模塊發(fā)送一條TEXT短信
* 實(shí)驗(yàn)平臺(tái):C51
* 庫(kù)版本 :
* 硬件連接說(shuō)明
使用單片串口與GPRS模塊通信
C51 GPRS模塊
P30 (RXD)->RXD
P31 (TXD)->TXD
GND ->GND
* 軟件功能說(shuō)明
板子上電后運(yùn)行指示燈RUNING_LED會(huì)以一秒的頻率閃爍
打開(kāi)代碼修改短信中心號(hào)、接收方手機(jī)號(hào)和短信內(nèi)容,編譯成功后下載到單片機(jī)里面,就可以實(shí)現(xiàn)發(fā)送一條文本短信
**********************************************************************************/
#include "config.h"
#include "string.h"
#include "delay.h"
#include "uart.h"
#include <reg51.h>
#include <stdlib.h>
#include <intrins.h>
#include <stdio.h>
#include <math.h>
unsigned char receiveData[8];
#define uchar unsigned char
#define uint unsigned int
#define SlaveAddress 0x46 //定義器件在IIC總線中的從地址,根據(jù)ALT ADDRESS地址引腳不同修改 //ALT ADDRESS引腳接地時(shí)地址為0xA6,接電源時(shí)地址為0x3A
typedef unsigned char BYTE;
typedef unsigned short WORD;
xdata BYTE BUF[8]; //接收數(shù)據(jù)緩存區(qū)
xdata int dis_data; //變?
xdata float temp;
/////////////////////溫濕度
bit flag_300ms ;
xdata uchar flat=1;
xdata uchar data_byte;
xdata uchar RH,TH;
xdata uchar c;
void delay_nms(unsigned int k);
void InitLcd();
void Init_BH1750(void);
void WriteDataLCM(uchar dataW);
void WriteCommandLCM(uchar CMD,uchar Attribc);
void DisplayOneChar(uchar X,uchar Y,uchar DData);
void conversion(uint temp_data);
void Single_Write_BH1750(uchar REG_Address); //單個(gè)寫(xiě)入數(shù)據(jù)
uchar Single_Read_BH1750(uchar REG_Address); //單個(gè)讀取內(nèi)部寄存器數(shù)據(jù)
void Multiple_Read_BH1750(); //連續(xù)的讀取內(nèi)部寄存器數(shù)據(jù)
//------------------------------------
void Delay5us();
void Delay5ms();
void BH1750_Start(); //起始信號(hào)
void BH1750_Stop(); //停止信號(hào)
void BH1750_SendACK(bit ack); //應(yīng)答ACK
bit BH1750_RecvACK(); //讀ack
void BH1750_SendByte(BYTE dat); //IIC單個(gè)字節(jié)寫(xiě)
BYTE BH1750_RecvByte(); //IIC單個(gè)字節(jié)讀
uchar code dak[]=" ";
uchar code dav[16]="煙霧濃度:";
uchar code daco[16]="CO濃度:";
uchar code dag[]="光照強(qiáng)度:";
uchar code daw[]="溫度:";
uchar code das[]="濕度:";
uchar dat[16];
////////12864接線
sbit CS = P2^7;//第4根線 RS
sbit SID = P2^6;//第5根線 RW
sbit SCK = P2^5;//第6根線 E
sbit ND1 = P2^0 ; //濃度
sbit ND2 = P2^1 ; //濃度
sbit io = P2^2 ; //dht11(口線定義)
sbit yin = P2^3; //聲音
sbit ren = P2^4; //人體感應(yīng)
sbit huo = P0^2; //火焰感應(yīng)
sbit beep = P0^3; //蜂鳴器
sbit SCL=P0^1; //IIC時(shí)鐘引腳定義
sbit SDA=P0^0; //IIC數(shù)據(jù)引腳定義
uchar ad_data,adc,s,dianliu;
void Delay5us()
{
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
}
void Delay5ms()
{
WORD n = 560;
while (n--);
}
void BH1750_Start()
{
SDA = 1; //拉高數(shù)據(jù)線
SCL = 1; //拉高時(shí)鐘線
Delay5us(); //延時(shí)
SDA = 0; //產(chǎn)生下降沿
Delay5us(); //延時(shí)
SCL = 0; //拉低時(shí)鐘線
}
void BH1750_Stop()
{
SDA = 0; //拉低數(shù)據(jù)線
SCL = 1; //拉高時(shí)鐘線
Delay5us(); //延時(shí)
SDA = 1; //產(chǎn)生上升沿
Delay5us(); //延時(shí)
}
void BH1750_SendACK(bit ack)
{
SDA = ack; //寫(xiě)應(yīng)答信號(hào)
SCL = 1; //拉高時(shí)鐘線
Delay5us(); //延時(shí)
SCL = 0; //拉低時(shí)鐘線
Delay5us(); //延時(shí)
}
bit BH1750_RecvACK()
{
SCL = 1; //拉高時(shí)鐘線
Delay5us(); //延時(shí)
CY = SDA; //讀應(yīng)答信號(hào)
SCL = 0; //拉低時(shí)鐘線
Delay5us(); //延時(shí)
return CY;
}
void BH1750_SendByte(BYTE dat)
{
BYTE i;
for (i=0; i<8; i++) //8位計(jì)數(shù)器
{
dat <<= 1; //移出數(shù)據(jù)的最高位
SDA = CY; //送數(shù)據(jù)口
SCL = 1; //拉高時(shí)鐘線
Delay5us(); //延時(shí)
SCL = 0; //拉低時(shí)鐘線
Delay5us(); //延時(shí)
}
BH1750_RecvACK();
}
BYTE BH1750_RecvByte()
{
BYTE i;
BYTE dat = 0;
SDA = 1; //使能內(nèi)部上拉,準(zhǔn)備讀取數(shù)據(jù),
for (i=0; i<8; i++) //8位計(jì)數(shù)器
{
dat <<= 1;
SCL = 1; //拉高時(shí)鐘線
Delay5us(); //延時(shí)
dat |= SDA; //讀數(shù)據(jù)
SCL = 0; //拉低時(shí)鐘線
Delay5us(); //延時(shí)
}
return dat;
}
void Single_Write_BH1750(uchar REG_Address)
{
BH1750_Start(); //起始信號(hào)
BH1750_SendByte(SlaveAddress); //發(fā)送設(shè)備地址+寫(xiě)信號(hào)
BH1750_SendByte(REG_Address); //內(nèi)部寄存器地址,請(qǐng)參考中文pdf22頁(yè)
// BH1750_SendByte(REG_data); //內(nèi)部寄存器數(shù)據(jù),請(qǐng)參考中文pdf22頁(yè)
BH1750_Stop(); //發(fā)送停止信號(hào)
}
void Multiple_read_BH1750(void)
{ xdata uchar i;
BH1750_Start(); //起始信號(hào)
BH1750_SendByte(SlaveAddress+1); //發(fā)送設(shè)備地址+讀信號(hào)
for (i=0; i<3; i++) //連續(xù)讀取6個(gè)地址數(shù)據(jù),存儲(chǔ)中BUF
{
BUF[i] = BH1750_RecvByte(); //BUF[0]存儲(chǔ)0x32地址中的數(shù)據(jù)
if (i == 3)
{
BH1750_SendACK(1); //最后一個(gè)數(shù)據(jù)需要回NOACK
}
else
{
BH1750_SendACK(0); //回應(yīng)ACK
}
}
BH1750_Stop(); //停止信號(hào)
Delay5ms();
}
void Init_BH1750()
{
Single_Write_BH1750(0x01);
}
uchar code AC_TABLE[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, //第一行漢字位置
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //第二行漢字位置
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, //第三行漢字位置
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, //第四行漢字位置
};
/********************************
名稱:SendByte
功能:串口發(fā)送一個(gè)字節(jié)
*********************************/
void SendByte(uchar Dbyte)
{
xdata uchar i;
for(i=0;i<8;i++)
{
SCK = 0;
Dbyte=Dbyte<<1;
SID = CY;
SCK = 1;
SCK = 0;
}
}
/***********接收一個(gè)字節(jié)****/
uchar ReceiveByte(void)
{
xdata uchar i,temp1,temp2;
temp1 = 0;
temp2 = 0;
for(i=0;i<8;i++)
{
temp1=temp1<<1;
SCK = 0;
SCK = 1;
SCK = 0;
if(SID) temp1++;
}
for(i=0;i<8;i++)
{
temp2=temp2<<1;
SCK = 0;
SCK = 1;
SCK = 0;
if(SID) temp2++;
}
return ((0xf0&temp1)+(0x0f&temp2));
}
void CheckBusy( void )
{
do SendByte(0xfc);
while(0x80&ReceiveByte());
}
void WriteCommand(uchar Cbyte )
{
CS = 1;
CheckBusy();
SendByte(0xf8);
SendByte(0xf0&Cbyte);
SendByte(0xf0&Cbyte<<4);
CS = 0;
}
void WriteData(uchar Dbyte )
{
CS = 1;
CheckBusy();
SendByte(0xfa);
SendByte(0xf0&Dbyte);
SendByte(0xf0&Dbyte<<4);
CS = 0;
}
uchar ReadData( void )
{
CheckBusy();
SendByte(0xfe);
return ReceiveByte();
}
void Delay(uint MS)
{
xdata uchar us,usn;
while(MS!=0)
{
usn = 2;
while(usn!=0)
{
us = 0xf5;
while (us!=0)
{
us--;
};
usn--;
}
MS--;
}
}
void LcmInit( void )
{
WriteCommand(0x30);
WriteCommand(0x03);
WriteCommand(0x0C);
WriteCommand(0x01);
WriteCommand(0x06);
}
void LcmClearTXT( void )
{
xdata uchar i;
WriteCommand(0x30);
WriteCommand(0x80);
for(i=0;i<64;i++)
WriteData(0x20);
}
void write_str(uchar row,uchar col,uchar *puts)
{
WriteCommand(0x30);
WriteCommand(AC_TABLE[8*row+col]);
while(*puts != '\0')
{
if(col==8)
{
col='0';
row++;
}
if(row==4) row='0';
WriteCommand(AC_TABLE[8*row+col]);
WriteData(*puts);
puts++;
WriteData(*puts);
puts++;
col++;
}
}
void DisplayDots(uchar DotByte)
{
xdata uchar i,j;
WriteCommand(0x34);
WriteCommand(0x36);
for(i=0;i<32;i++)
{
WriteCommand(0x80|i);
WriteCommand(0x80);
for(j=0;j<32;j++)
{
WriteData(DotByte);
}
DotByte=~DotByte;
}
}
unsigned long int poe(uchar a,uchar b)
{
xdata unsigned long int result=1;// 初始化為 1
for(;b>0;b--)
{
result*=a;
}
return result;
}
void write_num(uchar x,uchar y,unsigned long int num)
{
xdata uchar i=10;
switch (x)
{
case 0: WriteCommand(0x80+y);break;
case 1: WriteCommand(0x90+y);break;
case 2: WriteCommand(0x88+y);break;
case 3: WriteCommand(0x98+y);break;
default: ;
}
while(i>=1)
{
if((uchar)(num/poe(10,i-1))!=0)
break;
i--;
}
while(i)
{
WriteData(num/(unsigned long int)(poe(10,i-1))+'0');
num=num%(unsigned long int)(poe(10,i-1));
i--;
}
}
void delayms(uint z)
{
xdata uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void delayus(uint w)
{
xdata uint x,y;
for(x=w;x>0;x--)
for(y=10;y>0;y--);
}
void Lcd_Write(unsigned char *dat)//*********************<LCD寫(xiě)數(shù)組>
{
do{
CS = 1;
SID = 0;
SCK = 0;
s= *dat;
delayms(5);
SCK = 1;
delayms(5);
SCK = 0;
}while(*(dat++) != '\0');
}
void delay1()//延時(shí)10us
{
uchar i;
i--; i--; i--; i--; i--; i--;
}
void start()//開(kāi)始信號(hào)
{
io=1;
delay1();
io=0;
Delay(20);//>18ms
io=1;
delay1();//20-40us
delay1();
delay1();
delay1();
delay1();
}
uchar receive_byte()//接收一個(gè)字節(jié)
{
uchar i,temp,count;
for(i=0;i<8;i++)
{
count=2;
while((!io)&&count++); //判斷數(shù)據(jù)位是0還是1
delay1();delay1();delay1();delay1();
temp=0;
if(io==1)temp=1; // 如果高電平高過(guò)預(yù)定0高電平值則數(shù)據(jù)位為 1
count=2;
while((io)&&count++);
if(count==1)break;
data_byte<<=1;
data_byte|=temp;
}
return (data_byte);
}
void receive()//接收數(shù)據(jù)
{
uchar T_H,T_L,R_H,R_L,check,num_check;
uchar count;
start();//開(kāi)始信號(hào)
io=1;
if(!io)//讀取DHT11響應(yīng)信號(hào)
{
count=2;
while((!io)&&count++); //判斷從機(jī)是否發(fā)出 80us 的高電平,若發(fā)出則開(kāi)始采集數(shù)據(jù)
count=2;
while((io)&&count++);
R_H=receive_byte(); //采集濕度整數(shù)部分
R_L=receive_byte();
T_H=receive_byte();
T_L=receive_byte();
check=receive_byte();
io=0;//拉低延時(shí)50us
delay1();delay1();delay1();delay1();delay1();
io=1;
num_check=R_H+R_L+T_H+T_L;
if(num_check=check)
{
RH=R_H;
TH=T_H;
check=num_check;
}
}
}
#define Automatic_Startup 1 //定義自啟動(dòng) V1.2版本起有自啟動(dòng)功能
#define Buf1_Max 200 //串口1緩存長(zhǎng)度
/************* 本地常量聲明 **************/
sbit RUNING_LED = P1^2; //運(yùn)行指示燈
static unsigned char *SMS_Num="\"+8613800472500\"";//短信中心號(hào) 關(guān)于中心號(hào)的介紹可以看串口調(diào)試筆記的第二部分
static unsigned char *phone="\"17361603954\""; //短信接收方手機(jī)號(hào)
static unsigned char *content="Stranger entering!!!";//發(fā)送短信內(nèi)容
static unsigned char *content1="fire fire fire!!!";//發(fā)送短信內(nèi)容
/************* 本地變量聲明 **************/
xdata u8 Uart1_Buf[Buf1_Max];
u8 Times=0,First_Int = 0,shijian=0;
bdata u8 Flag;//定時(shí)器標(biāo)志位
sbit Timer0_start =Flag^0; //定時(shí)器0延時(shí)啟動(dòng)計(jì)數(shù)器
/************* 本地函數(shù)聲明 **************/
void GPIO_config(void); //引腳初始化
void Timer0Init(void); //定時(shí)器0初始化
void CLR_Buf1(void); //清串口接收緩存
u8 Find(u8 *a); //查找字符串
void Second_AT_Command(u8 *b,u8 *a,u8 wait_time); //發(fā)送指令
void Wait_CREG(void); //查詢等待模塊注冊(cè)成功
void Set_Text_Mode(void); //設(shè)置短信為TEXT模式
void Send_Text_Sms(void); //發(fā)送一條TEXT短信
/************* 外部函數(shù)和變量聲明*****************/
void beept()
{
u8 i;
for(i=1;i<20;i++)
{
beep=~beep;
delayms(1);
}
}
/*******************************************************************************
* 函數(shù)名 : main
* 描述 : 主函數(shù)
* 輸入 :
* 輸出 :
* 返回 :
* 注意 : 串口波特率是9600,GPRS模塊默認(rèn)波特率是115200,需要自己通過(guò)串口助手修改
為9600方可使用。
*******************************************************************************/
void main(void)
{
//OUT=0;
LcmInit(); //液晶初始化
LcmClearTXT(); //清屏
Init_BH1750(); //初始化BH1750
Lcd_Write(dat);
write_str(3,0,daw);
write_str(3,4,das);
write_str(0,0,dav);
write_str(1,0,daco);
write_str(2,0,dag);
// beep = 0;
while(1)
{
////////////////////////////////溫濕度
receive();
write_num(3,3,TH); //溫度顯示
write_num(3,7,RH);
adc=ad_data;
delayms(2);
if(ND1==1){
write_str(0,5,"低");
}else{
write_str(0,5,"高");
}
if(ND2==1){
write_str(1,5,"低");
}else{
write_str(1,5,"高");
}
////////////////////////////////HHHHH
Single_Write_BH1750(0x01); // powher on
Single_Write_BH1750(0x10); // H- resolution mode
Multiple_Read_BH1750(); //連續(xù)讀出數(shù)據(jù),存儲(chǔ)在BUF中
dis_data=BUF[0];
dis_data=(dis_data<<8)+BUF[1];//合成數(shù)據(jù)
temp=(float)dis_data/1.2;
if(temp<100)
{
write_str(2,6,dak);
}
write_num(2,5,temp);
///////////////////////////火焰 低有效
if(huo==0)
{
beept();
beep = 0;
}
//////////////////////////濃度 低電平有效
if(ND1==0)
{
beept();
beep = 0;
}
if(ND2==0)
{
beept();
beep = 0;
}
if(temp>=1000&ren==1){ /////////////////////光照 人來(lái)
Timer0Init(); //初始化定時(shí)器0
GPIO_config();
EA=1; //開(kāi)總中斷
Uart1Init(); //初始化串口9600
Wait_CREG(); //查詢等待模塊注冊(cè)成功
Set_Text_Mode();//設(shè)置短信為TEXT模式
Send_Text_Sms();//發(fā)送一條短消息
}
while(ren==1){;}
}
/*if(ND1==0&TH>40&ND2==0){ /////////////////////
Timer0Init(); //初始化定時(shí)器0
GPIO_config();
EA=1; //開(kāi)總中斷
Uart1Init(); //初始化串口9600
Wait_CREG(); //查詢等待模塊注冊(cè)成功
Set_Text_Mode();//設(shè)置短信為TEXT模式
Send_Text_Sms();//發(fā)送一條短消息
}*/
}
/*******************************************************************************
* 函數(shù)名 : Uart1
* 描述 : 串口1中斷服務(wù)入口函數(shù)
* 輸入 :
* 輸出 :
* 返回 :
* 注意 :
*******************************************************************************/
void Uart1() interrupt 4
{
if (RI)
{
RI = 0; //清除RI位
Uart1_Buf[First_Int] = SBUF; //將接收到的字符串存到緩存中
First_Int++; //緩存指針向后移動(dòng)
if(First_Int > Buf1_Max) //如果緩存滿,將緩存指針指向緩存的首地址
{
First_Int = 0;
}
}
if (TI)
{
TI = 0; //清除TI位
}
}
/*******************************************************************************
* 函數(shù)名 : Timer0_ISR
* 描述 : 定時(shí)器0中斷服務(wù)入口函數(shù),20ms中斷一次
* 輸入 :
* 輸出 :
* 返回 :
* 注意 :
*******************************************************************************/
void Timer0_ISR() interrupt 1
{
static u8 Time_count=0;
TL0 = 0x00; //重置定時(shí)器初值
TH0 = 0xB8; //重置定時(shí)器初值
TR0=0;//關(guān)定時(shí)器
Time_count++;
if(Time_count>=50)
{
Time_count = 0;
RUNING_LED =~RUNING_LED;
}
if(count_20ms) //20ms延時(shí)計(jì)數(shù)器
count_20ms--;
if(Timer0_start)
Times++;
if(Times > (50*shijian))
{
Timer0_start = 0;
Times = 0;
}
TR0=1;//開(kāi)定時(shí)器
}
/*******************************************************************************
* 函數(shù)名 : GPIO_config
* 描述 : IO口配置函數(shù)
* 輸入 :
* 輸出 :
* 返回 :
* 注意 :
*******************************************************************************/
void GPIO_config(void)
{
RUNING_LED=0;
}
/*******************************************************************************
* 函數(shù)名 : Timer0Init
* 描述 : 定時(shí)器0初始化,20ms定時(shí)
* 輸入 :
* 輸出 :
* 返回 :
* 注意 :
*******************************************************************************/
void Timer0Init(void) //20毫秒@11.0592MHz
{
AUXR &= 0x7F; //定時(shí)器時(shí)鐘12T模式
TMOD &= 0xF0; //
TMOD |= 0x01; //設(shè)置定時(shí)器模式,16位定時(shí)器
TL0 = 0x00; //設(shè)置定時(shí)器初值
TH0 = 0xB8; //設(shè)置定時(shí)器初值
TF0 = 0; //清TF0標(biāo)志
TR0 = 1; //定時(shí)器0開(kāi)始計(jì)時(shí)
ET0 = 1; //使能定時(shí)器0中斷
}
/*******************************************************************************
* 函數(shù)名 : CLR_Buf1
* 描述 : 清除串口2緩存數(shù)據(jù)
* 輸入 :
* 輸出 :
* 返回 :
* 注意 :
*******************************************************************************/
void CLR_Buf1(void)
{
u16 k;
for(k=0;k<Buf1_Max;k++) //將緩存內(nèi)容清零
{
Uart1_Buf[k] = 0x00;
}
First_Int = 0; //接收字符串的起始存儲(chǔ)位置
}
/*******************************************************************************
* 函數(shù)名 : Find
* 描述 : 判斷緩存中是否含有指定的字符串
* 輸入 :
* 輸出 :
* 返回 : unsigned char:1 找到指定字符,0 未找到指定字符
* 注意 :
*******************************************************************************/
u8 Find(u8 *a)
{
if(strstr(Uart1_Buf,a)!=NULL)
return 1;
else
return 0;
}
/*******************************************************************************
* 函數(shù)名 : Second_AT_Command
* 描述 : 發(fā)送AT指令函數(shù)
* 輸入 : 發(fā)送數(shù)據(jù)的指針、希望收到的應(yīng)答、發(fā)送等待時(shí)間(單位:S)
* 輸出 :
* 返回 :
* 注意 :
*******************************************************************************/
void Second_AT_Command(u8 *b,u8 *a,u8 wait_time)
{
u8 i;
u8 *c;
c = b; //保存字符串地址到c
CLR_Buf1();
i = 0;
while(i == 0)
{
if(!Find(a)) //查找需要應(yīng)答的字符
{
if(Timer0_start == 0)//超時(shí)重新發(fā)送命令
{
b = c; //將字符串地址給b
for (b; *b!='\0';b++)
{
UART1_SendData(*b);
}
UART1_SendLR();
Times = 0;
shijian = wait_time;
Timer0_start = 1; //開(kāi)始計(jì)時(shí)
}
}
else
{
i = 1;
Timer0_start = 0;
}
}
CLR_Buf1();
}
/*******************************************************************************
* 函數(shù)名 : Set_Text_Mode
* 描述 : 設(shè)置短信為TEXT文本模式
* 輸入 :
* 輸出 :
* 返回 :
* 注意 :
*******************************************************************************/
void Set_Text_Mode(void)
{
unsigned char xdata temp[50]="AT+CSCA=";
Second_AT_Command("ATE0","OK",3); //取消回顯
Second_AT_Command("AT+CMGF=1","OK",3); //TEXT模式
Second_AT_Command("AT+CPMS=\"SM\",\"SM\",\"SM\"","OK",3);//所有操作都在SIM卡中進(jìn)行
strcat(temp,SMS_Num); //字符串拼接函數(shù)(庫(kù)函數(shù))
Second_AT_Command(temp,"OK",3);//設(shè)置短信中心號(hào)
}
/*******************************************************************************
* 函數(shù)名 : Send_Text_Sms
* 描述 : 發(fā)送TEXT文本短信
* 輸入 :
* 輸出 :
* 返回 :
* 注意 :
*******************************************************************************/
void Send_Text_Sms(void)
{
unsigned char xdata temp[50]="AT+CMGS=";
strcat(temp,phone); //字符串拼接函數(shù)(庫(kù)函數(shù))
Second_AT_Command(temp,">",3); //等待接收到“>”才發(fā)送短信內(nèi)容
UART1_SendString(content); //發(fā)送短信內(nèi)容
UART1_SendData(0X1A); //發(fā)送結(jié)束符
}
/*******************************************************************************
* 函數(shù)名 : Wait_CREG
* 描述 : 等待模塊注冊(cè)成功
* 輸入 :
* 輸出 :
* 返回 :
* 注意 :
*******************************************************************************/
void Wait_CREG(void)
{
u8 i;
u8 k;
i = 0;
CLR_Buf1();
while(i == 0)
{
CLR_Buf1();
UART1_SendString("AT+CREG?");//查詢模塊網(wǎng)絡(luò)注冊(cè)狀態(tài)
UART1_SendLR();
delay_ms(250);
for(k=0;k<Buf1_Max;k++)
{
if(Uart1_Buf[k] == ':')
{
if((Uart1_Buf[k+4] == '1')||(Uart1_Buf[k+4] == '5')) //表明網(wǎng)絡(luò)注冊(cè)成功
{
i = 1;
break;
}
}
}
}
}
復(fù)制代碼
全部資料51hei下載地址:
GSM不亂.doc
(91 KB, 下載次數(shù): 15)
2018-12-16 10:17 上傳
點(diǎn)擊文件名下載附件
非亂嗎
下載積分: 黑幣 -5
圖.doc
(331 KB, 下載次數(shù): 15)
2018-12-16 10:16 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
GSM.doc
(97 KB, 下載次數(shù): 12)
2018-12-16 10:12 上傳
點(diǎn)擊文件名下載附件
源碼
下載積分: 黑幣 -5
作者:
admin
時(shí)間:
2018-12-17 04:10
補(bǔ)全頭文件原理圖即可獲得100+黑幣
作者:
言西
時(shí)間:
2019-2-9 17:09
謝謝分享
作者:
夢(mèng)園心田
時(shí)間:
2019-2-10 00:24
短信發(fā)送太貴了,沒(méi)有價(jià)值。
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1