Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need help for sending message from GSM Modem(connecting with PIC16C745)~~~

Status
Not open for further replies.

gomera

New Member
Hi there,

I'm doing the project of GSM Modem sending message to the cell phone when pressing the push button. The GSM Modem is connected with the PIC16C745. Can anyone tell me how to program correctly to make it work??

RB1 is the push button.
RB2 is the LED.(light up when button is pressed)
RB3 is the buzzer.(sound when button is pressed)

Btw, how to add a delay to my code??

Thxalot!!!

Here is my code.=]

#include <htc.h>
//#include "delay.h"
__CONFIG(WDTDIS&PWRTDIS&UNPROTECT&H4);

void init(void)
{
PORTB=0x02;
TRISB=0x02;
}

void initUSART(void)
{
TXSTA=0x22;
RCSTA=0x90;
SPBRG=0x9b;
}

void enter(void)
{
while(!TRMT);
TXREG=0x0d;
}

void tx_start(void)
{
while(!TRMT);
TXREG=0x1a;
}

void send_msg(const char*str)
{
char ps;
ps=*str;
while(ps>0)
{
str++;
if(ps==0)break;
while(!TRMT);
TXREG=ps;
ps=*str;
}
}

void main(void)
{
init();
initUSART();
while(1)
{
if(RB1==1)
{
RB3=0x01;
RB2=1;
send_msg("at+cmgf=1");
enter();
//Delay_Ms(50);
send_msg("at+cmgs=");
send_msg("+6583011234");
enter();
//Delay_Ms(50);
send_msg("hello");
tx_start();
//Delay_Ms(5000);

RB3=0;
RB2=0;
}
else if(RB1==0)
{
RB3=0;
RB2=0;
}
}
}

:D:D:D
 
Last edited:
If you programed the PIC16C745 I hope you have more you can only program them one time
 
Here is my updated code, can someone tell me, am i adding the "Delay" code correctly?? Because now i'm still cannot send message to my cell phone via GSM Modem..

Please help me!!! It's very urgent!!!!!
 
#include <htc.h>

__CONFIG(WDTDIS&PWRTDIS&UNPROTECT&H4);

void Delay(int loop)
{
int i;
for(i=0;i<loop;i++);
}

void init(void)//Assign & Initialize PORTB I/0
{
PORTB=0x02;
TRISB=0x02;
}

void initUSART(void)//Initialize USART
{
TXSTA=0x22;
RCSTA=0x90;
SPBRG=0x9b;
}

void enter(void)//ACSII Keycode for "Enter"
{
while(!TRMT);
TXREG=0x0d;
}

void tx_start(void)//ASCII Keycode for "Ctrl+Z"
{
while(!TRMT);
TXREG=0x1a;
}

void send_msg(const char*str)//Sending String of Characters
{
char ps;
ps=*str;
while(ps>0)
{
str++;
if(ps==0)break;
while(!TRMT);
TXREG=ps;
ps=*str;
}
}

void main(void)
{
init();
initUSART();
while(1)
{
if(RB1==1)
{
RB3=0x01;
RB2=1;
send_msg("at+cmgf=1");
enter();
Delay(500);
send_msg("at+cmgs=");
send_msg("+6591931234");
enter();
Delay(500);
send_msg("hello");
tx_start();
Delay(5000);

RB3=0;
RB2=0;
}
else if(RB1==0)
{
RB3=0;
RB2=0;
}
}
}
 
Like this you have to define crystal speed

Code:
#include <htc.h>	// Required to interface with delay routines

#ifndef _XTAL_FREQ
 // Unless already defined assume 4MHz system frequency
 // This definition is required to calibrate __delay_us() and __delay_ms()
 #define _XTAL_FREQ 4000000
#endif

//__CONFIG(WDTDIS&PWRTDIS&UNPROTECT&H4);

void Delay(int loop)
{
int i;
for(i=0;i<loop;i++);
}

void init(void)//Assign & Initialize PORTB I/0
{
PORTB=0x02;
TRISB=0x02;
}

void initUSART(void)//Initialize USART
{
TXSTA=0x22;
RCSTA=0x90;
SPBRG=0x9b;
}

void enter(void)//ACSII Keycode for "Enter"
{
while(!TRMT);
TXREG=0x0d;
}

void tx_start(void)//ASCII Keycode for "Ctrl+Z"
{
while(!TRMT);
TXREG=0x1a;
}

void send_msg(const char*str)//Sending String of Characters
{
char ps;
ps=*str;
while(ps>0)
{
str++;
if(ps==0)break;
while(!TRMT);
TXREG=ps;
ps=*str;
}
}

void main(void)
{
init();
initUSART();
while(1)
{
if(RB1==1)
{
RB3=0x01;
RB2=1;
send_msg("at+cmgf=1");
enter();
Delay(500);
send_msg("at+cmgs=");
send_msg("+6591931234");
enter();
Delay(500);
send_msg("hello");
tx_start();
Delay(5000);

RB3=0;
RB2=0;
}
else if(RB1==0)
{
RB3=0;
RB2=0;
}
}
}
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top