完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include"reg52.h" #include"delayms.h" #include"lcd12864.h" #include"I2C.h" #include"ds.h" #include"string.h" #include"intrins.h" #include"RTX51tiNY.H" #define uint unsigned int #define uchar unsigned char #define PCF8591 0x90 ***it beet=P1^5; ***it red=P1^7; //GSM数据设置 uchar xdata user_date[50]; uchar user_num,k=0; //LCD显示数据设置 uchar xdata user_name[]={" 毕业设计 "}; uchar xdata tem[]={"temp: 'C "}; uchar xdata smoke[]={"smoke: ppm "}; uchar xdata POL[]={"somebady "}; /****************************************/ //定义信号量 struct sem_set { uchar max_count; /*该信号的最大计数值*/ uchar count; /*该信号的当前计数值*/ uint pending_tasks; /*等待该信号的量任务表*/ }sem_tab[3]; //初始化信号量 #pragma disable void init_semaphore(uchar sem_id,max_count,uchar count) { sem_tab[sem_id].max_count=max_count; sem_tab[sem_id].count=count; sem_tab[sem_id].pending_tasks=0; } //等待信号量 #pragma disable char pend_sem(uchar sem_id) { if(sem_tab[sem_id].count>0) { sem_tab[sem_id].count-=1; /*获取信号量*/ return(-1); } sem_tab[sem_id].pending_tasks=(1< } void pend_semaphore(sem_id) { if(pend_sem(sem_id)==0) while(os_wait(K_TMO,255,0)!=RDY_EVENT); /*等待,直到任务就绪*/ } //释放信号量 #pragma disable char post_sem(uchar sem_id) { uchar i; uint temp=1; if(sem_tab[sem_id].count>0||sem_tab[sem_id].pending_tasks==0) { if(++(sem_tab[sem_id].count)>sem_tab[sem_id].max_count) sem_tab[sem_id].count=sem_tab[sem_id].max_count; return(-1); } for(i=0;i<16;i++) { if((sem_tab[sem_id].pending_tasks&(temp))!=0) { if(sem_tab[sem_id].pending_tasks&~(1< return(i); /*返回等待信号量的任务号*/ } temp<<=1; } } void post_semaphore(uchar sem_id) { char task_id; task_id=post_sem(sem_id); if(task_id!=-1) { os_set_ready(task_id); os_switch_task(); } } /****************************************/ uchar redsun(void) { if(red==0) { delayms(300); if(red==1) delayms(300); return 1; } else return 0; } void play(uchar t) { uchar i; for(i=0;i<100;i++) { beet=~beet; delayms(t); } beet=0; } //串口初始化 void ES_init(void) { TMOD=0x20; TH1=0xfd; TL1=0xfd; TR1=1; REN=1; SM0=0; SM1=1; EA=1; ES=1; } //串口中断处理 void es_interrupt() interrupt 4 { uchar date; date=SBUF; user_date[user_num++]=date; if(user_num>=50) user_num=0; else RI=0; } //发送数组型数据函数 void GSMsenddate(uchar *str) { while(*str!=' |