em copy trên mạng về được chương trình này nhưng không hiểu ý nghĩ chương trình thế nào. các pro nào có thể giải thích giúp e đoạn code này không ?
Code:
#include <16f877a.h> #device pic16f877a*=16adc=10 #include <string.h> #fuses NOWDT,XT,PUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP #use delay(clock=4000000) #use fast_io(d) #use fast_io(b) #use fast_io(c) #use fast_io(a) #use fast_io(e) #byte porta=0x05 #byte portb=0x06 #byte portc=0x07 #byte portd=0x08 #byte porte=0x09 #bit RS=PORTE.0 #bit RW=PORTE.1 #bit E=PORTE.2 #bit c0=portc.0 #bit c1=portc.1 #bit c2=portc.2 #bit c3=portc.3 #bit c4=portc.4 #bit c5=portc.5 #bit b0=portb.0 #bit b1=portb.1 #bit b2=portb.2 #bit b3=portb.3 #bit b4=portb.4 #bit b5=portb.5 #bit b6=portb.6 #bit b7=portb.7 #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7) char buff[90],tukhoa[5],nd_sms[20],nd_lcd[50],kt_bao_sms[9],kt[9]; int i,vitri,k,j,nguon,n,l,y,s,x,chuc,dv,cb; int1 ok; #INT_RDA void receive() { buff[i]=getc(); i++; if (i==2) {ok=1;} } void hien(); void xoa(); void kt_sms(); void tao(); void xuat(); void cauhinh(); void xoa_lcd(); void xuli_sms(); void kt_dieukhien(); void hienthi_nd_sms(); void doc_adc(); void main() { set_tris_b(0b00000000); set_tris_e(0b000); set_tris_d(0b00000000); set_tris_c(0b10100000); set_tris_a(0b100001); enable_interrupts(int_rda); enable_interrupts(global); i=0; portd=0; nguon=0; ok=0; c1=0; c2=0; c3=0; c4=0; k=0; strcpy (nd_lcd,"Welcome"); hien(); delay_ms(1000); strcpy (nd_lcd,"Duc - Cuong"); hien(); c0=1;//kich mass mo nguon delay_ms(5000); //mo nguon module c0=0; delay_ms(3000); xoa_lcd(); strcpy (nd_lcd,"Loading"); hien(); delay_ms(1000); cauhinh(); xoa_lcd(); strcpy (nd_lcd,"Finish"); hien(); delay_ms(1000); xoa_lcd(); strcpy (nd_lcd,"Call user"); hien(); printf("atd0944383390;\r\n"); delay_ms(8000); printf("ath\r\n"); delay_ms(4000); xoa(); ////vao vong lap chinh ///// while (1) { strcpy (nd_lcd,"Nhiet Do:"); hien(); delay_ms(5); doc_adc(); delay_ms(10); x=read_adc(); x=x/2.049; chuc=cb=x/10; dv=x%10; chuc=chuc+48; portd=chuc; xuat(); dv=dv+48; portd=dv; xuat(); //////////////////////////////chinh sua o day//////////////// kt_sms(); xoa(); if (n==1) { xoa_lcd(); strcpy (nd_lcd,"New Mesager"); hien(); xoa(); delay_ms(500); xuli_sms(); delay_ms(1000); kt_dieukhien(); xoa(); printf("at+cmgd=1\r\n"); n=0; delay_ms(2000); xoa(); } if (cb>=6) { strcpy (nd_lcd,"Warning"); hien(); delay_ms(2000); strcpy (nd_lcd,"Call user"); hien(); printf("at+cmgs=\"0944383390\"\r\n"); delay_ms(1000); printf("Canh bao nhiet do cao tren 60 do"); delay_ms(1000); putc(26); delay_ms(4000); strcpy (nd_lcd,"Sent SMS"); hien(); delay_ms(1500); xoa(); } } while (1) {} } //// VOID HIEN THI DU LIEU LEN LCD// void hien() { portd=0x01; tao(); portd=0x38; tao(); portd=0x0c; tao(); portd=0x80; tao(); for (l=0;l<= strlen(nd_lcd)-1;l++) { portd=nd_lcd[l]; xuat(); } } ///// VOID KHOI TAO LCD// void tao() { rs=0; rw=0; e=1; e=0; delay_ms(10); } ////VOID XUAT DU LIEU LEN LCD// void xuat() { e=1; rs=1; rw=0; e=0; delay_ms(10); } void kt_sms() { s=0; for (j=0;j<=80;j++) { if (buff[j]=='\r') { s++; } if (s==2) { n=1; } } } void cauhinh() {printf("a"); delay_ms(2000); {printf("a"); delay_ms(2000); printf("at\r\n"); delay_ms(2000); xoa(); printf("at\r\n"); delay_ms(2000); while (ok==0) { xoa_lcd(); xoa(); strcpy (nd_lcd,"Co loi"); hien(); printf("at\r\n"); delay_ms(2000); } xoa(); strcpy (nd_lcd,"OK"); hien(); printf ("ate0\r\n"); delay_ms(2000); printf ("at+csq\r\n"); delay_ms(2000); printf ("at+cmgf=1\r\n"); delay_ms(2000); printf ("at+cmgf=1\r\n"); delay_ms(2000); } } //// XOA NOI DUNG CHUOI//// void xoa() { i=0; vitri=0; for(j=0;j<=89;j++) //Xoa chuoi[] {buff[j]=0;} for(j=0;j<=5;j++) //Xoa {kt_bao_sms[i]=0;} for(j=0;j<=5;j++) //Xoa {kt[j]=0;} for(j=0;j<=20;j++) //Xoa {nd_sms[j]=0;} j=0; } //// void kiem tra bao co tin nhan moi// ///////// xoa LCD ///////// void xoa_lcd() { for(j=0;j<=49;j++) //Xoa nd_lcd[] {nd_lcd[j]=0;} } void xuli_sms() {xoa(); printf("at+cmgr=1\r\n"); delay_ms(3000); k=0; for (j=0;j<=strlen(buff)-9;j++) { if (buff[j]=='C') { k++; if (k==3) { vitri=j+1; } } } y=0; for (j=vitri;j<=strlen(buff)-9;j++) { nd_sms[y]=buff[j]; y++; } k=0; vitri=0; y=0; } ////++++ kiem tra ki tu dieu khien+++ void kt_dieukhien() { strcpy (nd_lcd,"Processing"); hien(); delay_ms(2000); hienthi_nd_sms(); delay_ms(2000); strcpy (kt,"ON1"); if ( strcmp(nd_sms,kt)==0 ) { c1=1; strcpy (nd_lcd,"CB1: ON"); hien(); delay_ms(1500); strcpy (nd_lcd,"Call user"); hien(); printf("at+cmgs=\"0944383390\"\r\n"); delay_ms(1000); printf("da bat TB1"); delay_ms(1000); putc(26); delay_ms(4000); xoa(); } strcpy (kt,"ON2"); if ( strcmp(nd_sms,kt)==0 ) { c2=1; strcpy (nd_lcd,"CB 2: ON"); hien(); delay_ms(1500); strcpy (nd_lcd,"Call user"); hien(); printf("at+cmgs=\"0944383390\"\r\n"); delay_ms(1000); printf("da bat TB 2"); delay_ms(1000); putc(26); delay_ms(4000); xoa(); } strcpy (kt,"ON3"); if ( strcmp(nd_sms,kt)==0 ) { c3=1; strcpy (nd_lcd,"CB 3: ON"); hien(); delay_ms(1500); strcpy (nd_lcd,"Call user"); hien(); printf("at+cmgs=\"0944383390\"\r\n"); delay_ms(1000); printf("da bat TB 3"); delay_ms(1000); putc(26); delay_ms(4000); xoa(); } strcpy (kt,"ON4"); if ( strcmp(nd_sms,kt)==0 ) { c4=1; strcpy (nd_lcd,"CB4: ON"); hien(); delay_ms(1500); strcpy (nd_lcd,"Bao nguoi dung"); hien(); printf("at+cmgs=\"0944383390\"\r\n"); delay_ms(1000); printf("da bat TB4"); delay_ms(1000); putc(26); delay_ms(4000); xoa(); } //////////// strcpy (kt,"OFF1"); if ( strcmp(nd_sms,kt)==0 ) { c1=0; strcpy (nd_lcd,"CB1: OFF"); hien(); delay_ms(1500); strcpy (nd_lcd,"Call user"); hien(); printf("at+cmgs=\"0944383390\"\r\n"); delay_ms(1000); printf("da tat TB 1"); delay_ms(1000); putc(26); delay_ms(4000); xoa(); } strcpy (kt,"OFF2"); if ( strcmp(nd_sms,kt)==0 ) { c2=0; strcpy (nd_lcd,"CB2: OFF"); hien(); delay_ms(1500); strcpy (nd_lcd,"Call user"); hien(); printf("at+cmgs=\"0944383390\"\r\n"); delay_ms(1000); printf("da tat TB 2"); delay_ms(1000); putc(26); delay_ms(4000); xoa(); } strcpy (kt,"OFF3"); if ( strcmp(nd_sms,kt)==0 ) { c3=0; strcpy (nd_lcd,"CB3: OFF"); hien(); delay_ms(1500); strcpy (nd_lcd,"Call user"); hien(); printf("at+cmgs=\"0944383390\"\r\n"); delay_ms(1000); printf("da tat TB 3"); delay_ms(1000); putc(26); delay_ms(4000); xoa(); } strcpy (kt,"OFF4"); if ( strcmp(nd_sms,kt)==0 ) { c4=0; strcpy (nd_lcd,"CB 4: OFF"); hien(); delay_ms(1500); strcpy (nd_lcd,"Call user"); hien(); printf("at+cmgs=\"0944383390\"\r\n"); delay_ms(1000); printf("da bat TB 4"); delay_ms(1000); putc(26); delay_ms(4000); xoa(); } strcpy (kt,"OFFALL"); if ( strcmp(nd_sms,kt)==0 ) { c1=c2=c3=c4=0; strcpy (nd_lcd,"All CB: OFF"); hien(); delay_ms(1500); strcpy (nd_lcd,"Call user"); hien(); printf("at+cmgs=\"0944383390\"\r\n"); delay_ms(1000); printf("da tat tat ca cac TB"); delay_ms(1000); putc(26); delay_ms(4000); xoa(); } delay_ms(3000); strcpy (kt,"ONALL"); if ( strcmp(nd_sms,kt)==0 ) { c1=c2=c3=c4=1; strcpy (nd_lcd,"ALL CB: ON"); hien(); delay_ms(1500); strcpy (nd_lcd,"Call User"); hien(); printf("at+cmgs=\"0944383390\"\r\n"); delay_ms(1000); printf("da bat tat ca cac TB"); delay_ms(1000); putc(26); delay_ms(4000); xoa(); } delay_ms(3000); } void hienthi_nd_sms() { portd=0x01; tao(); portd=0x38; tao(); portd=0x0c; tao(); portd=0x80; tao(); for (l=0;l<=strlen(nd_sms)-1;l++) { portd=nd_sms[l]; xuat(); } } void doc_adc() { setup_adc(adc_clock_div_4); setup_adc_ports(an0); set_adc_channel(0); delay_ms(20); }