CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with GSM and UART

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Zvasas
Guest







Problem with GSM and UART
PostPosted: Tue Apr 04, 2006 3:13 pm     Reply with quote

Hi all i have problem with connecting GSM to PIC.
I send data from PIC to GSM it'sall OK, but then i receiving data from GSM to PIC having problems, it's not corect data.


GSM sending

AT
OK

but i geting "PUH�" that is wrong ?

This is my code:

Code:

#include <16F628.h>
#include <string.h>
#use delay(clock=8000000)
#fuses hs, noprotect, nowdt, nolvp
#use rs232(baud=19200,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,stream=GSM)//Mobiliakoportas
#use rs232(baud=19200,parity=N,xmit=PIN_A3,rcv=PIN_A2,bits=8,stream=PC)//kompo portas

#define LED1 PIN_B4
#define LED2 PIN_B5
#define LED3 PIN_B6
#define BUT1 PIN_A0
#define BUT2 PIN_A1

const char SMSinit[] = "AT+CMGS=";        //duodama komanda kad bus pradeta siusti SMS
const char SMSinitEND[] = "\x0d";         //siunciama komanda AT+CMGS=XX kur XX yra bitu skaicius sekancio siuntimo
const char SMSStart[] = "0011000B91";     //pirmieji zinutes simboliai kurie nurodo zinutes tipa, numerio ilgi ir tt.
const char SMSbit[] = "0000AA";           //simboliai nurodantys zinute galiojimo laika ir tt.
const char SMSend[] = "\x1a\x0d";         //siunciame zinute <CRRL><Z>
const char ATDstart[] = "ATD+";
const char ATDEND[] = ";\x0d";
const char SMS[20] = "C526949AF5";              //zinutes tekstas (koduotas) siuo atveju "EMPTY"
const char SMSlenght[] = "05";                 //zinutes teksto ilgis "05" bus 5 simboliai ("0A" bus 10; 13 bus 19) simboliu
const char SMSnumber[] = "7360812481F7";      //telefono numeris y kuri bus siunciama zinute "37062546960" 'F'
const char SMSinitLNG[] = "18";                //zinute sudaro 13 + kiek sudaro zinutes tekstas
const char ATDnumber[] ="37061842187";                      //telefono numeris
int a,dial,smsas;

char simbolis;
char buferis[80] = "";
char atsakymas[] = "Kiaule";
int kintamasis = 0;

void init() { set_tris_a(0X0F);}          //nustatome RA_0,RA_1,RA_2,RA_3 kaip INPUT(iejimo)

void init_mobile()                        //Patikriname rysy su mobiliuojiu telefonu
{
char a,b;
loop:                                     //pradedame operacija "Loop"
 fprintf(PC,"AT\r\n");                        //siunciame komanda "AT"
    if(kbhit(PC)){a=fgetc(PC);}
    if(kbhit(PC)){b=fgetc(PC);}
    if(a=='O' && b=='K')                 //jeigu kintamasia a1=A o a2=T
    {
    output_high(LED2);
    delay_ms(200);
    }
    else
    {
    output_low(LED2);                   //kitu atveju sviesos dioda isjungeme
    delay_ms(200);
    goto loop;                            //kartojame nuo operacijos "Loop"
    }
}



void gaudom()
{
simbolis=fgetc(PC);
if(simbolis==0x0A ||simbolis==0x0D){kintamasis=0; fprintf(PC,"\r\nAtsakymas yra - "); goto galas;}
buferis[kintamasis]=simbolis;
kintamasis++;
fputc(simbolis,PC);
galas:
if(kintamasis==0)
 {
 if (strncmp(buferis,atsakymas,6)==0){fprintf(PC,"Teisingas\r\n");} else {fprintf(PC,"Neteisingas\r\n");}
 strcpy(buferis,"");
}
}

void gaudom_gsm()
{
simbolis=fgetc(GSM);
if(simbolis==0x0A ||simbolis==0x0D){} else fputc(simbolis,PC);
}

void Call()                               //Skambinimas
{
fprintf(GSM,ATDstart);
fprintf(GSM,ATDnumber);
fprintf(GSM,ATDEND);
delay_ms(500);
}

Void main()
{
int a=0;
init();
output_high(LED1);
output_high(LED2);
output_high(LED3);
delay_ms(1000);
output_low(LED1);
output_low(LED2);
output_low(LED3);
delay_ms(1000);
pradzia:
 //if(kbhit(PC)){output_high(LED3);gaudom(); goto pradzia;} else {output_low(LED3);}
 if(kbhit(GSM)){gaudom_gsm(); goto pradzia;}
 if(!input(BUT1)){ fprintf(PC,"Patikrinimas\r\n");}
 if(!input(BUT2) && a==0){fprintf(PC,"Paspaustas AT\r\n"); fprintf(GSM,"AT\r\n");a=1;} else if(input(BUT2)) {a=0;}
goto pradzia;
}


GSM phone connected directly.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group