Custom Search



Nơi bạn đến là nơi tôi bắt đầu, nơi tôi qua sẽ là nơi bạn đến...

Tuesday, October 2, 2012

Giao tiếp vi điều khiển với Module 548




Sơ đồ nguyên lý giao tiếp giữa Vi Điều Khiển với Module Sim548:



Code Demo:



#include "Pic_GSM_demo.h"


#include ".\myLCD16x2.c"
#include


#define Led0 PIN_C1
#define Led1 PIN_C2
#define GSM_PW PIN_E2
#define GSM_SENSE PIN_E1
#define TEXTMODE 5;
#define PDUMODE 0;


void GSM_init(void);
void GSM_start(void);
void GSM_sel_mess_mode(char mode);


void GSM_init(void)
{
output_bit(GSM_PW,1);
output_bit(Led1,1);
output_float(GSM_SENSE);
}
void GSM_start(void)
{
//start up GSM module
delay_ms(2000);
lcd_init();

lcd_putc("\fwww.elabvn.com\n");
lcd_putc("Pic GSM rev 1.0");
//printf("GSM demo \n \r");
output_bit(GSM_PW,0);
output_bit(Led1,0);
delay_ms(2000);
output_bit(GSM_PW,1);
output_bit(Led1,1);
lcd_putc("\nGSM initializing");
delay_ms(50000);


}


void GSM_sel_mess_mode(char mode)
{
if(mode>0) //text mode
{
output_bit(Led1,0);
printf("AT+CMGF=1");
putc(13);//enter CR
output_bit(Led1,1);
delay_ms(1000);
output_bit(Led1,0);


}
else //PDU mode
{
output_bit(Led1,0);
printf("AT+CMGF=0");
putc(13);//enter CR
output_bit(Led1,1);
delay_ms(1000);
output_bit(Led1,0);
}

}


void main()
{
int1 gsm_ok;
int cnt;
int1 temp;
char c;
int i;



GSM_init();
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab


// TODO: USER CODE!!
GSM_start();
GSM_sel_mess_mode(5);

printf("ATE1"); //echo on
putc(13);//enter CR
delay_ms(1000);//

printf("AT");
putc(13);//enter CR
output_bit(Led1,1);
lcd_putc("\nGSM send message ");
delay_ms(1000);
output_bit(Led1,0);
printf("AT+CMGS=");
putc(34);//"
printf("0989703330");
putc(34);//"

putc(13);//enter CR
delay_ms(1000);//cho ki tu ">"
printf("SIM300 Ready");
delay_ms(1000);//
putc(0x1A);//CTRL+Z
output_bit(Led1,1);
delay_ms(2000);//

lcd_putc("\nGSM sent done ");
while(1);
}


Nguồn: anhduc_4share