我正在尝试将我的诺基亚 N95 与 Proteus 接口。它几乎可以正常工作,除了一件事。当我想从调制解调器获得响应时,我使用unsigned char input[20]
and scanf("%s",input)
。当调制解调器收到呼叫时,它会发送RING
到端口,但我得到的scanf
是RIG
or RNG
。可能是什么问题?
#include <regx51.h>
#include <stdio.h>
#include <string.h>
sbit TE = P2^4;//for transmitting
unsigned char ch;
unsigned char ch2;
long i;
short bakar=0;
unsigned char Command_AT[]="AT\r";
unsigned char xdata Command_CPIN[]="AT+CPIN =\"0000\"\r";
unsigned char Command_CMGF[]="AT+CMGF=1\r";
unsigned char Command_CMGS[]="AT+CMGS =\"5555\"\r";
unsigned char msg_report[]="Ok";
unsigned char CtrlZ=0x1A;
unsigned char xdata Status_Ok[]="AT\rOK";
unsigned char Command_CHUP[]="AT+CHUP\r";
unsigned char input[10];
void iniSerial()
{
TMOD=0x20;
TH1=0XFD;
SCON=0x50;
TR1=1;
TI=1;
RI=0;
}
void delay()
{
for(i=1;i<=30000;i++); //Dont know how much exactly
}
void delay2()
{
for(i=1;i<=50000;i++);
}
void sendDeliveryReport()
{
puts(Command_AT);
delay();
puts(Command_CMGF);
delay();
puts(Command_CMGS);
delay();
puts(msg_report);
while(TI == 0);
SBUF = 0x1A;
}
void checkRing()
{
while(bakar!=1)
{
scanf("%s",&input);//problem is here
if(strcmp(input,"RING") == 0)
{
bakar=1;
delay();
puts(Command_CHUP);
}
delay2();
}
}
void main()
{
delay2(); //Wait for GSM modem to start.
TE=1; //Don't trasmit yet
iniSerial();
checkRing();
TE=0;
iniSerial();
sendDeliveryReport();
while(1); //Pause forever
}