📄 main.bak
字号:
#pragma interrupt INTSR0 MD_INTSR0
#pragma interrupt INTST0 MD_INTST0
#pragma interrupt INTSR6 MD_INTSR6
#pragma interrupt INTST6 MD_INTST6
#pragma interrupt INTTM000 MD_INTTM000
#pragma interrupt INTTM50 MD_INTTM50
#pragma interrupt INTTM51 MD_INTTM51
#include "ext_var.h"
#include "Timer.h"
#include "Strings.h"
#define ERROR 0
#define OK 1
#define CANCEL 2
#define CMD_STOP 0
#define CMD_RUN 1
#define PARA_BLOCK_NO 0
#define LOW 0
#define HIGH 1
#define ON 0
#define OFF 1
#define IGNORE 0
#define HOLD 1
#define _CMDMODE 0
#define _SMSMODE 1
#define _NULL 0
#define _EVEN 1
#define _ODD 2
#define IDLE 0
#define SEND 1
#define READ 2
#define _1200BPS 0
#define _2400BPS 1
#define _4800BPS 2
#define _9600BPS 3
#define _1920BPS 4
#define _3840BPS 5
#define _5760BPS 6
#define _1152BPS 7
#define _HUAWEI 0
#define _SIEMENS 1
#define _WAVECOM 2
#define _TEXT 0
#define _PDU 1
#define _NORMAL 0 //0 -- normal mode
#define _DEBUG 1 //1 -- debug mode
//structure of reception
//only receive
typedef struct
{
uchar Finish;
uint RcvPtr;
uint SndPtr;
int Length;
uchar Buf[BUF_LEN+1];
}UART6_REC;
extern uchar ucEEPROMWriteEx(uchar ucBlock,ushort usWriteAdr,ushort usWriteLen,uchar *pDataAddress);
extern uchar ucEEPROMReadEx(uchar ucBlock,ushort usReadAdr,ushort usReadLen,uchar *pDataAddress);
extern uchar ucEEPROMInitEx( uchar ucBlock );
extern ushort usEEPROMBlankAdrSearchEx( uchar ucBlock );
extern void DisableFLMD( void );
extern uchar ucReadOneByte(uchar ucBlock,ushort usReadAdr);
extern uchar IsBlockValid(uchar ucBlock);
void CPU_init(void);
void delay( unsigned int n );
uchar send_cmd( uchar *DataBuf,int DataLen,uchar InFlag );
void InitUart6Rec( void );
void UART0_Init( uchar cate,uchar parity );
void UART6_Init( uchar cate,uchar parity );
void UART0_SendData( uchar* txbuf, int txnum );
void UART6_SendData( uchar* txbuf, uint txnum );
void InitFLMD( void );
void delay_s(uint t);
uchar execute_AtCmd( uchar *CmdBuf,uchar CmdLen );
uchar send_at_cmd( char *cmdstr );
uchar sms_at_cmgs( uchar cate,uchar *para );
uchar sms_at_cmgd( uchar idx );
uchar sms_at_cmgr( uchar idx );
uchar sim_at_csca( void );
uchar sim_at_cpbr( uchar idx );
uchar SetCharSet(char *charset);
uchar ModuleSyncBR( uchar br );
uchar set_baud( uchar baud,uchar parity );
uchar read_debugflg( void );
uchar set_debugflg( void );
void check_debugflg( void );
uchar read_mode( void );
uchar set_mode( void );
void check_mode( void );
void u6WaitSndOver( void );
void u6WaitRcvOver( void );
void u0WaitSndOver( void );
void u0WaitRcvOver( void );
void SendRetInfo( uchar *info );
uchar DeleteAllMsg( void );
void check_wtdtime( void );
void ChangeModeToSMS( void );
void ChangeModeToCMD( void );
uchar SaveParaToFlash(ushort addr,uchar *dataBuf,uint dataLen);
void wtd_listen( void );
uchar GetSimInfo( void );
uchar SetSMSPara( void );
uchar ReadOneMsg( uchar idx );
uchar SendOneMsg( uchar *DataBuf,int DataLen );
uchar SendMsg( void );
uchar ReadMsg( void );
void read_block();
__interrupt void MD_INTST0( void );
__interrupt void MD_INTSR0( void );
__interrupt void MD_INTST6( void );
__interrupt void MD_INTSR6( void );
__interrupt void MD_INTTM000( void );
__interrupt void MD_INTTM50( void );
__interrupt void MD_INTTM51( void );
UART6_REC u6;
uint UART0_TX_CNT;
uchar *UART0_TX_ADDRESS;
uint UART6_TX_CNT;
uchar *UART6_TX_ADDRESS;
int IN_LEN = 0; //receive length
uchar RESP_BUF[RESPONE_LEN+1];
uint RESP_LEN = 0;
uchar tCount = 0; //TM00 counter
uchar tFlag = FALSE; //TM00 flag
uchar ch0;
uchar ch6;
//------------------------------------------
static uchar gMODE = _CMDMODE;
//------------------------------------------
uchar gCHIPTYPE = _SIEMENS; //module type: siemens tc35i
//------------------------------------------
uchar gCMDSTATE = CMD_STOP;
//--------first respone---------------------
uchar Rsp1MatchFlag = FALSE;
//uchar Rsp1TmpFlag = FALSE;
uint Rsp1Idx = 0;
//--------above----------------------------
//-------second respone--------------------
uchar Rsp2MatchFlag = FALSE;
uint Rsp2Idx = 0;
//uchar Rsp2TmpFlag = FALSE;
uchar RESP2_LEN = 5;
uchar RESP2_BUF[6]={'E','R','R','O','R',0};
//----------------above--------------------
//about delay parameter
uint DelayCnt = 1;
//temp buffer
uchar tempBuf[20+1];
long tempLong;
//globa parameter
long gWTDTIME = 90; //watch time(.sec)
//-------------------------------------
long gMSGTIME = 5; //msg out time(.sec)
//-------------------------------------
uchar gCD = HIGH;
uchar cd1,cd2,cd3;
//---------tm50 counter----------------
ulong tm50cnt =0;
uchar tm50Flag = FALSE;
//---------tm51 counter----------------
ulong tm51cnt =0;
uchar tm51Flag = FALSE;
//-------------------------------------
uchar CurrSwitch;
uchar PreSwitch = 0xFF;
//-------------------------------------
//uchar gSYSTEM = TRUE; //system status.(TRUE--ready; FALSE--not ready)
//-------------------------------------
uchar gPHONENUM[PHONE_LEN+1]={0,0}; //data center number.
uchar gPHONENUM_LEN = 0;
uchar gSMSCNUM[PHONE_LEN+1]={0,0}; //sms center number.
uchar gSMSCNUM_LEN = 0;
//-------------------------------------
uchar gINFLAG = IGNORE;
//-------------------------------------
uchar gSTATE = IDLE;
//-------------------------------------
uchar cmtiMatchFlag = FALSE;
uchar cmtiflag = FALSE;
char cmtiidx = 0;
uchar CMTI_BUF[20]={'+','C','M','T','I',':',' ','"','S','M','"',',',0,0};
uchar RIDX_BUF[10];
uchar RIDX_LEN = 0;
//uchar RIDX_CNT = 0;
uchar READ_FLG = FALSE;
//-------------------------------------
uchar CMD_MODE_FLG = FALSE;
uchar modeIdx = 0;
//------------------------------------------------------------------------
uint u0rcnt = 0;
uint u0scnt = 0;
uint u6scnt = 0;
uint u6rcnt = 0;
//--------------------------------------
uchar gPROTOCOL = _TEXT;
uint gMAX_RCV_LEN = 0;
//--------------------------------------
uchar TPDU[33]={0,0,0}; //PDU mode head.
int TPDU_LEN = 0;
//--------------------------------------
uchar gBAUD = _9600BPS;
uchar gPARITY = _NULL;
//--------------------------------------
uchar gDEBUG = _DEBUG; //default to debug mode.
//--------------------------------------
/**********************************************************************
* Func Name : UART0_Init
* Descript : Init Uart0
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/01/25
* Modify Date: 2008/01/25
* ********************************************************************/
void UART0_Init( uchar cate,uchar parity )
{
ASIM0 = 0; /*Clear ASIM0*/
PM1.0 = 0; /*Set P1.0(TxD0) mode to 0,(0-Output,1-Input)*/
P1.0 = 1; /*P1.0(TxD0) output 1*/
PM1.1 = 1; /*Set P1.1(RxD0) mode to 1,(0-Output,1-Input)*/
P1.1 = 1; /*P1.1(RxD0) output 1*/
ASIM0.1=0; /*SL0=0,stop bit:1 */
ASIM0.2=1; /*CL0=1,data bit:8 */
if(parity == _EVEN){
ASIM0.3=1;
ASIM0.4=1;
}
else if(parity == _ODD){
ASIM0.3=0;
ASIM0.4=1;
}
else
{
ASIM0.3=0; /*PS00=0,No parity*/
ASIM0.4=0; /*PS01=0,No parity*/
}
if(cate == _1152BPS){
BRGC0 = 0x51; /*baudrate=115200*/
}
else if(cate == _4800BPS){
BRGC0 = 0xDA; /*TPS01=1,TPS00=1,MDL04~MDL00=11010B. baudrate=4800*/
}
else{
BRGC0 = 0xCD; /*TPS01=1,TPS00=1,MDL04~MDL00=01101B. baudrate=9600*/
}
POWER0= 1; /*Enables operation of the internal operation clock.*/
TXE0 = 1; /*Enables transmission.*/
RXE0 = 1; /*Enables reception.*/
IF1L.1 = 0; /*SRIF0=0*/
MK1L.1 = 0; /*SRMK0=0,Enable receive interrupt of UART0.*/
IF0H.2 = 0; /*STIF0=0*/
MK0H.2 = 0; /*STMK0=0,Enable transfer interrupt of UART0.*/
}
/**********************************************************************
* Func Name : UART6_Init
* Descript : Initiation of uart6
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/01/29
* Modify Date: 2008/01/29
* *********************************************************************/
void UART6_Init( uchar cate,uchar parity )
{
ASIM6=0; /*Clear ASIM6*/
PM1.3=0; /*Set P1.3(TxD6) mode to 0,(0-Output,1-Input)*/
P1.3=1; /*P1.3(TxD6) output 1*/
PM1.4=1; /*Set P1.4(RxD6) mode to 1,(0-Output,1-Input)*/
P1.4=1; /*P1.4(RxD6) output 1*/
ASIM6.0=1; /*ISRM6=1,Enable interrupt of "INTSR6",no "INTSRE6" */
ASIM6.1=0; /*SL6=0,stop bit:1 */
ASIM6.2=1; /*CL6=1,data bit:8 */
// ASIM6.3=0; /*PS60=0,No parity*/
// ASIM6.4=0; /*PS61=0,No parity*/
if(parity == _EVEN){
ASIM6.3=1;
ASIM6.4=1;
}
else if(parity == _ODD){
ASIM6.3=0;
ASIM6.4=1;
}
else{
ASIM6.3=0; /*PS60=0,No parity*/
ASIM6.4=0; /*PS61=0,No parity*/
}
switch(cate)
{
case _1152BPS:
CKSR6=0;
BRGC6=35;
break;
case _9600BPS:
CKSR6=0x05; /*fxclk6=fprs/2^5*/
BRGC6=0x0D; /*MDL67~MDL60=00001101B. baudrate=9600*/
break;
case _4800BPS:
CKSR6=0x05; /*fxclk6=fprs/2^5*/
BRGC6=0x1A; /*MDL67~MDL60=00011010B. baudrate=4800*/
break;
default: //9600
CKSR6=0x05; /*fxclk6=fprs/2^5*/
BRGC6=0x0D; /*MDL67~MDL60=00001101B. baudrate=9600*/
break;
}
ASICL6.0=0; /*TXDLV6=0,normal output of TxD6 */
ASICL6.1=1; /*DIR6=1,LSB first transfer*/
POWER6=1; /*Enable operation of internal clock*/
TXE6=1; /*Enable transmition of TxD6*/
RXE6=1; /*Enable receiption of RxD6*/
IF0H.1=0; /*Clear UART6 interrupt flag of transmition:STIF6*/
MK0H.1=0; /*transfer end interrupt enable*/
IF0H.0=0; /*Clear UART6 interrupt flag of receiption:SRIF6*/
MK0H.0=0; /*receive end interrupt enable*/
PR0H.0=1; /* transfer interrupt low */
PR0H.1=1; /* receive interrupt low */
}
/**-----------------------------------------------------------------------------
**
** Abstract:
** This function is responsible for UART0 data transfering.
**
** Parameters:
** txbuf: transfer buffer pointer
** txnum: buffer size
**
** Returns:
** (TRUE)
** (FALSE)
**
**-----------------------------------------------------------------------------*/
void UART0_SendData( uchar* txbuf, int txnum )
{
if( txnum > 0 )
{
UART0_TX_ADDRESS = txbuf;
UART0_TX_CNT = txnum;
TXS0 = *UART0_TX_ADDRESS++;
}
}
/**********************************************************************
* Func Name : delay_s
* Descript : delay 1s, or 5s, or 10s, or 30s
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/07/22
* Modify Date: 2008/07/22
* **********************************************************************/
void delay_s(uint t)
{
tCount=0;
tFlag = FALSE;
TM00_Stop();
if(t<1) return;
DelayCnt = t;
TM00_Start();
while(tFlag==FALSE)
{
WDTE = 0xAC;
}
}
/**********************************************************************
* Func Name : UpCase
* Descript : up case the char from 'a'~'z'.
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/10/25
* Modify Date: 2008/10/25
* **********************************************************************/
uchar UpCase(uchar ch)
{
if(ch>='a' && ch<='z')
{
return('A'+ (ch-'a'));
}
return ch;
}
/**********************************************************************
* Func Name : SendOK
* Descript :
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/07/22
* Modify Date: 2008/07/22
* **********************************************************************/
void SendOK( void )
{
SendRetInfo("\r\nOK\r\n");
}
/**********************************************************************
* Func Name : SendError
* Descript :
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/07/22
* Modify Date: 2008/07/22
* **********************************************************************/
void SendError( void )
{
SendRetInfo("\r\nERROR\r\n");
}
/**********************************************************************
* Func Name : read_block
* Descript : read parameter block information,total 1024 bytes.
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/07/22
* Modify Date: 2008/07/22
* **********************************************************************/
void read_block()
{
uchar i,n;
ushort usReadAdr;
usReadAdr=0;
for(n=0;n<64;n++)
{
WDTE = 0xAC;
NOP();
NOP();
ucEEPROMReadEx(PARA_BLOCK_NO,usReadAdr,16,tempBuf);
UART6_SendData(tempBuf,16);
u6WaitSndOver();
usReadAdr+=16;
NOP();
NOP();
}
}
/**********************************************************************
* Func Name : ChangeModeToSMS
* Descript :
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/10/10
* Modify Date: 2008/10/10
* **********************************************************************/
void ChangeModeToSMS( void )
{
gMODE=_SMSMODE;
P4.1 = ON; //led on
CMD_MODE_FLG = FALSE;
modeIdx = 0;
InitUart6Rec();
cmtiMatchFlag = FALSE;
cmtiflag = FALSE;
cmtiidx = 0;
gSTATE = IDLE;
tm51cnt = 0;
tm51Flag = FALSE;
TM51_Start();
}
/**********************************************************************
* Func Name : ChangeModeToCMD
* Descript :
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/10/10
* Modify Date: 2008/10/10
* **********************************************************************/
void ChangeModeToCMD( void )
{
gMODE=_CMDMODE;
P4.1 = OFF; //led off
CMD_MODE_FLG = FALSE;
modeIdx = 0;
InitUart6Rec();
cmtiMatchFlag = FALSE;
cmtiflag = FALSE;
cmtiidx = 0;
gSTATE=IDLE;
}
/**********************************************************************
* Func Name : InitFLMD
* Descript :
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/04/30
* Modify Date: 2008/04/30
* **********************************************************************/
void InitFLMD( void )
{
PM6.3 = 0;
P6.3 = 0;
}
/**********************************************************************
* Func Name : InitUart6Rec
* Descript :
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/01/22
* Modify Date: 2008/01/22
* **********************************************************************/
void InitUart6Rec( void )
{
u6.Finish = FALSE;
u6.RcvPtr = 0;
u6.SndPtr = 0;
u6.Length = 0;
}
/**********************************************************************
* Func Name : PortInit
* Descript :
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/09/26
* Modify Date: 2008/09/26
* **********************************************************************/
void PortInit( void )
{
//PMx.y = z; z=0:output,1:input.
PM7.0 = 1; //DCD (0:connect, 1:disconnect)
PM7.1 = 0; //DTR (0:)
PM7.2 = 0; //POWER CTRL(0,1)
PM7.3 = 1; //line state ()//用来判断是断开状态还是要连接状态(0-don't discnnect,1-allow to connect)
PU7.0 = 1; //pull up
PU7.1 = 1; //pull up
PU7.2 = 1; //pull up
PU7.3 = 1; //pull up
PM4.1 = 0; //led
PU4.1 = 1; //led
PM4.0 = 1; //switch
PU4.0 = 1;
}
/**********************************************************************
* Func Name : u6WaitSndOver
* Descript :
* Parameters : None
* Returns : None
* Author : Nakata
* Create Date: 2008/09/26
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -