Source code for gsm cellular message display

by barkkathulla 2012-09-20 17:12:46

#include
#include
#include

#include
#include
#define BAUD 0xFD // 9600 baud rate
#define TRIGER 0
#define ECHO 1
#define _AT 1
#define _ATZ 2
#define _CSQ 3
#define _CMGF 4
#define _CMGS 5
#define _CMGR 6
#define _CMGD 7
typedef unsigned char byte; /* type define objects with */
typedef unsigned int word; /* more classical microprocessor */
byte Tim1val;
bit TIM1;
byte ticks;
bit togle;
idata char buff[41];
void putch(char ch);
void sputs(char*s);
void getline(char*s,byte buffmax);
byte decode_cmd(char*s);
/*
use the free-running timer
at approx. 70ms interval.
*/
void timer0() interrupt 1 using 1
{
TR0=0;
ET0=0;
TR0=1;
++ticks;
if(ticks==40)
{
togle=1;
ticks=0;
}
if(TIM1==TRIGER){
if(++Tim1val==20)TIM1=1; // 1sec delay for serial get_char
}
ET0=1;
}
void main(void){
byte i,result;
EA = 0;
TMOD =0x20; // tim1 auto re load mode
TH1=TL1=BAUD;
PCON =0;
// SCON =0x50; // Mode 1(variable) REN=1;
// TI =0;
// RI =0;
SCON =0x50; //for stdio.h
TI=1; //
RI=1; //
TL0 = 1;//(TIMER0_COUNT & 0x00FF); /* timer 0 period 3ms */
TH0 = 0;//(TIMER0_COUNT >>Cool
;
TMOD |=01; // tim0 16bit timer mode
TR0 =1;
ET0 =1;
TR1 =1;
EA =1;

printf("GSM Engine V 1.0\r\n");
while(1){
getline(&buff[0],sizeof(buff));
for (i = 0; buff[i] != 0; i++) { /* convert to upper characters */
buff[i] = toupper(buff[i]);
}
result=decode_cmd(&buff[0]);
puts("");
switch(result){
case _AT:
puts("OK");
break;
case _ATZ:
puts("OK");
break;
case _CSQ:
puts(":CSQ 30,99");
puts("");
puts("OK");
break;
case _CMGF:
puts("OK");
break;
case _CMGS:
puts("OK");
break;
case _CMGR:
puts("+CMGR:\"REC READ\",\"+923457202288\",\"MT\",\"07/07/23,10:04:53+08\"");
puts("#7,0*");
puts("");
puts("OK");
break;
default:
puts("ERROR");
}
//putchar(result+0x30);puts("");
}//while(1)
}
// //
//wait to get from serial port until carage return.//
// //
void getline(char*s,byte buffmax){
byte i;
char ch;
i=0;
for(;;){
ch=_getkey();
if( ch=='\r'){
//putchar('\n');
s[i]=0;
break;
}
else{
s[i]=ch;
}
if(ECHO)putchar(ch);
if(i!=buffmax)++i;
}
}
byte decode_cmd(char *line){
if(line[0]!='A') return(0);
if ((strcmp("AT",&line[0]))==0)
return(_AT);
else if ((strcmp("ATZ",&line[0]))==0)
return(_ATZ);
else if ((strcmp("AT\+CSQ",&line[0]))==0)
return(_CSQ);
else if ((strcmp("AT\+CMGF=1",&line[0]))==0)
return(_CMGF);
else if ((strcmp("AT\+CMGS",&line[0]))==0)
return(_CMGS);
else if ((strcmp("AT\+CMGR=1",&line[0]))==0)
return(_CMGR);
else if ((strcmp("AT\+CMGD=1",&line[0]))==0)
return(_CMGD);
else
return(0);
}
/*
// //
// send char to serial port //
// //
void putch(char ch){
SBUF= ch;
while(!TI);TI=0;
}
// //
// send string to serial port upto null char //
// //
void sputs(char*s){
byte i;
i=0;
for(;;){
if(s[i]==0)break;
SBUF= s[i];
while(!TI);TI=0;
++i;
}
}
760
like
0
dislike
0
mail
flag

You must LOGIN to add comments