Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
c> void adc(void); #define databus P1 void hex_to_dec(unsigned char); void mod(unsigned int temp); unsigned char adcvalue,digit1,digit2,digit3,adcvalue,adcvalue1,value,digit4=0,di git5=0,digit6=0; unsigned char x,y,z,tick=0,count=0; unsigned int var=0; bit FLAG=0; unsigned int var1=0,overflow_flag=0; unsigned int minute_count=0; unsigned char ad[]= {"[tp= c bt= sbit PULSE=P3^7; bit read_RE_START_flag = 0; int i=0; void main() { API_initializing_board(); API_initializing_lcd(); delay(500); send_command(0x01); send_string(" welcome " ); API_initializing_modem(); delay(500); add_a=1; add_b=0; add_c=0; for(i=0;i<10;i++) delay(10000); TR0=1; relay1=1; // if(PULSE==1) //{ //overflow_flag++; //} adc(); mod(var); delay(10); hex_to_dec(adcvalue); send_command(0xc0); send_string("temp."); send_data(digit2+0x30); send_data(digit3+0x30); send_string("C");
bpm]"};
// while(1) {
ad[5]= digit2+0x30; ad[6]= digit3+0x30; send_string("&bt "); send_data(digit4+0x30); send_data(digit5+0x30); send_data(digit6+0x30); ad[13]= digit4+0x30; ad[14]= digit5+0x30; ad[15]= digit6+0x30; send_command(0x02); delay(60000); delay(60000); delay(60000); delay(60000); delay(60000); delay(60000);
send_string("process "); delay(1000); if (FLAG==1) { //TR0=0; API_sms_send(&ad); // TR0=1; send_command(0x01); FLAG=0; } if( read_RE_START_flag == 0 ) { read_RE_START_flag = 1; } else if( read_CMTI_flag == 1 ) { send_string(&CMTI); delay(5000); rx_i=0; API_sms_delete(); read_CMTI_flag =0; } else if( initializing_Modem_flag == 1 && read_RE_START_flag == 1 ) { send_command(0x01); delay(50); send_command(0x80); delay(50); send_string(&READY); delay(5000); API_initializing_modem();
initializing_Modem_flag = 0; //check_Sensor_flag = 1; Initlization_Completion_Flag = 1; } else if( read_OK_flag == 1 && read_CMTI_flag == 0 ) { rx_i=0; send_command(0x80); delay(50); send_string("OK "); read_OK_flag = 0; } else if( SIM_CHECK_FLAG == 1 ) { send_command(0x01); delay(50); send_command(0x80); delay(50); send_string("SIM NOT INSERTED "); //buzzer = 0; delay(25000); send_command(0x01); delay(50); send_command(0x80); delay(50); send_string("INSERT SIM & RESTART "); //delay(25000); //delay1(30000); // for calling WDT
} else if( SIM_CHECK_FLAG == 0 && Initlization_Completion_Flag == 1 ) { } } } void mod(unsigned int temp) LCD IN TIME SETTING MODE { digit6 = temp%10; temp = temp/10; digit5 = temp%10; temp = temp/10; digit4 = temp%10; temp = temp/10; // // // // send_command(0xc0); send_data(z+0x30); send_data(y+0x30); send_data(x+0x30); } // MODULAS OF THE DATA TO SHOW IT ON THE
void adc() { delay(100); ale=1; delay(100); start=1; delay(100); ale=0; start=0; while(eoc==1); while(eoc==0); oe=1; delay(100); adcvalue =databus; oe=0; } void hex_to_dec(unsigned char temp) { digit3= temp%10; temp = temp/10; digit2= temp%10; }
void timer0(void) interrupt 1 using 0 { // TF0=0; TH0 = 0x3c; TL0 = 0Xb0; TR0=1; if(PULSE==1) { overflow_flag++; // var = overflow_flag; } count++; if (count == 20) { count = 0; if ( minute_count++==10) { minute_count=0; var = overflow_flag; overflow_flag=0; FLAG=1; } } }
{ // unsigned char rx_data; //WDTRST =0X1E; WDTRST = 0XE1; if(TI) { TI=0; } if(RI) { rx_data = SBUF; RI=0; if( sms_symbol == rx_data && Initlization_Completion_Fla g == 1 ) { procedded_sms_FLAG = 1; } else if( SIM_CHECK[rx_i] == rx_data ) { rx_i++; if( SIM_CHECK[rx_i]=='\0' ) { rx_i=0; SIM_CHECK_FLAG = 1; } } else if( READY[rx_i] == rx_data ) { rx_i++; if( READY[rx_i] =='\0' ) { rx_i=0 ; // power = 0; buzzer = 1; initializing_Modem_flag = 1; } } else if( CMTI[rx_i] == rx_data ) { rx_i++; if( CMTI[rx_i]=='\0' ) { rx_i=0; read_CMTI_flag = 1; } } else if( OK[rx_i] == rx_data ) { rx_i++; if( OK[rx_i]=='\0' ) { rx_i=0; rx_ack=1; read_OK_flag = 1; }
} else if( RE_START[rx_i] == rx_data ) { rx_i++; if( RE_START[rx_i]=='\0' ) { rx_i=0; } /* { rx_i++; if( Error517[rx_i]=='\0' ) { rx_i=0; re_try_flag = 1; } }*/ } } Program for LCD //unsigned int var; sbit rs = P2^2; sbit en = P2^3; void void void void send_command(unsigned char); send_data(unsigned char); send_string(unsigned char *); delay(unsigned int); } else if( Error517[rx_i] == rx_data )
void COM_putsf( unsigned char *); void COM_putchar( unsigned char ); void delay(unsigned int var) { unsigned int i; // // // // } void send_command(unsigned char var) { rs = 0; delay(10); P0 = var; en=1; for(i=0;i<var;i++); watch_dog(); for(i=0;i<var;i++); watch_dog(); //for(i=0;i<var;i++); watch_dog();
delay(500); en=0; delay(10); var = var << 4; P0 = var; en=1; delay(500); en=0; delay(10); rs=1; } void send_data(unsigned char var) { rs = 1; delay(10); P0 = var; en=1; delay(300); en=0; delay(10); var = var << 4; P0 = var; en=1; delay(200); en=0; delay(10); rs=0; } void send_string(unsigned char *name) { unsigned char count = 0; while(*name!=0) { // watch_dog(); send_data(*name); name++; count++; if(count==16) send_command(0xc0); } } void COM_putsf(unsigned char *fstr ) { while(*fstr!=0) { COM_putchar(*fstr); delay(500); fstr++; if(*fstr==0) { delay(500); SBUF = 0X0D; } } } void COM_putchar( unsigned char Tico )
{ SBUF = Tico; } Program for Modem Initialization: unsigned char code ATE0[] unsigned char code CMGF[] unsigned char code CSCS[] void API_initializing_modem(void); void API_initializing_board(void); void API_initializing_lcd(void); void API_initializing_modem() { send_command(0x80); //clear LCD delay(50); COM_putsf( ATE0 ); if(API_check_acknowledge() > 0) { send_string("OK"); delay(500); COM_putsf( CMGF ); if(API_check_acknowledge() > 0) { send_string("OK"); delay(500); COM_putsf( CSCS ); if(API_check_acknowledge() > 0) { send_string("OK"); delay(500); // buzzer = 0; } } } } void API_initializing_board() { P1=0XFF; P2=0XFF; // buzzer = 0; // relay1=0; P3=0XFF; P0=0XFF; IE=0X92; TMOD=0X21; TH0=0x3c; TL0=0xb0; //TR0=1; SCON=0X50; TH1=0xfd; // IT0=1; TR1=1; // watch_dog(); = "ATE0"; = "AT+CMGF=1"; = "AT+CSCS=\"GSM\"";
} void API_initializing_lcd(void) { send_command(0x03); delay(10); send_command(0x03); delay(10); send_command(0x03); delay(10); send_command(0x02); send_command(0x02); delay(10); send_command(0x28); delay(10); send_command(0x28); delay(10); send_command(0x28); delay(10); send_command(0x01); delay(10); send_command(0x0c); delay(10); send_command(0x80); delay(10); send_command(0x0c); }
Program of Acknowledgement int API_check_acknowledge( void ); static unsigned int Tico, ii; extern unsigned char rx_ack; int API_check_acknowledge( void ) { for( Tico = 0; ( rx_ack == 0 ) && ( Tico < 65535 ) ; Tico++ ) { //watch_dog(); for( ii = 0; ii < 50; ii++ ) { ; } } if( rx_ack > 0 ) { rx_ack = 0;
return 1; } } Program for MAX 232 extern extern extern extern bit sms_rx_flag; unsigned int counter; int API_check_acknowledge( void ); void API_initializing_modem(void); = "AT+CMGD=1"; = "AT+CMGS=\"9873594774\
unsigned char code CMGD[] unsigned char code CMGS[] "";//09560633450\"";09650633450\"";08800240082 bit procedded_sms_FLAG = 0; void API_sms_delete(void); void API_sms_send(unsigned char *sms); void API_sms_delete() { send_command(0x01); delay(50); send_command(0x80); delay(50); COM_putsf( CMGD ); delay(5000); send_string("SMS Deleted delay(5000); }
");
void API_sms_send(unsigned char *sms) { send_command(0x01); //clear LCD delay(50); send_command(0x80); delay(50); COM_putsf( CMGS ); delay(500); send_command(0x01); //clear LCD delay(500); send_command(0x80); delay(50); send_string("PLZ WAIT"); delay(5000); // if( procedded_sms_FLAG == 1 ) { //buzzer = 1; COM_putsf(sms); delay(4000); SBUF = 0x1A; delay(1000); // buzzer = 0; procedded_sms_FLAG = 0; send_command(0x01); //clear LCD delay(500); send_command(0x80); delay(50);
send_string("SMS Sended"); delay(55000); delay(55000); delay(10000); } /* else//(re_try_flag == 1) { send_command(0x01); //clear LCD delay(500); send_command(0x80); delay(50); COM_putsf(sms); delay(5000); SBUF = 0x1A; delay(500); send_string("RE TRYING"); delay(5000); goto lable_1; } */
Receiver Side Coding The Program for the Receivers Side is as follows: Main Program #include #include #include #include #include #include <AT89X52.H> <lcd.c> <header_file.h> <API_sms.c> <acknowledge.c> <init.c>
void intilizing_ALL_variable(void); bit display_flag=0; sbit buzz =P1^0; unsigned char z_tens,z_one; unsigned char rec_data[40],rx_ack = 0; bit sms_rx_flag = 0; unsigned int counter = 0; bit con = 0; bit error_check_flag = 0; bit read_wrong_flag = 0; bit sms_confermation_flag =0,sms_delete_flag = 0,Sender_Error_flag = 0,SIM_CHECK _FLAG = 0;// unsigned char sec=0; unsigned char time_count=0; int lcd_init=0,z=0; void main() { char i; API_inititlizing_board(); API_inititlizing_lcd(); read_RE_START_flag = 1; delay(500);
send_string(" welcome "); for(i=0;i<10;i++) delay(10000); relay1=1; buzz=0; // buzz=0; while(1) { // watch_dog(); /*if(z_one>=26 z_one <=20) { buzz=0; delay(2000); buzz=1; } else buzz=1;*/ if (display_flag==1) { display_flag=0; send_command(0x01); delay(10); send_string(rec_data); z_tens= rec_data[4]-0x30; z_one= rec_data[5]-0x30; z_one = z_tens*10 + z_one; if(z_one>=26 z_one <=20) { buzz=1; delay(60000); buzz=0; } delay(60000); delay(60000); } if( sms_confermation_flag == 1 && read_RE_START_flag == 1 ) { see = 0; send_command(0x80); delay(50); send_string("SMS OK "); delay(5000); sms_confermation_flag = 0; buzzer=0; } else if( read_wrong_flag == 1 ) { see=0; send_command(0x80); delay(50); send_string("wrong sms "); delay(5000); read_wrong_flag = 0; } else if( read_CMTI_flag == 1 && read_RE_START_flag == 1 && init_ shiv_flag == 1 ) {
TR0=0; rx_i=0; send_command(0x80); delay(50); send_string( &CMTI ); delay(5000); API_sms_recive_index_1(); see = 0; rx_i=0; API_sms_delete_index_1(); see = 0; rx_i=0; API_sms_recive_index_2(); see = 0; rx_i=0; API_sms_delete_index_2(); watch_dog(); // see = 0; rx_i=0; API_sms_recive_index_3(); see = 0; rx_i=0; API_sms_delete_index_3(); see = 0; rx_i=0; API_sms_recive_index_4(); // see = 0; rx_i=0; API_sms_delete_index_4(); see = 0; rx_i=0; API_sms_recive_index_5(); see = 0; rx_i=0; API_sms_delete_index_5(); sms_delete_flag = 1; // watch_dog(); buzzer = 0; send_command(0x01); delay(50); send_command(0x80); delay(500); send_string("DONE "); intilizing_ALL_variable(); read_CMTI_flag = 0;
buzzer = 0; TR0=1; } else if( sms_delete_flag == 1 && read_CMTI_flag == 0 && read_RE_ START_flag == 1 ) { see = 0; rx_i=0; sms_delete_flag = 0; // watch_dog(); // API_delete_ALL_SMS(); buzzer=0; } else if( read_OK_flag == 1 && read_CMTI_flag == 0 && read_RE_STA RT_flag == 1 ) { see = 0; rx_i=0; send_command(0x80); delay(50); send_string(&OK); read_OK_flag = 0; } else if( inititlizing_MODEM_flag == 1 && read_RE_START_flag == 1 ) { send_command(0x80); delay(50); send_string( &READY ); delay(5000); API_inititlizing_modem(); inititlizing_MODEM_flag=0; } else if( error_check_flag == 1 && sms_delete_flag == 0 && read_C MTI_flag == 0 && read_RE_START_flag == 1 ) { send_command(0x80); delay(50); error_check_flag = 0; send_string("Reciver Sensor Error "); } else if(SIM_CHECK_FLAG == 1 && read_RE_START_flag == 1 ) { send_command(0x01); delay(50); send_command(0x80); delay(50); send_string("SIM NOT INSERTED "); delay(35000); send_command(0x01); delay(50); send_command(0x80); delay(50); send_string("INSERT SIM & RESTART "); delay(40000); buzzer = 0; } else if( Sender_Error_flag == 1 && sms_delete_flag == 0 && read_
CMTI_flag == 0 ) { send_command(0x80); delay(50); send_string("Sender Sensor Sender_Error_flag = 0; } else if(pin1 == 0 && pin2 == 0 error_check_flag = 0; else if(pin1 == 0 && pin2 == 1 error_check_flag = 0; else if(pin1 == 0 && pin2 == 0 error_check_flag = 0; else if(pin1 == 0 && pin2 == 0 error_check_flag = 0; else if(pin1 == 1 && pin2 == 1 error_check_flag = 0; else error_check_flag = 1; } } void watch_dog() { //WDTRST =0X1E; //WDTRST = 0XE1; } void timer0() interrupt 1 using 0 { TH0=0x3c; TL0=0xb0; sec++; if(sec==20) { sec=0; time_count++; if(time_count==200) { time_count=0; read_CMTI_flag = 1; } } } void serial_isr() { unsigned // WDTRST // WDTRST interrupt 4 using 1 char rx_data; =0X1E; = 0XE1; Error ");
&& pin3 == 0 && pin4 == 0) && pin3 == 1 && pin4 == 1) && pin3 == 1 && pin4 == 1) && pin3 == 0 && pin4 == 1) && pin3 == 1 && pin4 == 1)
if(TI) TI=0; if(RI) { RI=0; rx_data = SBUF; if(check_flag==1) { sms_confermation_flag = 1; rec_data[z]= rx_data; z++; } if(rx_data== [ ) { check_flag=1; z=0; } else if(rx_data== ] ) { check_flag=0; display_flag=1; z=0; }
if(see == 0) { // WDTRST =0X1E; // WDTRST = 0XE1; if( sms_rx_flag == 1 ) { if(counter<54)//58) { rx_data= \0 ; counter++; } else { sms_rx_flag = 0; counter = 0; see = 1; } } else if( SIM_CHECK[rx_i] == rx_data ) {
\0 )
SIM_CHECK_FLAG = 1; } } else if( READY[rx_i] == rx_data ) { rx_i++; if( READY[rx_i] == \0 ) { rx_i=0 ; buzzer = 1; inititlizing_MODEM_flag = 1; power = 0; } } else if( CMTI[rx_i] == rx_data ) { rx_i++; if( CMTI[rx_i]== \0 ) { rx_i=0; read_CMTI_flag = 1; sms_delete_flag=0; // buzzer = 1; } } else if( OK[rx_i] == rx_data ) { rx_i++; if( OK[rx_i]== \0 ) { rx_i=0; rx_ack=1; read_OK_flag = 1; } } else if( RE_START[rx_i] == rx_data ) { rx_i++; if( RE_START[rx_i]== \0 ) { rx_i=0; } } } RI=0; } } void intilizing_ALL_variable() { rx_ack = 0; sms_rx_flag = 0; counter = 0; con = 0; error_check_flag = 0; read_OK_flag = 0;
read_wrong_flag = 0; sms_confermation_flag =0; rx_i = 0; inititlizing_MODEM_flag = 0; see = 0; buzzer=0; // } Program for LCD //unsigned int var; sbit rs = P2^4; sbit en = P2^5; void void void void void watch_dog(void); send_command( unsigned char ); send_data( unsigned char ); send_string( unsigned char * ); delay( unsigned int ); read_CMTI_flag = 0;
void COM_putsf( unsigned char *); void COM_putchar( unsigned char ); void delay(unsigned int var) { unsigned int i; for(i=0;i<var;i++); // watch_dog(); for(i=0;i<var;i++); //watch_dog(); } void send_command(unsigned char var) { rs = 0; delay(10); P0 = var; en=1; delay(30); en=0; delay(10); var = var << 4; P0 = var; en=1; delay(30); en=0; delay(10); rs=1; } void send_data(unsigned char var) { rs = 1; delay(10);
P0 = var; en=1; delay(30); en=0; delay(10); var = var << 4; P0 = var; en=1; delay(30); en=0; delay(10); rs=0; } void send_string(unsigned char *name) { unsigned char count = 0; //watch_dog(); while(*name!=0) { /* if( ( *name == \r ) ( *name == \n ) ( *name == + ) ( *name == \0 )) name++; */ send_data(*name); name++; count++; //if(count==16) // send_command(0xc0); } } void COM_putsf(unsigned char *fstr ) { TI=0; //watch_dog(); while(*fstr!=0) { COM_putchar(*fstr); delay(50); fstr++; if(*fstr==0) { SBUF = 0X0D; delay(100); } } } void COM_putchar( unsigned char Tico ) { SBUF = Tico; } Program for Modem Initialization unsigned char code ATE0[] unsigned char code CMGF[] = "ATE0"; = "AT+CMGF=1";
( *name ==
unsigned char code CSCS[] extern unsigned char rec_data[20]; void API_inititlizing_modem(void); void API_inititlizing_board(void); void API_inititlizing_lcd(void); void API_inititlizing_modem() { send_command(0x01); delay(100); send_command(0x80); delay(50); COM_putsf( ATE0 ); if(API_check_acknowledge() > 0) { send_string("OK"); delay(5000); COM_putsf( CMGF ); if(API_check_acknowledge() > 0) { send_string("OK"); delay(5000); COM_putsf( CSCS ); if(API_check_acknowledge() > 0) { buzzer = 0; send_string("OK"); delay(5000); init_shiv_flag = 1; } } } } void API_inititlizing_board() { P1=0XFF; P2=0XFF; buzzer = 0; relay1=0; P3=0XFF; P0=0XFF; delay(10); IE=0X92; // boad rate 9600 TMOD=0X21; TH0=0x3c; TL0=0xb0; SCON=0X50; TH1=0xfd; TR1=1; TR0=1; watch_dog();
= "AT+CSCS=\"GSM\"\r";
// }
delay(10); send_command(0x03); delay(10); send_command(0x03); delay(10); send_command(0x02); send_command(0x02); delay(10); send_command(0x28); delay(10); send_command(0x28); delay(10); send_command(0x28); delay(10); send_command(0x06); delay(10); send_command(0x01); delay(10); send_command(0x0c); delay(10); send_command(0x80); delay(10); }
Program for Acknowledgement int API_check_acknowledge( void ); unsigned int k, ii; extern unsigned char rx_ack; int API_check_acknowledge( void ) { for( k = 0; ( k == 0 ) && ( k < 65535 ) ; k++ ) { // watch_dog(); for( ii = 0; ii < 50; ii++ ) { ; } } if( rx_ack > 0 ) { rx_ack = 0; return 1; } }
Program for MAX 232 extern bit sms_rx_flag; extern unsigned int counter; extern int API_check_acknowledge( void ); extern unsigned char rec_data[40]; //extern bit display_flag; unsigned char code CMGR1[] unsigned char code CMGD1[] unsigned char code CMGR2[] unsigned char code CMGD2[] unsigned char code CMGR3[] unsigned char code CMGD3[] unsigned char code CMGR4[] unsigned char code CMGD4[] unsigned char code CMGR5[] unsigned char code CMGD5[] void API_sms_recive_index_1(void); void API_sms_delete_index_1(void); void API_sms_recive_index_2(void); void API_sms_delete_index_2(void); void API_sms_recive_index_3(void); void API_sms_delete_index_3(void); void API_sms_recive_index_4(void); void API_sms_delete_index_4(void); void API_sms_recive_index_5(void); void API_sms_delete_index_5(void); void API_delete_ALL_SMS(void); void API_sms_delete_index_1() { send_command(0x80); delay(50); COM_putsf( CMGD1 ); delay(500); send_command(0xc0); send_string("SMS Del 1 delay(5000); } void API_sms_delete_index_2() { send_command(0x80); delay(50); COM_putsf( CMGD2 ); delay(500); = "AT+CMGR=1"; = "AT+CMGD=1"; = "AT+CMGR=2"; = "AT+CMGD=2"; = "AT+CMGR=3"; = "AT+CMGD=3"; = "AT+CMGR=4"; = "AT+CMGD=4"; = "AT+CMGR=5"; = "AT+CMGD=5";
");
send_command(0xc0); send_string("SMS Del 2 delay(5000); } void API_sms_delete_index_3() { send_command(0x80); delay(50); COM_putsf( CMGD3 ); delay(500); send_command(0xc0); send_string("SMS Del 3 delay(5000); } void API_sms_delete_index_4() { send_command(0x80); delay(50); COM_putsf( CMGD4 ); delay(5000); // COM_putsf( CMGD4 ); delay(500); send_command(0xc0); send_string("SMS Del 4 delay(5000); } void API_sms_delete_index_5() { send_command(0x80); delay(50); COM_putsf( CMGD5 ); delay(5000); // COM_putsf( CMGD5 ); delay(500); send_command(0xc0); send_string("SMS Del 5 delay(5000); } void API_sms_recive_index_1() { send_command(0x80); delay(50); send_command(0xc0); send_string("sms1 "); delay(5000); sms_rx_flag = 1; counter = 0; COM_putsf( CMGR1 ); } void API_sms_recive_index_2() { send_command(0x80); delay(50); send_command(0xc0);
");
");
");
");
send_string("sms2 "); delay(5000); sms_rx_flag = 1; counter = 0; COM_putsf( CMGR2 ); } void API_sms_recive_index_3() { send_command(0x80); delay(50); send_command(0xc0); send_string("sms3 "); delay(5000); sms_rx_flag = 1; counter = 0; COM_putsf( CMGR3 ); } void API_sms_recive_index_4() { send_command(0x80); delay(50); send_command(0xc0); send_string("sms4 "); delay(5000); sms_rx_flag = 1; counter = 0; COM_putsf( CMGR4 ); } void API_sms_recive_index_5() { send_command(0x80); delay(50); send_command(0xc0); send_string("sms5 "); delay(5000); sms_rx_flag = 1; counter = 0; COM_putsf( CMGR5 ); } void API_delete_ALL_SMS(void) { if( read_CMTI_flag == 0 ) { COM_putsf( CMGD1 ); if( API_check_acknowledge() > 0 && read_CMTI_flag == 0 ) { COM_putsf( CMGD2 ); if( API_check_acknowledge() > 0 && read_ CMTI_flag == 0 ) { COM_putsf( CMGD3 ); if( API_check_acknowledg e() > 0 && read_CMTI_flag == 0 ) { read_OK_flag = 0 ;
send_command(0xc 0); delay(10); send_string("ALL OK ; if( read_CMTI_fl ag == 0 ) delay(70 00); } } } } } "); //display_flag=1