#include #include sbit meter=P2^0; sbit SCL=P3^2; sbit SDA=P3^3; void delay(unsigned int w) { unsigned int q; for(q=0;q> ( 7 - i ) ) & 0x01 ) SDA = 1 ; else SDA = 0 ; clock() ; } } void i2c_write(unsigned char dat,unsigned char addr) { start(); //dummy write start opdat(0xa0); //send dev addr waitack(); opdat(addr); waitack(); opdat(dat); //write data waitack(); stop(); } unsigned char getdat() { unsigned char i , dat; SDA = 1; _nop_() , _nop_() , _nop_(); for ( i = 0 ; i < 8 ; i++ ) { dat = ( ( ( dat << 1 ) & 0xfe ) | SDA ); clock(); } return dat; } unsigned char i2c_read(unsigned char addr) { unsigned char rdata; start(); //dummy write start opdat(0xa0); //send dev addr waitack(); opdat(addr); waitack(); start(); //start read opdat(0xa1); //give device adddr or with for read waitack(); //operation coz lsb gives r|w rdata = getdat(); nack() ; stop() ; return(rdata); } void tx(unsigned char num) { SBUF = num; while(TI == 0); TI = 0; } void tx_str(unsigned char *y) { while(*y!='\0') { tx(*y); y++; } } void main() { unsigned int e; unsigned char r,q,w,t,y,u,i,arr1[6],arr[20],arr2[15]; SCON=0x50; TMOD=0x20; TH1=0xfd; TR1=1; i2c_write(0,0); delay(1200); i2c_write(0,1); delay(1200); i2c_write(0,2); delay(1200); i2c_write(0,3); delay(1200); i2c_write(1,4); delay(1200); i2c_write(4,5); delay(1200); i2c_write(1,6); delay(1200); qwe: for(w=0;w<16;w++) { arr[w]=0; } tx_str("AT"); tx(0x0d); delay(60000); tx_str("AT+CMGF=1"); tx(0x0d); delay(60000); tx_str("AT+CMGD=1"); tx(0x0d); delay(60000); delay(60000); q=0; while(1) { if(meter==1) { w=i2c_read(6); delay(100); if(w<9) { i2c_write((w+1),6); delay(1200); } else { i2c_write(0,6); delay(1200); q=i2c_read(5); delay(100); if(q<9) { i2c_write((q+1),5); delay(1200); } else { i2c_write(0,5); delay(1200); r=i2c_read(4); delay(100); if(r<9) { i2c_write((r+1),4); delay(1200); } else { i2c_write(0,4); delay(1200); t=i2c_read(3); delay(100); if(t<9) { i2c_write((t+1),3); delay(1200); } else { i2c_write(0,3); delay(1200); y=i2c_read(2); delay(100); if(y<9) { i2c_write((y+1),2); delay(1200); } else { i2c_write(0,2); delay(1200); u=i2c_read(1); delay(100); if(u<9) { i2c_write((u+1),1); delay(1200); } else { i2c_write(0,1); delay(1200); i=i2c_read(0); delay(100); if(i<9) { i2c_write((i+1),0); delay(1200); } } } } } } } } if(RI==1) { w=SBUF; RI=0; if(w=='+') { e=0; while(RI==0) { e=e+1; if(e>30000) goto qwe; } RI=0; q=SBUF; e=0; while(RI==0) { e=e+1; if(e>30000) goto qwe; } RI=0; q=SBUF; e=0; while(RI==0) { e=e+1; if(e>30000) goto qwe; } RI=0; q=SBUF; if(q=='T') { delay(30000); tx_str("AT+CMGR=1"); tx(0x0d); zxc: e=0; while(RI==0) { e=e+1; if(e>30000) { goto qwe; } } RI=0; r=SBUF; if(r!=':') goto zxc; r=0; xcv: e=0; while(RI==0) { e=e+1; if(e>30000) { goto qwe; } } RI=0; r=SBUF; if(r!='+') goto xcv; r=0; asd: e=0; while(RI==0) { e=e+1; if(e>30000) { goto qwe; } } RI=0; arr2[r]=SBUF; r=r+1; if(SBUF!='"') goto asd; r=0; wer: e=0; while(RI==0) { e=e+1; if(e>30000) { goto qwe; } } RI=0; r=SBUF; if(r!='*') goto wer; r=0; ert: e=0; while(RI==0) { e=e+1; if(e>30000) { goto qwe; } } RI=0; arr[r]=SBUF; r=r+1; if(SBUF!='#') goto ert; if(r==11) { if(arr[0]=='R' && arr[1]=='E' && arr[2]=='A' && arr[3]=='D' && arr[4]=='I' && arr[5]=='N' && arr[6]=='G' && arr[7]==' ' && arr[8]=='1' && arr[9]=='1') { for(t=0;t<7;t++) { arr1[t]=i2c_read(t); delay(100); } tx_str("AT+CMGS="); tx('"'); tx('0'); for(t=2;t<12;t++) { tx(arr2[t]); } tx('"'); tx(0x0d); delay(20000); tx_str("VALUE - "); for(t=0;t<7;t++) { tx(0x30+arr1[t]); if(t==4) tx('.'); } } } } } goto qwe; } } }