⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mc35.c

📁 无线模块MC35的应用开发程序。用于GPRS 方面
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************
MC35.lib

A set of routines for controlling an external MC35 through a full RS232 link.
Default hardware is a core module using serial port C
Pin assignments for control lines are:
	DTR - PB6 (out)
	RTS - PB7 (out)
	CTS - PB0 (in)
	DCD - PB2 (in)
	RI  - PB3 (in)
	DSR - PB4 (in)
	TXD - PC2 (out)
	RXD - PC3 (in)

****************************/

/*** BeginHeader */
#ifndef __EXTMC35_LIB
#define __EXTMC35_LIB 

#ifndef MC35_DEBUG
	#define MC35_DEBUG 0
#endif

unsigned long extMC35_baudrate;	//current baud rate for communication with MC35

//setup flow control for port C 串口C的流控制端口设置
#define SERC_RTS_PORT PBDR
#define SERC_RTS_SHADOW PBDRShadow
#define SERC_RTS_BIT 7
#define SERC_CTS_PORT PBDR
#define SERC_CTS_BIT 0 

/*** EndHeader */

#define MC35_Set_Command "ATE0V1X0&C0&D0&S0\\Q3\r"
#define MC35_OK_String "OK"
#define MC35_Hangup_Command "\rATH\r"


/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_Open */
int MC35_Open(unsigned long baud);
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************
MC35_Open                                 <MC35.LIB>

SYNTAX:		int MC35_Open(unsigned long baud);

DESCRIPTION: 	Starts up communication with an external MC35

PARAMETER1:		The baud rate for communicating with the MC35

RETURN VALUE:	1 - External MC35 detected	0 - not connected to external MC35
END DESCRIPTION **********************************************************/

int MC35_Open(unsigned long baud)
{
	extMC35_baudrate = baud;
	BitWrPortI(PCDR, &PCDRShadow, 1, 2);	//set serial line to idle ????
	MC35_SetDTR(1);		//set DTR active
	if(MC35_Ready())	//check DSR line
	{
		serCopen(baud);
		serCflowcontrolOn();
		return 1;
	}
	else
	{
		return 0;
	}

}	
/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_Init */
int MC35_Init();
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************
MC35_Init                                 <MC35.LIB>

SYNTAX:		int MC35_Init();

DESCRIPTION: 	resets MC35 with AT, ATZ commands

RETURN VALUE:	1 - success		0 - MC35 not responding
END DESCRIPTION **********************************************************/

int MC35_Init()
{
	auto int i;
	auto unsigned long t;
	
	for(i = 0;i < 3;i++)
	{
		if(MC35_Connected())  MC35_Hangup();
		serCrdFlush();
		MC35_Send(MC35_Set_Command);
   	        VdHitWd(wd);				// 复位内部看门狗
  	        WDI_Rst();				// 复位外部看门狗
		if(MC35_Expect(MC35_OK_String, 1000))  return 1;
	}
	if(MC35_Connected())
	{
		if(MC35_DEBUG)
		{
			printf("\r\nMC35 can\'t hangup!\r\n");
		}
	}
	return 0;
}	

/* --------------------------------------------------------------------- */
/*** BeginHeader CofMC35_Init */
scofunc int CofMC35_Init();
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************
CofMC35_Init                                 <MC35.LIB>

SYNTAX:		int CofMC35_Init();

DESCRIPTION: 	resets MC35 with AT, ATZ commands. Yields to other tasks
			while waiting for responses.

RETURN VALUE:	1 - success		0 - MC35 not responding
END DESCRIPTION **********************************************************/

nodebug scofunc int CofMC35_Init()
{
	auto int i;
	auto int status;
	
	for(i = 0;i < 3;i++)
	{
		if(MC35_Connected())
		{
		     wfd { CofMC35_Hangup(); }
		}
		serCrdFlush();
		wfd { CofMC35_Send(MC35_Set_Command); }
		wfd { status = CofMC35_Expect(MC35_OK_String, 1000); }
		if(status)  return 1;
	}
	if(MC35_Connected())
	{
		if(MC35_DEBUG)
		{
			printf("\r\nMC35 can\'t hangup!\r\n");
		}
	}
	return 0;
}	
/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_Ready */
int MC35_Ready();
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************
MC35_Ready                                 <MC35.LIB>

SYNTAX:		int MC35_Ready();

DESCRIPTION: 	Returns true if the DSR line is asserted
		DSR(输入)为低有效(数据设备准备就绪)
RETURN VALUE:	1 - DSR line is active	0 - DSR inactive (nothing connected)
END DESCRIPTION **********************************************************/

nodebug int MC35_Ready()
{
	//PB1 is DSR line
	if(BitRdPortI(PBDR, 4))
	{
		return 0;
	}
	else
	{
		return 1;	//active low signal
	}
}	
/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_SetDTR */
int MC35_SetDTR(int active);
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************
MC35_SetDTR                                 <MC35.LIB>

SYNTAX:		int MC35_SetDTR(int active);

DESCRIPTION: 	Sets the value of the DTR line
		DTR(输出)为低有效(数据终端准备就绪)
PARAMETER1:	1 - DTR active (low)	0 - DTR inactive (high)

END DESCRIPTION **********************************************************/

nodebug int MC35_SetDTR(int active)
{
	//PB6 is DTR line
	if(active)
	{
		BitWrPortI(PBDR, &PBDRShadow, 0, 6);
	}
	else
	{
		BitWrPortI(PBDR, &PBDRShadow, 1, 6);
	}
}	
/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_Connected */
int MC35_Connected();
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************
MC35_Connected                                 <MC35.LIB>

SYNTAX:		int MC35_Connected();

DESCRIPTION: 	Returns true if the DCD line is asserted, meaning the MC35 is
			connected to a remote carrier.
		DCD(输入)为低有效(有载波连接)
RETURN VALUE:	1 - DCD line is active	0 - DCD inactive (nothing connected)
END DESCRIPTION **********************************************************/

nodebug int MC35_Connected()
{
	if(BitRdPortI(PBDR, 2))	//PB2 is DCD line
	{
		return 0;
	}
	else
	{
		return 1;	//active low signal
	}
}	
/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_Ringing */
int MC35_Ringing();
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************************
MC35_Ringing                                 <MC35.LIB>

SYNTAX:		int MC35_Ringing();

DESCRIPTION: 	Returns true if the RI line is asserted, meaning the line is ringing.
		RI(输入)为低有效(检铃)
RETURN VALUE:	1 - RI line is active	0 - RI inactive (nothing connected)
END DESCRIPTION **********************************************************************/

nodebug int MC35_Ringing()
{
	if(BitRdPortI(PBDR, 3))	//PB3 is RI line
	{
		return 0;
	}
	else
	{
		return 1;	//active low signal
	}
}	
/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_Getc */
void MC35_Getc(char get_char);
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************
MC35_Getc                                 <MC35.LIB>

SYNTAX:		void MC35_Getc(char get_char);

DESCRIPTION: 	receives a character  to the MC35

PARAMETER1:	A character to be received to the MC35

END DESCRIPTION **********************************************************/

nodebug void MC35_Getc(char get_char)
{
	serCgetc(get_char);
}
/* --------------------------------------------------------------------- */
/*** BeginHeader CofMC35_Getc */
scofunc void CofMC35_Getc(char get_char);
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************
CofMC35_Getc                                 <MC35.LIB>

SYNTAX:		void CofMC35_Getc(char get_char);

DESCRIPTION: 	receives a character to the MC35. Yields to other tasks while
			receiving.

PARAMETER1:	A character to be received to the MC35

END DESCRIPTION **********************************************************/

nodebug scofunc void CofMC35_Getc(char get_char)
{
	wfd {cof_serCgetc(get_char); }
}	
/* --------------------------------------------------------------------- */
/*** BeginHeader MC35_Putc */
void MC35_Putc(char put_char);
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************
MC35_Putc                                 <MC35.LIB>

SYNTAX:		void MC35_Putc(char put_char);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -