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

📄 task.c

📁 51单片机_RTOS方式控制GSM模块TC35I源程序. 希望对大家有用。
💻 C
字号:

void SET_TC35(uchar *in,uchar len)
{
	uchar data temp ;
	temp = 0 ;
    while(temp != TC35_OK)
    {
    	OSWait(K_TMO,250);
    	PutString(in,len) ;							//send command
    	OSQPend(&temp,CommandData,250) ;            // 等待消息
    }
}

void Task_init(void)
{
	uint8 data temp ;
	
	Set_HardReset();
	
	for(temp=0;temp<16;temp++)
	{
		OSWait(K_TMO,250);
	}
	OSQCreate(CommandData, 15);
    OSQCreate(SerialInData, 20);
    OSQCreate(SerialOutData, MaxSerialDataLen);
    Serial_Init();                               // 初始化串行口
    SerialDLength = 0 ;
    OSWait(K_TMO,250);
    OSWait(K_TMO,250);
    
    SET_TC35("ATE\r",4) ;
    SET_TC35("AT^SSYNC=1\r",11) ;
    SET_TC35("AT+IPR=9600\r",12) ;
    SET_TC35("AT^SNFS=3\r",10) ;
    SET_TC35("AT+CLIP=1\r",10) ;
//	SET_TC35("AT+CNMI=1,1,0,0,1\r",18) ;
//  SET_TC35("AT&w\r",5) ;
    
    temp = 0 ;
    while(temp != TC35_REGISTERED)
    {
    	PutString("AT+CREG?\r",9) ;				//是否登陆网络
    	OSWait(K_TMO,250);
    	OSWait(K_TMO,250);
    	OSWait(K_TMO,250);
    	OSWait(K_TMO,250);
    	OSWait(K_TMO,250);
    	OSWait(K_TMO,250);
    	OSQPend(&temp,CommandData,250) ;               // 等待消息
    }
    
	SET_TC35("AT+CNMI=1,1,0,0,1\r",18) ;
    SET_TC35("AT&w\r",5) ;

	while(1)
	{
		RING = 0 ;
		RING = 0 ;
		while(1) ;
	}
}

void Serial_Dial(void)
{
	uint8 data temp ;
	while(1)
	{
		while(OSQPend(&temp,SerialInData,200) == OS_Q_OK)
		{
			if(temp != ENDFLAG)
			{
				SerialDBuf[SerialDLength] = temp ;
				if(SerialDLength < MaxSerialDataLen-1) SerialDLength++ ;
				continue ;
			}
			else
			{
				SerialDLength -= 1 ;
				if((SerialDLength == 0)||(SerialDBuf[SerialDLength] != 0x0d))
				{
					SerialDLength = 0 ;
					continue ;
				}
				else
				{
					if(mem_Include(SerialDBuf,"OK",SerialDLength,2) == TRUE)
					{
						OSQPost(CommandData, TC35_OK);
					}
					else if(mem_Include(SerialDBuf,"ERROR",SerialDLength,5) == TRUE)
					{
						OSQPost(CommandData, TC35_ERROR);
					}
					else if(mem_Include(SerialDBuf,"BUSY",SerialDLength,4) == TRUE)
					{
						OSQPost(CommandData, TC35_BUSY);
					}
					else if(mem_Include(SerialDBuf,"NO CARRIER",SerialDLength,10) == TRUE)
					{
						OSQPost(CommandData, TC35_NOCARRIER);
					}
					else if(mem_Include(SerialDBuf,"+CREG",SerialDLength,5) == TRUE)
					{
						temp = mem_query(SerialDBuf,SerialDLength,',',1) ; 	//
						if((temp != 0xff)&&(temp < SerialDLength))
						{
							if((SerialDBuf[temp+1] == '1')||(SerialDBuf[temp+1] == '5'))	//登陆网络
							{
								OSQPost(CommandData, TC35_REGISTERED);
							}
						}
					}
				/*	else if(mem_Include(SerialDBuf,"+CLIP:",SerialDLength,6) == TRUE)
					{
						temp = mem_query(SerialDBuf,SerialDLength,',',1) ; 	//
						if((temp != 0xff)&&(temp < SerialDLength))
						{
							Callid_buf[0] = temp-9 ;
							mem_asctohex(Callid_buf+1,SerialDBuf+8,Callid_buf[0]) ;
							ACC = Sys_TimerReqire(OTimerID1,70,0) ;			//定时7秒如果没有振铃,就清除振铃
							OSQPost(CommandData, TC35_CALLID_COME);
						}
					}*/
				}
				SerialDLength = 0 ;
			}
		}
	}
}

⌨️ 快捷键说明

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