GSM调制解调器和PIC16F877A [英] GSM Modem and PIC16F877A

查看:68
本文介绍了GSM调制解调器和PIC16F877A的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,



我通过PIC16F877A传送GSM调制解调器(SIMCOMM300),能够正常发送和接收短信/电话。但是,当我接收到RING时发出AT + CLCC命令,要知道呼叫者号码我能够接收到对AT + CLCC命令的响应,而且我能够处理所有命令,然后是AT + CLCC。但问题是我无法处理另一个来电(RING)或短信。程序挂起。我不知道问题出在哪里。所以,为了您的方便,我在这里给你代码。如果有任何错误,请转到代码并纠正我。对所有提供帮助的人,我将非常感恩和谦虚。预谢谢。

Dear Sir,

I communicated GSM Modem (SIMCOMM300) from PIC16F877A and can able to send and recieve SMS/Calls fine. But, when i issue AT+CLCC command when the GSM receives RING, to know the caller number I can able to receive the response to the "AT+CLCC" command and also I can able to process all the commands followed by "AT+CLCC". But whats the problem is I can't able to process another incoming call (RING) or SMS. Program hangs. I don't know where the problem is. So, I give you the code here for your convenience. Pl go thro' the code and correct me if there is any error. I will be very thankful and humble to all who provide help. Advance thanks.

#include <stdio.h>
#include <htc.h>
#include "usart.h"
#include "lcd.h"
#include "string.h"

__CONFIG(HS & WDTDIS & UNPROTECT &  LVPDIS);

unsigned char gsmInput[60];
unsigned int i=0;
unsigned int lenOfGSMInput = 0;

bit OK;
bit Error;
bit Ring;

void showGSM_DATA(char GSM_DATA[]){ //to show the GSM OUTPUT after eliminating the chars '\r' and '\n'
    
    if (strcmp(GSM_DATA, "OK") == 0){ 
        OK = 1;
    }
    else if (strcmp(GSM_DATA, "ERROR") == 0){
            Error = 1;
    }
    else if (strcmp(GSM_DATA, "RING") == 0){
       
        Ring = 1;
        
        GSM_DATA[0] = '\x00';
        puts("AT+CLCC");
        putch(0x0D);
        
    }
    else{
        lcd_clear();
        lcd_goto(0);
        lcd_puts(GSM_DATA);
    }
  GSM_DATA[0] = '\x00';
 
} // end function showGSM_DATA

void main(int argc, char* argv[]){

	unsigned char input;
       
	INTCON=0;	// purpose of disabling the interrupts.
    
	lcd_init(); // initiate LCD
	
	init_comms();	// set up the USART - settings defined in usart.h
    			    
    puts("ATE0");
    putch(0X0D);
    
    puts("AT+CMGF=1");
    putch(0X0D);
    
    while(1){
		               
        input = getch();	// read a response from the GSM
        
        switch(input){
            
            case '\x0A': // if line feed detected in the GSM output i.e. '\n'
                        break;
            case '\x0D': // if carriage return detected i.e. '\r'
                        gsmInput[i] = '\x00';
                        
						lenOfGSMInput = strlen(gsmInput);
                        if (lenOfGSMInput > 0){
                            i = 0;
                            lenOfGSMInput = 0;
                            showGSM_DATA(gsmInput);
                        }
                        break;
            case '\x3E': // if greater-sign (in order to send SMS)
                        break;
            
        default: // if characters received
                gsmInput[i] = input;
                i++;
                break;
        }//end brace for switch
	} //end brace for while loop
}//end brace for main</htc.h></stdio.h>

推荐答案

默认代码看起来很危险:你确定 i 将无法达到 60 因此超出缓冲区?
The default code looks dangerous: are you sure i won't reach 60 thus overruning the buffer?


检查 GSM_DATA [ ] 因为代码原样,如果碰巧有一个额外的空格, strcmp()将不会导致0(即如果有的话)字符串开头的空格。)
Check GSM_DATA[] because with the code as is, if there happens to be an extra blank space, strcmp() will not result in 0 (i.e. if there's a blank space at the beginning of the string).


这篇关于GSM调制解调器和PIC16F877A的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆