Я пишу код для создания модуля, который включает порт микроконтроллера через смс. Я использую Pic16F88 и модуль Sim900, я программирую в mplab X и XC8. Это работает в Proteus, но нет в схеме, я решил проблемы с энергопотреблением с некоторыми конденсаторами, поэтому я думаю, что проблема в коде. Может быть, модуль не распознает символ \ r как возврат каретки ??
/*
* File: ContGsmMain.c
* Author: camil
*
* Created on 28 de enero de 2020, 22:08
*/
// CONFIG1
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off)
#pragma config CCPMX = RB0 // CCP1 Pin Selection bit (CCP1 function on RB0)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
// CONFIG2
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal External Switchover mode disabled)
#define _XTAL_FREQ 8000000
#include <xc.h>
#include "pic16f88.h"
#include "uart.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
//Funcion retorna la posición donde comienza la cadena seleccionada
int existe(char linea[], char busq[]);
void main(void) {
TRISA=0; // Program Init
TRISB=0x04;
PORTA=0;
PORTB=0;
OSCCON = 0b01111100;
UART_Init(9600);
__delay_ms(200);
int porta[8]={0,0,0,0,0,0,0,0}; //Variable declaration
char buffer[80]="";
char *buff;
char textbuf[10]="";
int i=0,e=0;
buff=buffer;
RA3=1; //Module Init
__delay_ms(3000);
RA3=0;
UART_Write_Text("AT+CMGF=1\r");
__delay_ms(100);
UART_Write_Text("AT+IPR=9600\r");
__delay_ms(100);
UART_Write_Text("AT+CNMI=2,2,0,0,0\r");
__delay_ms(100);
while(1){
if(RCIF==1){ // Try if message is received
for(i=0;i<80;i++){
while(!RCIF);
buff[i]=UART_Read();
if(buff[i]=='\r')
break;
}
/* itoa(textbuf,existe(buff, "L"),10 ); //Debugging segment
UART_Write_Text(textbuf); */
if(existe(buffer, "L")==1) {
porta[2]=!porta[2];
RA2=porta[2];
/* itoa(textbuf,porta[3],10 ); //Debugging segment
UART_Write_Text("Existe ");
UART_Write_Text(textbuf);
UART_Write_Text("\r");*/
}
for(i=0;i<80;i++) buff[i]=0;
}
}
}
int existe(char linea[], char busq[]){
int e=0,a=0;
char *carpal, *carbus;
carpal=linea;
carbus=busq;
for(e=0;e<strlen(linea);e++){
if(carpal[e]==carbus[a]){
a++;
if(a==strlen(busq)){
return 1;
}
continue;
}
else a=0;
}
return 0;
}