PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > PIC - Thiết kế và Ứng dụng

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

PIC - Thiết kế và Ứng dụng Ý tưởng cho các sản phẩm sử dụng PIC/dsPIC và các sản phẩm của Microchip

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 24-12-2013, 03:15 PM   #28
leanhdung90
Nhập môn đệ tử
 
Tham gia ngày: Sep 2013
Bài gửi: 7
:
Trích:
Nguyên văn bởi longtu View Post
Mình tạo luồn này để nói về Sim908, cách thiết kế phần cứng cũng cách sử dụng.

Các bạn nếu quan tâm đến GPS module thôi thì đọc bài viết này của mình:
http://www.picvietnam.com/forum/showthread.php?p=54876
Sau thời gian tìm hiểu em đã viết chương trình giám sát nhiệt độ và điều khiển thiết bị nhưng không biết bị lỗi gì mà nó không chạy. Anh có thể xem chương trình của em rồi tìm nguyên nhân giúp em với. Gần đến ngày nộp lắm rồi. Em dùng module sim900d giao tiếp với vdk 16f877. điều khiển led ra ở chân C0 C1.
Đây là code của em:
#include <16f877a.h>
#device PIC16F877A*=16 ADC=10
#include <string.h>
#include <lcd_lib_4bit.c>
#fuses nowdt,hs,noput,noprotect,nodebug,nobrownout,nolvp, nocpd,nowrt
#use delay(clock=12000000)
#use fast_io(b)
#use fast_io(e)
#define Led0 PIN_C0
#define Led1 PIN_C1
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
char chuoi[90],noidung_sms[20],tu_khoa[20];
int8 dem,i,j,k,new_sms,z,vitri,x,y,adc,f;
/*********** Khai bao ngat nhan noi tiep ***********/
#INT_RDA
void ngat()
{
chuoi[dem]=getc();
if(chuoi[dem]=='')
{
z++;
if(z==2)new_sms=1;
}
dem++;
}
void xuly();
void xuly_sms();
void gsm_config();
void xoa();
void nhiet_do();
void main()
{
enable_interrupts(global);//Cho phep ngat toan cuc
enable_interrupts(int_rda);//Cho phep ngat nhan noi tiep
setup_adc(ADC_clock_internal); // thiet lap tan so lay mau ADC
setup_adc_ports(AN0); // ngo vao A0
set_adc_channel(0); // chan doc gia tri adc bang read_adc()
portd=1;delay_ms(1000);portd=0;delay_ms(1000); //1 led sang
LCD_init(); //khoi tao LCD
Printf(LCD_putchar," DO AN ");
LCD_putcmd(0xC0);Printf(LCD_putchar,"Dang cau hinh ");delay_ms(1000);
gsm_config();//goi chuong trinh con cau hinh Module GSM
LCD_putcmd(0xC0);Printf(LCD_putchar,"Cau hinh xong ");delay_ms(2000);
new_sms=0;
z=0;
while(1)
{
signed int16 x;
signed int16 adc;
int16 y=70; // nhiet do bao dong
x=read_ADC();
adc=x/2; // do C
f=adc*1.8+32; // do F
LCD_putcmd(0x01);// xoa man hinh chi thi
LCD_putcmd(0x80);Printf(LCD_putchar," Nhiet do phong ");
LCD_putcmd(0xC0);Printf(LCD_putchar,"%u",adc);LCD_ putcmd(0xC0+4);Printf(LCD_putchar,"C");
LCD_putcmd(0xC0+8);Printf(LCD_putchar,"%u",f);LCD_ putcmd(0xC0+12);Printf(LCD_putchar,"F");
delay_ms(500);
if(new_sms==1)
{
LCD_putcmd(0x01);// xoa man hinh chi thi
LCD_putcmd(0x80); Printf(LCD_putchar,"Co tin nhan moi ");
LCD_putcmd(0xC0); Printf(LCD_putchar,"Dang xu ly");
xoa();
puts("at+cmgr=1");
delay_ms(500);
xuly_sms();
LCD_putcmd(0x01);// xoa man hinh chi thi
xuly();
trang_thai();
nhiet_do();
delay_ms(200);
puts("at+cmgd=1");
delay_ms(500);
xoa();
delay_ms(500);
}
if(adc>=y) // kiem tra nhiet do cao
{
LCD_putcmd(0x01);// xoa man hinh chi thi
LCD_putcmd(0x80);Printf(LCD_putchar," Nhiet do cao ! ");
LCD_putcmd(0xC0);Printf(LCD_putchar,"Dang goi dien ");
printf("ATD01674577163;");
putc(13);
delay_ms(20000);
puts("ATH");
delay_ms(1000);
printf("AT+CMGS=\"01675491246\"\r\n");
delay_ms(500);
printf("Nhiet do luc nay la:\r\n %u",adc); // gui nhiet do ve may
delay_ms(500);
printf("do C");
delay_ms(500);
putc(26); // ctrl +Z
delay_ms(500);
}

}
void gsm_config()
{
delay_ms(2000);
printf("at\r\n");
delay_ms(500);
printf("at\r\n");
delay_ms(500);
printf("at\r\n");
delay_ms(500);
printf("at\r\n");
delay_ms(500);
printf("ate0\r\n");
delay_ms(500);
printf("at+cmgf=1\r\n");
delay_ms(500);
printf("at+cmgd=1\r\n");
delay_ms(500);
xoa();
delay_ms(500);
}
//+++++++++++++++ xoa +++++++++++++++++//
void xoa()
{
new_sms=0;
z=0;
dem=0;
y=0;
vitri=0;
for(i=0;i<=90;i++) //Xoa chuoi[]
{chuoi=0;}
for(i=0;i<=20;i++) //Xoa noidung_sms[]
{noidung_sms=0;}
}
//+++++++++++++++++++++ xu ly tin nhan ++++++++++++++//
void xuly_sms()
{
y=0;
k=0;
for(i=0;i<=strlen(chuoi);i++)
{
if(chuoi=='\n')
{
k++;
if(k==2)vitri=i+1 ;
}
}
for(x=vitri;x<strlen(chuoi)-8;x++)
{noidung_sms[y]=chuoi[x];
y++ ; // lay noi dung
}
}
//+++++++++++++++ XU LY va DIEU KHIEN +++++++++++++++++++//
void xuly()
{
strcpy(tu_khoa,"On1");
if(strcmp(tu_khoa,noidung_sms)==0)
{
output_bit(Led1,1);
LCD_putcmd(0x80); Printf(LCD_putchar,"Den 1 da mo ");
LCD_putcmd(0xC0); Printf(LCD_putchar,"Gui sms p.hoi");
printf("AT+CMGS=\"01675491246\"\r\n");
delay_ms(500);
printf("den 1 da mo");
delay_ms(500);
putc(26); // ctrl +Z
delay_ms(500);
}
strcpy(tu_khoa,"Off1");
if(strcmp(tu_khoa,noidung_sms)==0)
{
output_bit(Led1,0);
LCD_putcmd(0x80); Printf(LCD_putchar,"Den 1 da tat ");
LCD_putcmd(0xC0); Printf(L CD_putchar,"Gui sms p.hoi");
printf("AT+CMGS=\"01675491246\"\r\n");
delay_ms(500);
printf("den 1 da tat");
delay_ms(500);
putc(26); // ctrl +Z
delay_ms(500);
}
strcpy(tu_khoa,"On2");
if(strcmp(tu_khoa,noidung_sms)==0)
{
output_bit(Led2,1);
LCD_putcmd(0x80); Printf(LCD_putchar,"Den 2 da mo ");
LCD_putcmd(0xC0); Printf(LCD_putchar,"Gui sms p.hoi");
printf("AT+CMGS=\"01675491246\"\r\n");
delay_ms(500);
printf("den 2 da mo");
delay_ms(500);
putc(26); // ctrl +Z
delay_ms(500);
}
strcpy(tu_khoa,"Off2");
if(strcmp(tu_khoa,noidung_sms)==0)
{
output_bit(Led2,0);
LCD_putcmd(0x80); Printf(LCD_putchar,"Den 2 da tat ");
LCD_putcmd(0xC0); Printf(LCD_putchar,"Gui sms p.hoi");
printf("AT+CMGS=\"01675491246\"\r\n");
delay_ms(500);
printf("den 2 da tat");
delay_ms(500);
putc(26); // ctrl +Z
delay_ms(500);
}
}
void nhiet_do()
{
strcpy(tu_khoa,"nhietdo");
if(strcmp(tu_khoa,noidung_sms)==0)
{
LCD_putcmd(0x80); Printf(LCD_putchar,"Kiem tra nhiet ");
LCD_putcmd(0xC0); Printf(LCD_putchar,"do ve dt ");
printf("AT+CMGS=\"01675491246\"\r\n");
delay_ms(500);
printf("Nhiet do luc nay la:\r\n %u",adc); // gui nhiet do ve may
delay_ms(500);
printf("do C");
delay_ms(500);
putc(26); // ctrl +Z
delay_ms(500);
}
}
leanhdung90 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 04:46 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam