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;
}
}
}



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;
}
}
}
Last edited: