嗨,我的任务是在中继上,每当有来自发送者的消息,中继之后,应该有一个确认消息给发送者,中继***作。没有确认消息,我的中继***作,但是每当我插入一个函数来发送一个消息时,我的代码就会出现故障。继电器操作,也没有消息。我不明白为什么会这样。我只是尝试发送MSG,然后它的OK,但在while循环,它没有显示任何结果,在这里接收消息我已经使用中断服务例程。下面我附上代码请通过它,告诉我哪里错了You酸奶
以上来自于百度翻译
以下为原文
hi ,
my task is to On the relay whenever there is message from sender , after relay on there should be acknowledge message to sender that relay is operated.without acknowledge message my relay is operated , but whenever i inserted a func
tion for sending a message my code get malfunctioning ,neither relay operated nor message . i could not understand why this happening. i simply tried for sending msg then its ok but in while loop it is not showing any result,
here to receive message i have used interrupt service routine.below i have attached code please go through it ,
and tell me where i am wrong
thanking you
yogesh
///////////////////////////////////////////
//LCD decleration//
#define TRUE 1
#define bool_val_1 flags. f0
#define LCD_DIR TRISD
#define CTRL_DIR TRISB
#define LCD PORTD
#define RS PORTB.F0
#define E PORTB.F1
#include"lcd.h"
//////////////////////////////////////////////////////
#define STRLEN 55
#define index 2
unsigned char flag=0;
unsigned char flag1=0;
volatile int flag2=0;
unsigned char t,send;
volatile unsigned char rcindex;
volatile unsigned char rcbuf[STRLEN];
unsigned char num[]="918208996450";
unsigned char i,j;
unsigned char rcvd[13];
unsigned char Msg[]="Relay On";
unsigned char num1[12];
unsigned char count;
void UART_Init(void)
{
TXSTA.TXEN=1; // enable transmitter
TXSTA.BRGH=1; // enable high baud rate
RCSTA.CREN=1; // continuous data receiption
//configure input output
TRISC.TRISC6=1; // rRX pin as a input
TRISC.TRISC7=1; // TX pin as a input
TRISC.TRISC0=1;
SPBRG=103; // set buad rate 9600
PIE1.RCIE=1; //enable USART receive interrupt
RCSTA.SPEN=1; //enable USART
}
///////////Initialise Message///////////////
void Init_Msg()
{
UART1_Write_Text("AT+CMGS="+918446323311"r");
delay_ms(500);
UART1_Write_text("Relay Opearted r");
UART1_Write(26);
UART1_Write(0x1A);
}
void main() {
INTCON.PEIE=1; //enable interrupt
INTCON.GIE=1; // enable globle interrupt
CTRL_DIR=0X00;
LCD_DIR=0X00;
init_lcd();
delay_ms(500);
//Init_gsm();
UART_Init();
delay_ms(500);
UART1_Write_Text("ATE0rn");
delay_ms(500);
//USART_puts("intialisation in complete!n");
// UART1_Write_Text("AT+CPBR=3rn");
delay_ms(500);
UART1_Write_Text("AT+CMGF = 1r");
Delay_ms(1000);
UART1_Write_Text("AT+CNMI=2,2,0,0,0r");
Delay_ms(1000);
cmd_lcd(0x80);
string_lcd("Init Complete");
while(1)
{
if(flag)
{
// check();
//cmd_lcd(0x80);
//string_lcd(rcbuf);
for(i=8;i<20;i++)
{rcvd[i-8]=rcbuf
;}
if(rcvd[0]=='9')
{
if(rcvd[1]=='1')
{
if(rcvd[2]=='8')
{
if(rcvd[3]=='2')
{
if(rcvd[4]=='0')
{
if(rcvd[5]=='8')
{
if(rcvd[6]=='9')
{
if(rcvd[7]=='9')
{
if(rcvd[8]=='6')
{
if(rcvd[9]=='4')
{
PORTB.F6=1;
delay_ms(500);
PORTB.F6=0;
delay_ms(1000);
UART1_Write_Text("AT+CMGS="+918446323311"r");
delay_ms(500);
cmd_lcd(0x80);
string_lcd(rcbuf);
delay_ms(1000);
UART1_Write_text("Relay Opearted ");
UART1_Write(26);
UART1_Write(0x1A);
}}}}}}}}}}
flag=0;
}
}
}
void interrupt(void)
{
if(PIR1.RCIF) //check the receive interrupt flag has fired
{
t=RCREG;
if((t!='n')&&(rcindex
{
rcbuf[rcindex]=t;
if(rcbuf[0]=='+')
{
rcindex++;
}
else
{
rcindex=0; //reset string index
flag=0;
}
}
else
{
flag=1;
rcindex=0;}
}
PIR1.RCIF=0;
}