Hi, is there anybody who is able to write a keil c programming for my gsm to receive the message from what the user send to the gsm? i am using the #include<DS89C4xx.H> header and xdata.
You need winrar to extract the file. It is a CodeVisionAVR Project. So, just open the .c file in notepad and copy it and paste it to keil. Remove the code related to AVR and use it for your 8051.
#include<DS89C4xx.H> //microcontroller specific library (DS89C450)#include<absacc.h> //XBYTE[]#include<string.h>#define uchar unsigned char;/*Global Variables*/
uchar start_header='+',end_header=':';//gsm command header
uchar xdata GSMrd[80];
uchar xdata raw_data[80];
uchar xdata infor[4];enum sector_state {Idle,Extract} state;
uchar read_count,raw_data_count,infor_count,infor_count1, get_infor,infor_start,infor_start1;
uchar xdata extract;void initializtion (void){
SCON1 =0x52;//set serial port 1, 8-bit UART, TI Enable
SCON0 =0x52;
TMOD =0x21;//set Timer 1 to 16-bit timer/counter//WDCON = 0x80;
TH1 =0xFD;//set Baud Rate=9600//PCON=0x80; //set SCON=1 for baud rate = 19200
TR1=1;//Run Timer 1
EA=1;
ES0=1;}void tx(unsignedchar x){while(TI_1==0);
TI_1 =0;
SBUF1 = x;}void tx0(unsignedchar x){while(TI_0==0);
TI_0 =0;
SBUF0 = x;}void SMSstring(unsignedchar*msg)//send string GSM to hyper terminal{int count=0;while(msg[count]){
tx(msg[count++]);}// tx(0x0D); //CR carriage return// tx(0x0A); //next line}void SMSstring0(unsignedchar*msg){int count=0;
ES0=0;while(msg[count]){
tx0(msg[count++]);}
ES0=1;// tx(0x0D); //CR carriage return// tx(0x0A); //next line}void serial_int(void) interrupt 4//serial port 0{
ES0=0;//disable interruptif(RI_0==1){if(read_count==80)//Check is array full
read_count=0;//Restart from position 0
GSMrd[read_count]=SBUF0;//Storing the data from serial buffer into array
read_count++;//increase the count//indicator=1;
RI_0=0;//reset RI flag}
ES0=1;}void delay(int num){int i,j;for(i=0;i<num;i++)//number of loop according with the given numfor(j=0;j<1200;j++);//num * 1200 times of looping}void read_message (void){if(raw_data_count != read_count)//checking is there any unread data?{if(raw_data_count==80)//go back to start position of array
raw_data_count=0;
raw_data[raw_data_count]=GSMrd[raw_data_count];//read the data //======================= CHECK FOR "CMTI"================================if(raw_data[raw_data_count]==start_header)//check for + sign{
SMSstring0("Detected + Sign");//prove that is detected
infor_start=1;//increment to 1 if start header is true
raw_data[raw_data_count]=GSMrd[raw_data_count]='0';//reset the string array of raw_data and GSmrd
tx0(0x0D);//CR carriage return
tx0(0x0A);//next line}elseif(infor_start==1)// if information (CMTI) is true{if(raw_data[raw_data_count]==end_header)//check for : sign{
SMSstring0("Detected : Sign");
raw_data[raw_data_count]=GSMrd[raw_data_count]='0';//reset the string array of raw_data and GSmrd
infor_start=0;//reset infor_start back to zero
infor_count=0;//reset infor_count back to zero
tx0(0x0D);//CR carriage return
tx0(0x0A);//next lineif((infor[0]=='C')&&(infor[1]=='M')&&(infor[2]=='T')&&(infor[3]=='I')){
delay(100);
SMSstring0("AT+CMGR=1");//Read SMS message in SIM location 1
tx0(0x0D);//CR carriage return
tx0(0x0A);//next line
extract=1;//when message is true it will extract out the dataswitch(raw_data[raw_data_count]){case:'+':
state=extract;break;default:break;}}
infor[0]=infor[1]=infor[2]=infor[3]='0';//reset the CMTI information}elseif(infor_count<4)//counter to detect CMTI{
infor[infor_count]= raw_data[raw_data_count];//store the raw data into infor as a string
infor_count++;//every character receieve will incraese the count }}
raw_data_count++;}}void main(void){
delay(200);//call delay
PMR=PMR|0X81;//power management modules for external memory
initializtion();//initialization );
SMSstring("GSM Testing ");//to indicate system is ready for testingwhile(1){
read_message();}}