/***********************************************************
***********************************************************/
//#include "stc15.h" //包含STC15單片機寄存器定義文件
#include "STC15F2K.h"
//#include "LCD12864.H"
#include <intrins.H>
typedef unsigned char unint8;
typedef unsigned char unint16;
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef uint
#define uint unsigned int
#endif
#define SEND "AT+CMGS=\"電話號碼\"\r\n"
unsigned char qwh;
sbit buzzer = P0^6;
sbit relay = P0^4;
sbit key=P3^2;
void delay(uchar t,uchar y)
{
uint i,j;
for(i=0;i<y;i++)
for(j=0;j<t;j++);
}
void InitUART(void)
{ //9600bps@11.0592MHz
PCON &= 0x7F; //波特率不倍速
SCON = 0x50; //8位數據,可變波特率
AUXR |= 0x40; //定時器1時鐘為Fosc,即1T
AUXR &= 0xFE; //串口1選擇定時器1為波特率發生器
TMOD &= 0x0F; //清除定時器1模式位
TMOD |= 0x20; //設定定時器1為8位自動重裝方式
TL1 = 0xDC; //設定定時初值
TH1 = 0xDC; //設定定時器重裝值
ET1 = 0; //禁止定時器1中斷
TR1 = 1;
ES = 1; //使能串口中斷
EA = 1;
}
void SendData(uchar dat)
{
//while (busy_ck); //等待前面的數據發送完成
//busy_ck = 1;
SBUF = dat; //寫數據到UART數據寄存器
while(TI==0);
TI=0;
}
/*----------------------------
發送字符串
----------------------------*/
void SendString(uchar *s)
{
while (*s) //檢測字符串結束標誌
{
SendData(*s++); //發送當前字符
}
}
/****************************************************************************/
void fs(void)
{
int i;
SendString("AT+CMGF=1\r\n"); //m模式設置
for(i=0;i<50;i++)
delay(8888,8888);
SendString(SEND); //電話號碼 在頂部定義的
for(i=0;i<50;i++)
delay(8888,88888);
SendString("Warning! Someone broke into the house!\r\n"); //短信內容
for(i=0;i<50;i++)
delay(8888,8888);
SendData(0x1a); //結束符
}
void main(void)
{
int flage=0,i=0,j=0;
InitUART();
while(1)
{
relay = 0;
P2 = 0xA0;
P2 = 0x00;
if(key==1&&flage==0)
{
//P1=0XFF;
relay = 1;
P2 = 0xA0;
P2 = 0x00;
fs();
flage=1;
}
if(flage==1)
{
P1=0XFF;
}
delay(8888,8888);
i++;
if(i>=500)
{
flage=0;
i=0;
}
}
}
void Uart_Isr() interrupt 4 using 1
{
if (RI)
{
RI = 0; //Clear receive interrupt flag
//a[pi]= SBUF; //P0 show UART data
}
if (TI)
{
TI = 0; //Clear transmit interrupt flag
}
// pi++;
}