Suirank Suirank
快交出你的胖次
关注数: 63 粉丝数: 153 发帖数: 4,043 关注贴吧数: 22
新人求问 #include <reg52.h> #include <intrins.h> #include <string.h> #include <stdio.h> #define uint unsigned int #define uchar unsigned char sbit red_1=P1^0; sbit red_2=P1^1; sbit red_3=P1^2; sbit red_4=P1^3; sbit red_5=P1^4; sbit led_1=P0^7; #define MAXCHAR 81 uchar aa[MAXCHAR]; code uchar ATE0[]="ATE0\r\n"; code uchar CREG_CMD[]="AT+CREG?\r\n"; code uchar SMS_send[]="AT+CMGS=18\r\n"; code uchar ATCN[]="AT+CNMI=2,1\r\n"; code uchar CMGF0[]="AT+CMGF=0\r\n"; code uchar CMGF1[]="AT+CMGF=1\r\n"; code uchar CMGR[12]="AT+CMGR=1\r\n"; code uchar CMGD[12]="AT+CMGD=1\r\n"; #define CALL_YOU_TELNUMBER "ATD18113974162;\r\n" #define SEND_MESSA_TO_YOUR "at+cmgs=\"18113974162\"\r\n" #define SEND_MESSA_CONTENT "warning" uchar a,j=0,flag=0; int g_timeout=0; void delay(uint ms) { uchar i; while(ms--) { for(i=0;i<120;i++); } } Print_Char(uchar ch) { SBUF=ch; while(TI!=1); TI=0; } Print_Str(uchar *str) { while(*str!='\0') { Print_Char(*str); delay(2); str++; } } Ini_UART(void) { SCON = 0x50 ; TMOD |= 0x20 ; PCON |= 0x80 ; TH1 = 0xFA ; TL1=0xFA; IE |= 0x90 ; TR1 = 1 ; TI=1; ES=1; EA=1; EX0=0; IT0=0; } void clearBuff(void) { for(j=0;j<MAXCHAR;j++) { aa[j]=0x00; } j=0; } void led(int i) { P0 |= i; delay(20); P0 &= ~i; delay(20); P0 |= i; delay(20); P0 &= ~i; } int Hand() { delay(10); if(strstr(aa,"OK")!=NULL) { g_timeout=0; return 1; } if(g_timeout>50) { g_timeout=0; return -1; } g_timeout++; return 0; } void AT(void) { clearBuff(); Print_Str(ATE0); delay(50); while(strstr(aa,"OK")==NULL) { delay(50); led(0x01); clearBuff(); Print_Str(ATE0); } led(0x02); Print_Str(ATCN); delay(50); while(1) { clearBuff(); Print_Str(CREG_CMD); delay(50); if(((aa[9]=='0')&&(aa[11]=='1'))||((aa[9]=='0')&&(aa[11]=='5'))) { clearBuff(); led(0x08); break; } else { clearBuff(); led(0x04); delay(50); } } } void send_english() { P0=0XFF; clearBuff(); Print_Str(CMGF1); delay(100); led(0x01); Print_Str(SEND_MESSA_TO_YOUR); delay(300); led(0x02); Print_Str(SEND_MESSA_CONTENT); delay(10); Print_Char(0x1A); delay(10); led(0x04); clearBuff(); delay(3000); delay(3000); } void send_call() { clearBuff(); delay(100); Print_Str(CALL_YOU_TELNUMBER); clearBuff(); delay(3000); delay(3000); } void main() { Ini_UART(); AT(); delay(10); clearBuff(); Print_Str(CMGD); delay(50); while(Hand()==0); clearBuff(); Print_Str(CMGF1); delay(30); Print_Str(ATCN); delay(30); send_english(); while(1) { if(strstr(aa,"+CMTI")!=NULL) { clearBuff(); Print_Str(CMGF1); delay(50); while(Hand()==0); clearBuff(); Print_Str(CMGR); delay(100); if(strstr(aa,"1")!=NULL) { EX0=1; } else if(strstr(aa,"2")!=NULL) { EX0=0; } clearBuff(); Print_Str(CMGD); delay(50); while(Hand()==0); clearBuff(); } } } void ser() interrupt 4 { if(RI==1) { aa[j]=SBUF; RI=0; j++; } } 主函数里while之前都能很快运行,到while了,给信号几乎要3分钟才会有响应,这是怎么回事啊
1 下一页