hi there! guys please help me compile this code for my compiler is having problems. i have compiled this code already but i need different baud value to match the baud to the module. i used ccs compiler when i compile this code. please compile and upload the .hex file here. thanks.
Rich (BB code):
#if defined(__PCB__)
#include <16f877a.h>*
#include <string.h>*
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT*
#use delay(clock=8000000) //must be 8 MHz*
#elif defined(__PCM__)
#include <16f877a.h>
#include <string.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT
#use delay(clock=8000000) //must be 8 MHz*
#use rs 232(baud=2400, xmit=PIN_C6, rcv=PIN_C7) // serial*
void SerialInt();
int TEST_AT();
int SET_MEM();
int SET_PDU();
int SET_CNMI();
int SMSALERT();
int READ_SMS();
int DO_CMD();
int DEL_SMS();
int GET_CMD();
int GET_OK(int Stop_Search);
volatile int counter_search=0;
volatile int counter_read=0;
Volatile int HitCounter=0;// for string comparison*
Volatile int Next_CMD=0;
volatile Char Recieve_String[70];//buffer for incoming data*
void main()
{
SET_TRIS_A( 0x00 );// to avoid floating pins*
SET_TRIS_B( 0x00 );
OUTPUT_B(0X00);
SET_TRIS_C( 0x80 );
SET_TRIS_D( 0x00 );
SET_TRIS_E( 0x00 );
enable_interrupts(INT_RDA);// enable RDA interrupts*
enable_interrupts(GLOBAL);// enable global ints*
output_high(PIN_D1);// blink for circuit 'ON' confirmation*
delay_ms(500);
output_low(PIN_D1);
delay_ms(500);
output_high(PIN_D1);
delay_ms(500);
output_low(PIN_D1);
Delay_ms(1000);
while(1)
{
if(TEST_AT())
{
if(SET_MEM())
{
if(SET_PDU())
{
if(SET_CNMI())
{
if(SMSALERT())
{
if(READ_SMS())
{
if(GET_CMD())
{
if(DEL_SMS())
{
DO_CMD();
}
}
else
{
DEL_SMS();
}
}
}
}
}
}
}
}
}
int TEST_AT()
{
counter_read=0;
printf("AT");//send command*
putchar(0x0D);//send return ('enter' in hyperterminal)*
output_high(PIN_D1);
While(counter_read<=8)//"A T \R \R \N O K \R \N" characters returned by modem*
{
}
output_low(PIN_D1);
counter_read=0;
Delay_ms(500);// ignore all remaining characters received*
if(GET_OK(0X0A))
Return(1);
else return(0);
}
int SET_MEM()
{
counter_read=0;//reset all counters.*
printf("AT+CPMS=\"ME\",\"ME\",\"ME\"");//text part of the command.*
putchar(0x0D);// enter*
While(counter_read<25)// stay here, ignore first 25 chars*
{
}
counter_read=0;// start filling up the array from cero...from here on, keep the incoming text for parsing*
while(counter_read<=28)// acquire all pertinent text, I'm only looking for an "OK" but for now I'm keeping all incoming txt.*
{// maybe for future use...*
}
counter_read=0;
Delay_ms(500);// ignore all remaining characters received..if any.*
if(GET_OK(0X1C))
Return(1);
else return(0);
}
int SET_PDU()
{
counter_read=0;
printf("AT+CMGF=1");//send command*
putchar(0x0D);//send return*
While(counter_read<=15)// get all returned text*
{
}
counter_read=0;
Delay_ms(500);// ignore all remaining characters recieved*
if(GET_OK(0X0E))
Return(1);
else return(0);
}
int SET_CNMI()
{
counter_read=0;//reset all counters.*
printf("AT+CNMI=2,1,2,0,0");//text part of the command.*
putchar(0x0D);//send return*
While(counter_read<24)// read all data*
{
}
counter_read=0;
Delay_ms(500);// ignore all remaining characters recieved..if any.*
if(GET_OK(0X17))
Return(1);
else return(0);
}
int SMSALERT()
{
const char StrCMTI[]={"+CMTI"};
counter_read=0;
While(counter_read<=16)// read all data*
{
output_high(PIN_D1);// signal ready to receive sms*
}
counter_read=0;
Delay_ms(500);// ignore all remaining characters recieved..if any.*
output_low(PIN_D1);// off receive ready light.*
counter_search=2;
HitCounter=0;
while((HitCounter!=5)&&(counter_search<8))
{
if(Recieve_String[counter_search]==StrCMTI[counter_search-2])
HitCounter++;
counter_search++;
}
if(HitCounter==0x05)
Return(1);
else return(0);
}
int READ_SMS()
{
counter_read=0;
printf("AT+CMGR=1");// send command, MEMORY LOCATION OF SMS IS ALWAYS ONE, SINCE I DELETE THEM AFTER PROSCESING*
putchar(0x0D);
delay_ms(3000);// long [spam] message... so give time,* buffer will loop back one time...*
// text will be on second fill.*
counter_read=0;
if(GET_OK(0X45))
Return(1);
else return(0);
}
int GET_CMD()
{
const char CMD1[8][7]={"Led1 0","Led1 1","Led2 0","Led2 1","Led3 0","Led3 1","Led4 0","Led4 1"};
int offset=0;
int store_counter=0;
counter_search=0;
while((Recieve_String[counter_search]!='!')&&(counter_search<69))// wait till command indicator is found '!'*
{
counter_search++;
}
counter_search=counter_search+1;// increment one to actual first letter of command*
store_Counter=counter_search;// store current position for multiple searches*
NEXT_CMD=0;// NEXT_CMD keeps track of the command being read, thus used*
while((HitCounter!=6)&&(NEXT_CMD<8))// compare to all commands in list.*
{
counter_search=store_Counter;// initialize counter search with stored counter value.*
offset=0;// since value of counter is unknown use a separate counter for the const array*
HitCounter=0;// counts number of equal letters found.*
while((HitCounter!=6)&&(offset<=6))// keeps the counters in check...to not overshoot. and compares the strings*
{
if(Recieve_String[counter_search]==CMD1[NEXT_CMD][offset])// if letter is found*
HitCounter++;
offset++;
counter_search++;
}
if(HitCounter==6)// if 6 chars found...exit..*
{
Return(1);
}
NEXT_CMD++;// if increase to search next command.*
}
Return(0);
}
int DO_CMD()
{
if(NEXT_CMD==0)output_low(PIN_B1);
if(NEXT_CMD==1)output_high(PIN_B1);
if(NEXT_CMD==2)output_low(PIN_B2);
if(NEXT_CMD==3)output_high(PIN_B2);
if(NEXT_CMD==4)output_low(PIN_B3);
if(NEXT_CMD==5)output_high(PIN_B3);
if(NEXT_CMD==6)output_low(PIN_B4);
if(NEXT_CMD==7)output_high(PIN_B4);
}
int DEL_SMS()
{
counter_read=0;
printf("AT+CMGD=1");//send command*
putchar(0x0D);//send return*
While(counter_read<=15)// get all returned text*
{
}
counter_read=0;
Delay_ms(500);// ignore all remaining characters received*
if(GET_OK(0X0E))
Return(1);
else return(0);
}
int GET_OK(Stop_Search)
{
counter_search=0;
while((Recieve_String[counter_search]!='O')&&(counter_search<Stop_Search))//check buffer until an 'O' is found or 10 chars have been checked.*
{
counter_search++;//obvious*
}
if((Recieve_String[counter_search]=='O')&&(Recieve_String[counter_search+1]=='K'))//check for a 'K' after the 'O'*
{
counter_search=0;
Return(1);//function returns true*
}
Return(0);
counter_search=0;
}
#INT_RDA
void SerialInt()
{
Recieve_String[counter_read]=getchar();
counter_read++;
if(counter_read==69)counter_read=0;
}