Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

sim300 cant send ctrlZ ..its showing -> when im sending 26 =ctrl+z=0x1a;pic16f877a

Status
Not open for further replies.

bakiyaraj

Newbie level 4
Joined
May 10, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,359
target16f877a, compiler hitech c ...couldnt send ctrlz to send sms it giving arrow mark when i send ox1a...please help sort this out thanks for your time guys



#include<htc.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 11059200
#endif

void tx(unsigned char);
void stx(unsigned const char*);
void gsmsend(unsigned char*);
void uart_init(void);
unsigned char *text="STATUS OF THE DEVICE";
unsigned char *cmd_sendsms="AT+CMGS=";
unsigned char *mobile_no="09845138163";
unsigned char enter=0x0D;
unsigned char ctrlz=0x1A;
unsigned char newline=0x0A;
void main()
{

uart_init();
__delay_ms(7000);
gsmsend(text);
while(1);
}


void tx(unsigned char t)
{
TXREG=t;
while(PIR1bits.TXIF == 0);
PIR1bits.TXIF = 0;
}

void stx(unsigned const char *s)
{
while(*s)
{
tx(*s);
while(PIR1bits.TXIF == 0);
PIR1bits.TXIF = 0;
s++;
}

}

void gsmsend(unsigned char *string)
{

//puts("AT");
//putch(0x0D);
//tx(newline);
stx("AT");tx(enter);tx(newline);
__delay_ms(1000);
stx("AT+CMGF=1");tx(enter);tx(newline);
__delay_ms(1000);
stx(cmd_sendsms);
__delay_ms(1000);
tx(0x22);
__delay_ms(2);
stx(mobile_no);
__delay_ms(2);
tx(0x22);
__delay_ms(2);
tx(enter);
__delay_ms(2);
tx(newline); //goto next line
__delay_ms(2);
stx(string);
__delay_ms(5000);
tx(newline);
tx(enter);
tx(ctrlz);
__delay_ms(1000);

}



void uart_init(void)
{
TRISC7 = 1;
TRISC6 = 0;
//TRISC =0x81;
SPBRG = 71; // BAUD RATE; 9600 with 11.0592mhz 71 IS DECIMAL; HIGH SPEED
//SPBRG = 5; // 115200 BRGH = 1; 11.0592 Mhz
// SPBRG = 129; // 9600 brgh = 1; 20 Mhz
// SPBRG = 64; // 19200 brgh = 1; 20 Mhz
TXSTA = 0x24;
RCIE =1 ; GIE =1; PEIE =1;
RCSTA = 0x90;
}
 

Re: sim300 cant send ctrlZ ..its showing -> when im sending 26 =ctrl+z=0x1a;pic16f877

It doesnt matter wat its showing
try this by simulating in Proteus using virtual COMPIM
it will use your PC serial port and you can connect your modem to it
its also adviced to install serial port monitor from HDD
 

Re: sim300 cant send ctrlZ ..its showing -> when im sending 26 =ctrl+z=0x1a;pic16f877

Thanks for prompt response. Any other solution without installing that. did you find any logical problem.
 

Re: sim300 cant send ctrlZ ..its showing -> when im sending 26 =ctrl+z=0x1a;pic16f877

you welcome
its a adviced not to put delays...wait for relative reply from the modem
like after AT+CMGF=1, modem reponse must be "OK"
sometime modem takes more time specially after sending sms
and its very good to have a proteus ISIS, it will help you alot to test ur code and circuit.
HDD is just give you an idea whats going on at RS232 port level
 

Re: sim300 cant send ctrlZ ..its showing -> when im sending 26 =ctrl+z=0x1a;pic16f877

I did check for ok . The problem now is its giving ok when i connect to hyper terminal but when i connect to pic controller its not giving the ok....could you pls take a look at code...it will be really helpful for me..I already spent much time dude...Thanks for your valuable time.


#include<htc.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 11059200
#endif


void tx(unsigned char);
void stx(unsigned const char*);
void gsmsend(unsigned char*);
unsigned char receiver();
void uart_init(void);

unsigned char *text="STATUS OF THE DEVICE";
unsigned char *cmd_sendsms="AT+CMGS=";
unsigned char *mobile_no="09986592825";
unsigned char enter=0x0D;
unsigned char ctrlz=0x1A;
unsigned char newline=0x0A;

unsigned char *initial="GSM is initializing";
unsigned char received[5];

void main()
{

uart_init();
__delay_ms(7000);
stx(initial);
gsmsend(text);
while(1);
}


void tx(unsigned char t)
{
TXREG=t;
while(PIR1bits.TXIF == 0);
PIR1bits.TXIF = 0;
}

void stx(unsigned const char *s)
{
while(*s)
{
tx(*s);
while(PIR1bits.TXIF == 0);
PIR1bits.TXIF = 0;
s++;
}

}

unsigned char receiver()
{
unsigned char x;
for(x=0;x<3;x++)
{
received[x]=RCREG;
while(RCIF==0);
RCIF=0;
}
}

void gsmsend(unsigned char *text)
{



//stx("AT");tx(enter);tx(newline);
//receiver();
//__delay_ms(5000);
stx("AT+CMGF=1");
receiver();
//__delay_ms(5000);

if(received[0]== 'O' && received[1]== 'K')
{
tx(enter);
tx(newline);

stx(cmd_sendsms);

tx(0x22);

stx(mobile_no);

tx(0x22);
tx(newline);
tx(enter);



stx(text);
tx(newline);
tx(enter);

tx(newline);

tx(enter);


tx(ctrlz);


}
else
stx("GSM is not ready");


}



void uart_init(void)
{
TRISC7 = 1;
TRISC6 = 0;
//TRISC =0x81;
SPBRG = 71; // BAUD RATE; 9600 with 11.0592mhz 71 IS DECIMAL&47 is hex; HIGH SPEED
//SPBRG = 5; // 115200 BRGH = 1; 11.0592 Mhz
// SPBRG = 129; // 9600 brgh = 1; 20 Mhz
// SPBRG = 64; // 19200 brgh = 1; 20 Mhz
TXSTA = 0x24; //TXEN is enabled, BRGH - asynchronous and high speed enalbed and
RCSTA = 0x90;//receiver status and control register; 1.serial port enabled 2. continuous receiver enabled and single recive enable
RCIE =1; // receiver interrupt
//TXIE=1; //Transmitter enable bit
GIE =1; PEIE =1;

}
 

Re: sim300 cant send ctrlZ ..its showing -&gt; when im sending 26 =ctrl+z=0x1a;pic16f877

have you made its hardware or simulating it?
if you have made its hardware then try to connect it to your PC and communite between then just to test
I use Proton BASIC compiler here is my working code

NO_MOBILE_CONNECTED:
Print At 1,1,"MODEM FiNDing..."
DelayMS 1000
HSerOut ["AT",13] 'Sending "AT" and Carraige return to GSM module ' If its ok, the it will send a response back OK
HSerIn 3000, NO_MOBILE_CONNECTED,[Wait("OK")] ' wait for response ok for 3 seconds
Cls
Print At 1,1,"MODEM FOUND..."
DelayMS 1000
HSerOut ["AT+CMGF=1",13]
HSerIn 3000,NO_MOBILE_CONNECTED,[Wait("OK")] ' wait for response ok for 3 seconds

Print At 1,1,"SENDING SMS"
MOBILE_CONNECTED:
HSerOut ["AT+CMGS=",34,"+92xxxxxxxx",34,13]
HSerIn 8000,MOBILE_CONNECTED,[Wait(">")]
DelayMS 500
HSerOut ["TEMP: ",Dec1 TEMPERATURE,13,"BPM:",Dec2 bpm,26]
HSerIn 10000,MOBILE_CONNECTED,[Wait("OK")]
DelayMS 1000
Cls
Print At 1,1,"SMS SENT"

- - - Updated - - -

and inverted commas are necessary in AT+CMGS command before and after the destination number
and i think u r missing it
 

Re: sim300 cant send ctrlZ ..its showing -&gt; when im sending 26 =ctrl+z=0x1a;pic16f877

Thanks very Much kvii7. I got that working. There was silly mistake ..not disabled the receiver and was trying to send data. I should have disabled Rx first before sending data and also used straight cable not crossed cable(RX and Tx)..I just attach the working code for future newbies..which they can refer. Thanks again AKVII7.
#include<htc.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 11059200
#endif

void Mobile_Init();
void Msg_Send(const unsigned char *,const unsigned char *,unsigned char);
unsigned int mob_del;

void Serial_Init();
void Serial_Out(unsigned char);
void Serial_Conout(const unsigned char *,unsigned char);
void Baudrate(unsigned long int);
void Receive(unsigned char);

void Msg_Send();
unsigned char num[]={"9986592825"}; //,comm,j;
//unsigned char node1,node2;

void main()
{

TRISC=0xc1;
Mobile_Init();
Msg_Send(num,"STATUS OF THE FIRST DEVICE",26);
__delay_ms(2000);
while(1);
}

void Mobile_Init()
{


Serial_Init();
__delay_ms(7000);

Serial_Out('A');Serial_Out('T');
//__delay_ms(1000);
Serial_Out(0x0d);Serial_Out(0x0a);


Serial_Conout("AT+CMGF=1",9);
//__delay_ms(1000);
Serial_Out(0x0d);Serial_Out(0x0a);

}


void Msg_Send(const unsigned char *mob_no,const unsigned char *data,unsigned char n)
{
unsigned char mob_j;

Serial_Conout("AT+CMGS=",8);

Serial_Out('"');
Serial_Conout("+91",3);
//__delay_ms(1000);
for(mob_j=0;mob_j<10;mob_j++)
{
Serial_Out(mob_no[mob_j]);
}

Serial_Out('"');
Serial_Out(0x0d);Serial_Out(0x0a);
mob_del=65000;
while(mob_del--);
mob_del=40000;
while(mob_del--);

for(mob_j=0;mob_j<n;mob_j++)
{
Serial_Out(data[mob_j]);


}
Serial_Out(0x1a);
__delay_ms(2000);
}

void Serial_Init()
{
//Baudrate(baud);
SYNC = 0; // asynchronous mode
SPEN = 1; // serial port enable
TXEN = 1; // tx enable
GIE=1;
PEIE=1;
RCIE = 1; // interrupt set
CREN = 1; // rx enable

SPBRG = 71; // for 9600 baud rate with11.0592mhz
BRGH = 1; // baud rate high
}

void Serial_Out(unsigned char val)
{
Receive(0);
TXREG =val;
while(!TRMT);
__delay_ms(10);
TRMT = 0;
}


void Serial_Conout(const unsigned char *data,unsigned char n)
{
unsigned char ser_j;
for(ser_j=0;ser_j<n;ser_j++)
{
Serial_Out(data[ser_j]);
//__delay_ms(1000);
}
}
void Receive(unsigned char rece)
{
if(rece==1)
{
RCIE = 1; // interrupt set
CREN = 1; // rx enable
}
else
{
RCIE = 0; // interrupt set
CREN = 0; // rx enable
}
}



MPLAB Version: V8.90
HITECH C compiler

TARGET: PIC16F877A
GSM MODEM: SIM300


Have a great programming...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top