gsm

5
#include <18F4520.h> #device *=16 adc=8 #FUSES NOWDT //No Watch Dog Timer #FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale #FUSES HS //Low power osc < 200 khz #FUSES NOPROTECT //Code not protected from reading #FUSES NOBROWNOUT //No brownout reset #FUSES BORV20 //Brownout reset at 2.0V #FUSES NOPUT //No Power Up Timer #FUSES NOCPD //No EE protection #FUSES STVREN //Stack full/underflow will cause reset #FUSES NODEBUG //No Debug mode for ICD #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O #FUSES NOWRT //Program memory not write protected #FUSES NOWRTD //Data EEPROM not write protected #FUSES IESO //Internal External Switch Over mode enabled #FUSES FCMEN //Fail-safe clock monitor enabled #FUSES PBADEN //PORTB pins are configured as analog input channels on RESET #FUSES NOWRTC //configuration not registers write protected #FUSES NOWRTB //Boot block not write protected #FUSES NOEBTR //Memory not protected from table reads #FUSES NOEBTRB //Boot block not protected from table reads #FUSES NOCPB //No Boot Block code protection #FUSES LPT1OSC //Timer1 configured for low-power operation #FUSES MCLR //Master Clear pin enabled #FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode) #use delay(clock=20000000) #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) unsigned char sms[150]; char c=0x00,c1=0x00,c2=0x00,c3=0x00,c4=0x00,c5=0x00; int8 new_sms=0,i=0,j=0,vi_tri,dk; // ngắt nhận UART // đọc tất cả dữ liệu từ module sim truyền đến và lưu vào mảng sms[] // nếu chuỗi dữ liệu ban đầu là +CMTI thì đã có tin nhắn mới. #int_RDA void RDA_isr(void) { c=getc(); if(c=='+') c1=c; if(c=='C') c2=c; if(c=='M') c3=c;

Upload: doublemint1001

Post on 14-Sep-2015

214 views

Category:

Documents


1 download

DESCRIPTION

gsm

TRANSCRIPT

#include #device *=16 adc=8

#FUSES NOWDT //No Watch Dog Timer#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale#FUSES HS //Low power osc < 200 khz#FUSES NOPROTECT //Code not protected from reading#FUSES NOBROWNOUT //No brownout reset#FUSES BORV20 //Brownout reset at 2.0V#FUSES NOPUT //No Power Up Timer#FUSES NOCPD //No EE protection#FUSES STVREN //Stack full/underflow will cause reset#FUSES NODEBUG //No Debug mode for ICD#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O#FUSES NOWRT //Program memory not write protected#FUSES NOWRTD //Data EEPROM not write protected#FUSES IESO //Internal External Switch Over mode enabled#FUSES FCMEN //Fail-safe clock monitor enabled#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET#FUSES NOWRTC //configuration not registers write protected#FUSES NOWRTB //Boot block not write protected#FUSES NOEBTR //Memory not protected from table reads#FUSES NOEBTRB //Boot block not protected from table reads#FUSES NOCPB //No Boot Block code protection#FUSES LPT1OSC //Timer1 configured for low-power operation#FUSES MCLR //Master Clear pin enabled#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=20000000)#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)unsigned char sms[150];char c=0x00,c1=0x00,c2=0x00,c3=0x00,c4=0x00,c5=0x00;int8 new_sms=0,i=0,j=0,vi_tri,dk;// ngt nhn UART// c tt c d liu t module sim truyn n v lu vo mng sms[]// nu chui d liu ban u l +CMTI th c tin nhn mi.

#int_RDAvoid RDA_isr(void){ c=getc(); if(c=='+') c1=c; if(c=='C') c2=c; if(c=='M') c3=c; if(c=='T') c4=c; if(c=='I') c5=c; if(c1=='+' && c2=='C' && c3=='M' && c4=='T' && c5=='I') new_sms=1; if((c!=13)&&(c!=10)){sms[i]=c; i++;}}

#define LCD_ENABLE_PIN PIN_D2#define LCD_RS_PIN PIN_D0#define LCD_RW_PIN PIN_D1#define LCD_TYPE 2#include

void delete_sms(){ printf("AT+CMGD=1,4\r\n");//delete all message delay_ms(500);}

void reset(){ i=0; new_sms=0; c=0x00,c1=0x00,c2=0x00,c3=0x00,c4=0x00,c5=0x00; for(j=0;j