Thiết kế mạch tự động cân bằng nhiệt độ và điều khiển thiết bị thông qua tin nhắn SMS - 9

char chuong_trinh = 0;


/// Ham delay

void delay (unsigned int a) { unsigned int x ; unsigned char y ;

for (x=0 ; x<=a ; x ++) {

for (y=0 ; y<=200 ; y ++ ) { }

}

}


// ham khoi tao ADC0804 void ADC_0804(void){

Có thể bạn quan tâm!

Xem toàn bộ 80 trang tài liệu này.

CS_ADC=0; WR_ADC=0;

_nop_(); WR_ADC=1; CS_ADC=1;

Thiết kế mạch tự động cân bằng nhiệt độ và điều khiển thiết bị thông qua tin nhắn SMS - 9

delay(10);


P1=0XFF; CS_ADC=0; RD_ADC=0;

nhiet_do=P1; RD_ADC=1; CS_ADC=1;

}

// HAM NGAT TIMER

void ngat_timer0() interrupt 1 { TR0 = 0;

TF0 = 0;

if(caidat == 1){

n1 = temp/10; n2 = temp%10; n3 = 10;


}

else {

n4 = 11;


n1 = nhietdocd/10; n2 = nhietdocd%10; n3 = 12;

n4 = 12;


LED_1=LED_2=LED_3=LED_4=1;

dem++; if(dem == 1){

P0 = bang_ma[n1]; LED_1 = 0;

};

if(dem == 2){

P0 = bang_ma[n2]; LED_2 = 0;

};

if(dem == 3){

P0 = bang_ma[n3]; LED_3 = 0;

};

if(dem == 4){

dem = 0;

P0 = bang_ma[n4]; LED_4 = 0;

};

} TR0 = 1;

}


//Ham chinh

void main (void) {

TMOD = 0x01; // timer 1 che do 1 16bit, timer 0 che do 2 8bit tu dong nap lai ET0 = 1; // ngat timer 0

TH0 = 0xEC; // 0xEC

TL0 = 0x77; // cu 100us thi xay ra ngat ET0 = 1;

EA = 1;

TR0 = 1; // khoi chay timer 0 ADC_0804();

while (1) {


}

}


CODE DANH CHO SIM900A

#include

#include

#include "lcd.c"

#include "1wire.c"

#include "ds18b20.c"


void send_sms(char *sdt, char n);

unsigned char i, j=13, dau_nhay, str[16], rev, xbuffer; unsigned char *check1,*check2,*check3,*check4; unsigned char den1

unsigned char den2 unsigned char den3 unsigned char den4

unsigned char num1[]="+84984076453";

unsigned char rev_c0,rev_c1,rev_c2,rev_c3,rev_c4,rev_c5; unsigned char buffer[95], tach_so[16];

unsigned char *ptr, ok[]="OK";// ktnd[]="ktnd";

unsigned char eeprom; int1 new_sms;

int1 tb;

void Clear_buffer(void)

{

for(i = 0 ; i < 150 ; i++)

{

buffer[i] =' '; delay_us(100);

}

}

void clear_tachso(){ for(i=0;i<16;i++){ tach_so[i]=' '; delay_us(100);

}

}

#int_rda

void ISR_RDA(){

//Led_bao=!Led_bao;

rev=getch(); // lay du lieu khi nhan duoc if(rev=='+') rev_c1=rev;

if(rev=='C') rev_c2=rev; if(rev=='M') rev_c3=rev; if(rev=='T') rev_c4=rev; if(rev=='I') rev_c5=rev;

if(rev_c1=='+'&&rev_c2=='C'&&rev_c3=='M'&&rev_c4=='T'&&rev_c5=='I')

{Led_bao=0; new_sms=1;}

if(rev != 13 && rev != 10) buffer[xbuffer++]=rev; if(xbuffer>149) xbuffer=0;

}

unsigned char wait_ok(){ ptr=strstr(buffer,ok); if(strncmp(ptr,ok,2)==0) return 1;

return 0;

}

void deleteall_sms(){ printf("AT+CMGDA=");//delete all message putc(34); printf("DEL ALL"); putc(34); putc(13); delay_ms(1000);

}

void delete_sms(){ printf("AT+CMGD=1");//delete all message putc(13);

delay_ms(1000);

}

void reset_var(){


rev=rev_c0=rev_c1=rev_c2=rev_c3=rev_c4=rev_c5=new_sms=xbuffer=j=dau_nhay= tb=0;

}

void khoi_tao_GSM(){ Led_bao=0; // bat led PWU_KEY = 1;

delay_ms(1500); // kich 1 xung toi thieu la 1s PWU_KEY = 0;

delay_ms(8000); // cho SIM900A duoc khoi dong xong printf("ATE0"); putc(13); delay_ms(200); // tat che do ECHO printf("AT"); putc(13); delay_ms(2000); // gui lenh AT

printf("AT+CMGF=1"); putc(13); delay_ms(2000); // cau hinh nhan tin nhan dang text(mac dinh la PDU)

Clear_buffer(); reset_var();

printf("AT+CNMI=2,1,0,0,0"); putc(13); delay_ms(2000); // cau hinh khi sim co tin nhan moi

while(wait_ok() == 0);

delete_sms(); delay_ms(2000); Clear_buffer(); reset_var();

j=12; // Tong so +84984076453 la 12 send_sms(num1,0);

delay_ms(3000); sprintf(str,"SIM900A San Sang"); LCD_Gotoxy(0,0); LCD_Puts(str);

Led_bao=1; // tat led

}

// Goi tin nhan

void send_sms(char *sdt, char n){ Led_bao=0; printf("AT+CMGS=");

putc(34); // dau " for(i=0;i

putc(13);

delay_ms(2000); // delay 2s switch(n){

case 0: {printf("BAT DAU SAN SANGnr"); break;} case 1: {printf("DA BAT DEN SO ,1nr"); break;} case 2: {printf("DA TAT DEN SO ,1nr"); break;} case 3: {printf("DA BAT DEN SO ,2nr"); break;} case 4: {printf("DA TAT DEN SO ,2nr"); break;} case 5: {printf("DA BAT DEN SO ,3nr"); break;} case 6: {printf("DA TAT DEN SO ,3nr"); break;} case 7: {printf("DA BAT DEN SO ,4nr"); break;} case 8: {printf("DA TAT DEN SO ,4nr"); break;}

case 9: {printf("Nhiet do phong hien nay la: nr"); break;}

case 10: {printf("SAI CU PHAP,BAM “HELP” HOAC GOI DEN 0984076453 DE

DUOC TRO GIUP!nr"); break;} case 11: {

for(i=0;i<150;i++){ putc(buffer[i]);

}

break;

}

delay_ms(100); putc(26); // ctr+z delay_ms(2000);

Led_bao=1; // tat led bao da hoan tat viec gui tin nhan

}

// Ham chinh void main() {

set_tris_a(0b00000011); set_tris_b(0b00100001); set_tris_c(0b10000011); set_tris_d(0x00); set_tris_e(0x00); Coi_chip =1 ;

PWU_KEY = PORTD_0 = PORTD_1 = PORTD_2 = PORTD_3 = 0; Led_bao = 1;

delay_ms(500); eeprom=read_eeprom(0); PORTD_0 = eeprom & 0; PORTD_1 = (eeprom>>1) & 0; PORTD_2 = (eeprom>>2) & 0; PORTD_3 = (eeprom>>3) & 0;

// Ham ngat enable_interrupts(int_rda); enable_interrupts(global); LCD_Init();

delay_ms(200); sprintf(str,"DEMO SIM900A"); LCD_Gotoxy(2,0); LCD_Puts(str); khoi_tao_GSM(); Clear_buffer();

delay_ms(500);

// Tat dong benh ngoai while(true){

// Nut reset if(!Reset_gsm){ delay_us(1000); while(!Reset_gsm); PWU_KEY = 1;

delay_ms(2000); // kich 1 xung toi thieu la 1s PWU_KEY = 0;

}

// Khi co tin nhan moi

if(new_sms == 1){ // khi co tin nhan moi den SIM900A new_sms = 0;

Clear_buffer(); // xoa buffer clear_tachso();

reset_var();

//delay_ms(3000);

printf("AT+CMGR=1");putc(13); delay_ms(4000);// cho 2s doc tin nhan moi j=0;

for(i=15;i<50;i++){ // 10 if(buffer[i]=='+') dau_nhay=1; if(dau_nhay) { if(buffer[i]=='"') break;

else {tach_so[j]=buffer[i]; j++; }

}

..... Xem trang tiếp theo?
⇦ Trang trước - Trang tiếp theo ⇨

Ngày đăng: 29/06/2022