当单片机与电脑通信时,串口助手显示如下:
我独自用电脑操作串口助手发送AT指令,SIM800A成功发送信息:
但当我单片机与SIM800A通信时,SIM800A没有执行指令。想请教各位专家是什么原因?接线如下:
代码如下:
- #include<REGX52.H>
- #include<intrins.h>
- #include "Delay.h"
- #include "LCD1602.h"
- #include "ADC0832.h"
- #include<stdio.h>
- #define FOSC_110592M
- #define uchar unsigned char
- #define uint unsigned int
- unsigned int AD_X;
- unsigned int AD_Y;
- unsigned int rec_data_len_uart=0;
- unsigned char idata Buffer_Uart0_Rec[25]={0};
- void SerialInti()
- {
- TMOD=0x20;
- #ifdef FOSC_12M
- TH1=0xf3;
- TL1=0xf3;
- #else
- TH1=0xfd;
- TL1=0xfd;
- #endif
- TR1=1;
- SM0=0;
- SM1=1;
- REN=1;
- EA=1;
- ES=1;
- }
- void Serial_interrupt() interrupt 4
- {
- unsigned char temp_rec_data_uart0;
- temp_rec_data_uart0 = SBUF;
- RI=0;
- Buffer_Uart0_Rec[rec_data_len_uart]=temp_rec_data_uart0;
- rec_data_len_uart++;
- if(rec_data_len_uart>24)
- {
- rec_data_len_uart=0;
- }
- }
- void Uart1Send(uchar c)
- {
- SBUF=c;
- while(!TI);
- TI=0;
- }
- void Uart1Sends(uchar *str)
- {
- while(*str!='\0')
- {
- Uart1Send(*str);
-
-
-
- str++;
- }
- }
- void main()
- {
- LCD_Init();
- SerialInti();
- LCD_ShowString(1,1,"X Y");
- Delay(10000);
- while(1)
- {
- AD_X=ADC0832(1);
- LCD_ShowNum(2,1,AD_X,3);
- AD_Y=ADC0832(0);
- LCD_ShowNum(2,6,AD_Y,3);
- if((AD_X<=47 || AD_X>=126) || (AD_Y>=141 || AD_Y<=57))
- {
-
- Uart1Sends("AT\r\n");
- Delay(2000);
- Uart1Sends("AT+CSCS=\"UCS2\"\r\n");
- Delay(2000);
- Uart1Sends("AT+CMGF=1\r\n");
- Delay(2000);
- Uart1Sends("AT+CSCA?\n");
- Delay(2000);
- Uart1Sends("AT+CSMP=17,167,0,25\r\n");
- Delay(2000);
- Uart1Sends("AT+CMGS=\"00310039003100360037003500340036003700320034\"\r\n");
-
-
- Delay(2000);
- Uart1Sends("4F7F7528800553EF80FD64545012FF0C8BF7524D5F800058005800585E2E52A9FF01");
- Uart1Send(0x1a);
- Delay(8000);
- }
- Delay(100);
- }
- }
复制代码 |