注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

东月之神

在单纯的观念里面,生命就容易变得比较深刻!

 
 
 

日志

 
 
关于我

别驻足,梦想要不停追逐,别认输,熬过黑暗才有日出,要记住,成功就在下一步,路很苦,汗水是最美的书!

网易考拉推荐

单片机AT命令控制GPRS打电话发短信  

2011-12-22 10:03:43|  分类: 我的单片机 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |


#include <REG52.H>
#include <stdio.h>
#include <string.h>
#include "lcd.c"

#define uchar unsigned char
#define uint unsigned int

sbit call = P2^0;
sbit send_mes = P2^1;
sbit answer = P2^2;
sbit refuse = P2^3;

void delay1(uint i);    //函数声明
void send(char *s);
void serial_init(void);
void wirte_string(uchar *s);
void recieve(uchar n);

uchar b[12];

uchar cnt = 0, cnt1 = 0;

void main (void)

   serial_init();     //初始化串口
 lcd_init();                //初始化LCD                                                                                                                                  
 while(1)
 {
  lcd_clr();         //清屏
                                                                                                                               
       lcd_pos(0x00);               //设置显示位置为第一行第1列                                                                               
        wirte_string(dis1);

  lcd_pos(0x40);
  lcd_wdat(cnt + '0'); 
  
  lcd_pos(0x43);
  wirte_string(b);
                                                                       
  delay(100); 

  if(call == 0)      //拨打电话
  { 
   delay1(30);
   if(call == 0)
   {
    send("at+colp=1\r\n");
    delay1(100);
    send("atd15088649632;\r\n");
    delay1(100);
   }   
  }
  else if(send_mes == 0)   //发送信息
  {
   delay1(30);
   if(send_mes == 0)
   {
    send("at+cmgf=1\r\n"); //发送信息
    delay1(100);
    send("at+cmgs=\"15088649632\"\r\n");
    delay1(500);
    send("sb\r\n\x01a");
    delay1(500);
   }
  }
  else  if(answer == 0)
  {
   delay1(30);
   if(answer == 0)
   {
    send("ata\r\n");//接听电话
     delay1(100);
   }
  }
  else  if(refuse == 0)
  {
   delay1(30);
   if(refuse == 0)
   {
    send("ath\r\n"); //拒绝来电
     delay1(100);
   }
  }
  P1 = ~cnt;
 }
}

void wirte_string(uchar *s)
{
 uchar i = 0;                                                                                                                                   
    while(s[i] != '\0')                                               
    {                                                                    
       lcd_wdat(s[i]);         //显示字符"        "            
       i++;                                                               
    }     
}

void send(uchar *s)

 uchar i = 0;
 cnt++;
 for(i = 0; i < strlen(s); i++)
 {
  TI = 0;
  SBUF = s[i];         //SUBF接受/发送缓冲器(又叫串行通信特殊功能寄存器)
  while(!TI);    // 等特数据传送 (TI发送中断标志)
  TI = 0;     // 清除数据传送标志  
 }  
}

 /**************************************************                    
    串口初始化                         
**************************************************/
void serial_init(void)
{
 SCON = 0x50;      //REN=1允许串行接受状态,串口工作模式2        
    TMOD |= 0x20;      //定时器工作方式2                      
 PCON |= 0x80;      //波特率提高一倍                                                      
    TH1 = 0xFA;    //波特率9600、数据位8、停止位1。效验位无 (11.0592MM)
 TL1 = 0xFA;
 TR1 = 1;         //开启定时器1                                                     
 ET1 = 0;
 ES = 1;         //开串口中断                 
 EA = 1;         // 开总中断
}

 /**************************************************                    
    延时处理程序                          
**************************************************/
void delay1(uint i)
{
 uchar j;
 for(i; i > 0; i--)
  for(j = 200; j > 0; j--) ;
}

 /**************************************************                    
    串口接收中断函数                         
**************************************************/
void serial() interrupt 4
{
 uchar j;
 if(RI)
 {
  uchar ch;
  RI = 0;
  ch = SBUF;  
  b[cnt1] = ch;
  cnt1++;
  if(cnt1 == 10 || b[cnt1] == 0x0A)
  {
   for(j = 0; j < cnt1; j++)
    b[j] = '\0';
   cnt1 = 0;
  }   
 }
}

 

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

                                                                          
                                                                                              
 

  评论这张
 
阅读(1355)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017