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