Hi there,
I'm doing the project that i need to send message via GSM Modem to my cell phone, but now still cannot work..can someone help me to check my code??(I'm using MPLAB..)
Thx alot!!!
-----------------------
#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;
}
}
}
I'm doing the project that i need to send message via GSM Modem to my cell phone, but now still cannot work..can someone help me to check my code??(I'm using MPLAB..)
Thx alot!!!
-----------------------
#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;
}
}
}