View Single Post
Old 21-06-2012, 11:35 AM   #1
xuanthuongth
Nhập môn đệ tử
 
Tham gia ngày: Aug 2010
Bài gửi: 2
:
hỏi về pic 16f877a

em đang làm đồ điều khiển 4 thiết bị bằng tin nhắn sms sữ dụng module sim300cz voi pic 16f877a , phần cứng em kết noi trực tiếp từ hai chân rx,tx của module sim với hai rx,tx của pic . nhưng khi em viết chương trình cho pic khi biên dịch thì báo lỗi không sữ dụng rs232 .
Bác nào có từng làm đề tài này chỉ em với .
đây là đoạn code em lập trình 1 thiết bị

#include <16f877a.h>// chuong trinh su dung cho vi dieu khien Pic16f877a
#device icd=true // tao ma tuong thich debug phan cung Microchip
#fuses HS,NOWDT,NOPROTECT,NOLVP // khai bao cac thiet dat cho Pic
#use delay(clock=20000000) // su dung OSC=20 Mhz
#include <string.h>
#include <stdlibm.h>
#include <stdlib.h>
char chuoi[90],noidung_sms[20],tu_khoa[20];
int i,y,k,vitri,x;
// khai bao thanh ghi
#byte portb=0x06
#byte portc=0x07
#bit b1=portb.0
#bit b2=portb.1
#bit b3=portb.2
#bit b4=portb.3
void xuly();
void xuly_sms();
void gsm_config();
void trang_thai();
void main()
{
set_tris_b(0b00000000);
portb=0;
}
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);
}
//+++++++++++++++++++++ xu ly tin nhan ++++++++++++++//
void xuly_sms()
{
y=0;
k=0;
for(i=0;i<=strlen(chuoi);i++)
{
if(chuoi[i]=='\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)
{
b1=1;
printf("AT+CMGS=\"01674577163\"\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)
{
b1=0;
printf("AT+CMGS=\"01674577163\"\r\n");
delay_ms(500);
printf("den 1 da tat");
delay_ms(500);
putc(26); // ctrl +Z
delay_ms(500);
}
}
void trang_thai()
{
strcpy(tu_khoa,"Status");
if(strcmp(tu_khoa,noidung_sms)==0)
printf("AT+CMGS=\"01674577163\"\r\n");
delay_ms(500);
if(b1==1)
{
printf("den 1 dang mo\r\n");
delay_ms(500);
}
if(b1==0)
{
printf("den 1 dang tat\r\n");
delay_ms(500);
}
putc(26); // ctrl +Z
delay_ms(500);
}
xuanthuongth vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn