现在完成了对DHT11数据读取并将数据传给TFT屏。而且用户如果有来电的话,程序会提取来电信息,把其号码作为发送信息的目标号码,将当前的DHT11的数据传给用户。
int main(void)
{
//由于使用UCOS,一下的初始化虽然可以在OS运行之前运行,但注意别使能任何中断.
ChipHalInit(); //片内硬件初始化
ChipOutHalInit(); //片外硬件初始化
OSInit(); //UCOS INIT~
os_err = OSTaskCreate(Task0, //第一个任务0
(void *)0, //不带参数
(OS_STK *)&Task0Stk[128 - 1],//堆栈指针
(INT8U )TASK1PRIO); //优先级
OSStart();
while(1);
}
void Task0(void *p_arg)
{
//u8 os_err;
OS_CPU_SysTickInit(); //使能SYSTICK中断
#if (OS_TASK_STAT_EN > 0)
// OSStatInit(); /*这东西可以测量CPU使用量 */
#endif
//创建事件和标志
CreatFlags();
//创建信号量
CreatSem();
os_err = OSTaskCreate(Task1, //任务1
(void *)0, //不带参数
(OS_STK *)&Task1Stk[128 - 1],//堆栈指针
(INT8U)TASK2PRIO); //优先级
os_err = OSTaskCreate(Task2, //任务2
(void *)0, //不带参数
(OS_STK *)&Task2Stk[128 - 1],//堆栈指针
(INT8U)TASK3PRIO); //优先级
os_err = OSTaskCreate(Task3, //任务3
(void *)0, //不带参数
(OS_STK *)&Task3Stk[128 - 1],//堆栈指针
(INT8U)TASK4PRIO); //优先级
OSTaskNameSet(TASK1PRIO, (INT8U *)"Task1", &err);
OSTaskNameSet(TASK2PRIO, (INT8U *)"Task2", &err);
OSTaskNameSet(TASK3PRIO, (INT8U *)"Task3", &err);
OSTimeDlyHMSM(0,0,2,0); //等待两秒 配置TC35
TC35_AT();
OSTimeDlyHMSM(0,0,0,500);
TC35_CNMI();
OSTimeDlyHMSM(0,0,0,500);
TC35_CLIP();
OSTimeDlyHMSM(0,0,0,500);
TC35_CMGF(1);
OSTimeDlyHMSM(0,0,0,500);
for(;;)
{
if(Choice==1)
TC35_CMGD(1);
if(Choice==2)
TC35_CMGR(1);
OSTimeDlyHMSM(0,0,2,0); //等待两秒
}
}
void Task1(void *p_arg)
{
for(;;)
{
OSTimeDlyHMSM(0,0,5,0); //等待5秒
DHT11_Init();
Start_Signal();//主机发开始信号
if(Read_Response())
{
Read_Byte();//读字节数
}
// PutChar(120,220,Tempreture+31,White,Magenta);
// PutChar(120,250,Humidity+31,White,Magenta);
// strcat(s_temp1,"'C");
GUI_Text(120,220,s_temp1,White,Magenta);
GUI_Text(132,220,"'C",White,Magenta);
strcat(s_temp2,"%");
GUI_Text(120,250,s_temp2,White,Magenta);
OSTimeDlyHMSM(0,0,10,0); //等待10秒
}
}
void Task2(void *p_arg)
{
INT32U TM;
uint8_t string[5]={0,0,0,0,0};
LED2_OFF;
OSTimeDlyHMSM(0,0,3,0); //等待两秒
GUI_Text(30,10,"XinJiang University",Red,White);
GUI_Text(20,40, "AT: OK",Black,White);
GUI_Text(20,70, "AT+CSMS=GSM: OK",Black,White);
GUI_Text(20,100,"AT+CMGF=1: OK",Black,White);
GUI_Text(20,130,"AT+CLIP=1: OK",Black,White);
GUI_Text(20,160,"AT+CNMI=2,1: OK",Black,White);
GUI_Text(20,190,"Have A Call: NO",Black,White);
GUI_Text(20,220,"Tempreture:",Black,White);
GUI_Text(20,250,"Humidity :",Black,White);
GUI_Text(20,280,"Time has passed:",Black,White);
PutChar(200,280,'S',Black,White);
for(;;)
{
// OSFlagPend(FlagPtr,(OS_FLAGS) 1,OS_FLAG_WAIT_SET_ALL,0,&err);
// LED2_ON;
TM = OSTimeGet();
TM=TM/1001;
sprintf((char *)string,"%d",TM);
GUI_Text(160,280,string,Black,White);
OSTimeDlyHMSM(0,0,1,0); //等待1秒
}
}
void Task3(void *p_arg)
{
char Send_String[20];
for(;;)
{
/* OSTimeDlyHMSM(0,0,2,0); //等待两秒
if(Tempreture>25&&Send_T==0)
{
TC35_ATD("13565809332");
//TC35_CMGS("");
Send_T=1;
}
*/
OSSemPend(ring_semp,0,&err);
strncpy(TEL,&RxBuffer1[14],11);
GUI_Text(120,190,TEL,Red,White);
OSTimeDlyHMSM(0,0,1,0); //等待两秒 挂机
TC35_ATH();///挂机
OSTimeDlyHMSM(0,0,8,0); //等待8秒 发送信息
strcpy(Send_String,"Tempreture:");
strcat(Send_String,s_temp1);
strcat(Send_String,"'C \rHumidity:");
strcat(Send_String,s_temp2);
TC35_CMGS(Send_String);
}
}
/*
给用户发送信息代码
* /
/////// TC35发送信息
void TC35_CMGS(char * String)
{
CMD = CMGS;
UartPrintf(USART1,"AT+CMGS=");
UartPrintf(USART1,&RxBuffer1[14]);
delay(50);
UartPrintf(USART1,"\r");
delay(50);
UartPrintf(USART1,(unsigned char *)String);
delay(50);
UartPutchar(USART1,0x1A);
CMD=0;
}
/*
提取来电信息,这里使用的TEXT格式,读取来电号码的方法有点笨,(从RxBuffer1[14]----RxBuffer1[24]是电话号码,根据前面对来电信息的分析得出的,太傻太笨了……呵呵 )以后再改进吧
*/
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)