?? ctrlbq.c
字號:
/*******************************************************************************************************
**
**(c)Copyright 2004 沈陽波爾科技有限公司 All rights reserved.
**
**--------------文件信息--------------------------------------------------------------------------------
**
**文 件 名: CtrlBQ.c
**創 建 人: 陳征(Eric.Chen)
**最后修改日期: 2004.07
**描 述: 通過串口與 BENQ 模塊 M22 的通訊函數
**
**
**--------------歷史版本信息----------------------------------------------------------------------------
**
** 創建人: 陳征(Eric.Chen)
** 版 本: v1.0
** 日 期: 2004.07
** 描 述: 原始版本
**
**------------------------------------------------------------------------------------------------------
**
** 修改人:
** 版 本:
** 日 期:
** 描 述:
**
**--------------當前版本修訂------------------------------------------------------------------------------
**
** 修改人:
** 版 本:
** 日 期:
** 描 述:
**
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#include <msp430x14x.h>
#include "modem.h"
extern void delayms(uint num);
void BENQInit(void);
void PowerOffBQ(void);
void SendBQ(uchar *buf, uint len);
void ReadMsg(uchar num);
void DelMsg(uchar num);
void SendAT(void);
void BQSetMsgCen(uchar *buf, uchar len);
void DialUp(uchar *buf, uchar len);
void HangUp(void);
void AnswerTel(void);
void SendMsg(uchar enorcn, uchar *buf, uchar len);
extern uchar g_SendMsgNumLen;
extern uchar g_SendMsgNum[MSGCENLEN];
/*----------------------------------------------------------------------------------
*函數介紹:BENQ_GSM(M22)模塊初始化
*輸入參數:無
*輸出參數:無
*返 回 值:無
*/
void BENQInit(void)
{
uchar i;
delayms(200);
PWON_L;
delayms(1000);
PWON_H;
for (i = 0; i < 18; i++)
{
delayms(1000);
}
SendAT();
delayms(100);
SendBQ("AT$NOSLEEP=1\r\n", 14); //取消休眠狀態
delayms(100);
SendBQ("AT+CLIP=1\r\n", 11); //設置來電顯示
delayms(100);
SendBQ("AT+CMGF=0\r\n", 11); //設置短信格式為PDU格式
delayms(100);
SendBQ("AT$AUPATH=3,1\r\n", 15);//設置語音通道
delayms(100);
}
/*----------------------------------------------------------------------------------
*函數介紹:關閉
*輸入參數:無
*輸出參數:無
*返 回 值:無
*/
void PowerOffBQ(void)
{
SendBQ("AT+POWEROFF\r\n", 13);
}
/*----------------------------------------------------------------------------------
*函數介紹:通過串口向BENQ模塊發送數據
*輸入參數:uchar* buf 發送數據指針 uint len 發送數據長度
*輸出參數:無
*返 回 值:無
*/
void SendBQ(uchar *buf, uint len)
{
uint i;
for (i = 0; i < len; i++)
{
TXBUF0 = buf[i];
while ((UTCTL0 & 0x01) == 0);
}
}
/*----------------------------------------------------------------------------------
*函數介紹:向BENQ模塊發送AT\r\n
*輸入參數:無
*輸出參數:無
*返 回 值:無
*/
void SendAT(void)
{
SendBQ("AT\r\n", 4);
}
/*----------------------------------------------------------------------------------
*函數介紹:設置短信中心號碼
*輸入參數:uchar *buf 號碼地址 uchar len 號碼長度
*輸出參數:無
*返 回 值:無
*/
void BQSetMsgCen(uchar *buf, uchar len)
{
// SendAT();
// delayms(10);
SendBQ("AT+CSCA=\"+", 10);
SendBQ(buf, len);
SendBQ("\",145\r\n", 7);
}
/*----------------------------------------------------------------------------------
*函數介紹:讀第num條短信
*輸入參數:uchar num 第num條
*輸出參數:無
*返 回 值:無
*/
void ReadMsg(uchar num)
{
// SendAT();
// delayms(10);
num += 0x30;
SendBQ("AT+CMGR=", 8);
SendBQ(&num, 1);
SendBQ("\r\n", 2);
}
/*----------------------------------------------------------------------------------
*函數介紹:刪除第num條短信
*輸入參數:uchar num 第num條
*輸出參數:無
*返 回 值:無
*/
void DelMsg(uchar num)
{
// SendAT();
// delayms(10);
num += 0x30;
SendBQ("AT+CMGD=", 8);
SendBQ(&num, 1);
SendBQ("\r\n", 2);
}
/*----------------------------------------------------------------------------------
*函數介紹:接聽來電
*輸入參數:無
*輸出參數:無
*返 回 值:無
*/
void AnswerTel(void)
{
SendBQ("ATA\r\n", 5);
}
/*----------------------------------------------------------------------------------
*函數介紹:掛機
*輸入參數:無
*輸出參數:無
*返 回 值:無
*/
void HangUp(void)
{
SendBQ("ATH\r\n", 5);
}
/*----------------------------------------------------------------------------------
*函數介紹:撥號
*輸入參數:uchar *buf 號碼地址 uchar len 號碼長度
*輸出參數:無
*返 回 值:無
*/
void DialUp(uchar *buf, uchar len)
{
SendBQ("ATD", 3);
SendBQ(buf, len);
SendBQ(";\r\n", 3);
}
/*----------------------------------------------------------------------------------
*函數介紹:恢復出廠設置
*輸入參數:無
*輸出參數:無
*返 回 值:無
*/
void ReFactory(void)
{
SendBQ("AT&F\r\n", 6);
}
/*----------------------------------------------------------------------------------
*函數介紹:發送短信
*輸入參數:無
*輸出參數:無
*返 回 值:無
*/
void SendMsg(uchar enorcn, uchar *buf, uchar len)
{
uchar i,j,k;
uchar temp1,temp2;
//發送頭
SendBQ("AT+CMGS=", 8);
//發送長度
if (ENCODE == enorcn)
{
j = (4 + (g_SendMsgNumLen + 1) / 2 + 3 + len - len /8 );
}
else
{
j = (4 + (g_SendMsgNumLen + 1) / 2 + 3 + len );
}
if (j < 10)
{
j += 0x30;
SendBQ(&j, 1);
}
else
{
if (j < 100)
{
k = j / 10 + 0x30;
SendBQ(&k, 1);
k = (j % 10) + 0x30;
SendBQ(&k, 1);
}
else
{
k = (j / 100) + 0x30;
SendBQ(&k, 1);
k = ((j % 100) / 10) + 0x30;
SendBQ(&k, 1);
k = (j % 10) + 0x30;
SendBQ(&k, 1);
}
}
//等待輸出'>'
SendBQ("\r", 1);
delayms(100);
SendBQ("000103",6);
//發送對方號碼長度
j = g_SendMsgNumLen / 16 + 0x30;
SendBQ(&j, 1);
j = ((g_SendMsgNumLen & 0x0f) < 0x0a)? ((g_SendMsgNumLen & 0x0f) + 0x30) : ((g_SendMsgNumLen & 0x0f) + 0x37);
SendBQ(&j, 1);
SendBQ("91", 2);
//發送對方號碼
for (i = 0; i < ((g_SendMsgNumLen + 1) / 2); i++)
{
j = ((g_SendMsgNum[i] / 16) < 0x0a)? (g_SendMsgNum[i] / 16 + 0x30) : (g_SendMsgNum[i] / 16 + 0x37);
SendBQ(&j, 1);
j = ((g_SendMsgNum[i] & 0x0f) < 0x0a)? ((g_SendMsgNum[i] & 0x0f) + 0x30) : ((g_SendMsgNum[i] & 0x0f) + 0x37);
SendBQ(&j, 1);
}
//發送編碼格式
if (ENCODE == enorcn)
{
SendBQ("0000", 4);
}
else
{
SendBQ("0008", 4);
}
//發送短信長度
j = ((len / 16) < 0x0a)? (len / 16 + 0x30) : (len / 16 + 0x37);
SendBQ(&j, 1);
j = ((len & 0x0f)< 0x0a)? ((len & 0x0f) + 0x30) : ((len & 0x0f) + 0x37);
SendBQ(&j, 1);
//發送短信內容
if (ENCODE == enorcn)
{
len = len - len / 8;
j = 0;
k = 0;
for (i = 0; i < len; i++)
{
temp1 = (buf[j] >> k) | (buf[j + 1] << (7 - k));
temp2 = ((temp1 / 16) < 0x0a)? (temp1 / 16 + 0x30) : (temp1 / 16 + 0x37);
SendBQ(&temp2, 1);
temp2 = ((temp1 & 0x0f)< 0x0a)? ((temp1 & 0x0f) + 0x30) : ((temp1 & 0x0f) + 0x37);
SendBQ(&temp2, 1);
j++;
k = (k + 1) % 7;
if (0 == k)
{
j++;
}
}
}
else
{
j = 0;
k = 0;
for (i = 0; i < len; i++)
{
//temp1 = (buf[j] >> k) | (buf[j + 1] << (7 - k));
temp2 = ((buf[i] / 16) < 0x0a)? (buf[i] / 16 + 0x30) : (buf[i] / 16 + 0x37);
SendBQ(&temp2, 1);
temp2 = ((buf[i] & 0x0f)< 0x0a)? ((buf[i] & 0x0f) + 0x30) : ((buf[i] & 0x0f) + 0x37);
SendBQ(&temp2, 1);
// j++;
// k = (k + 1) % 7;
// if(0 == k)
// {
// j++;
// }
}
}
temp1 = 0x1a;
SendBQ(&temp1, 1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -