Code
Code
h"
printf("AT+CMGF=0");
putc(13);//enter CR
output_bit(Led1,1);
delay_ms(1000);
output_bit(Led1,0);
#include ".\myLCD16x2.c"
#include <math.h>
#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);
}
}
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);
");
2057.2950
{
unsigned char i;
lcd_gotoxy(x,y);
//lcd_putchar(lat0);
for (i=0;i<9;i++)
{
lcd_putchar(lat[i]);
}
}
//---------------------void lon_display(unsigned char x, unsigned char y) //
10550.3465
{
unsigned char i;
lcd_gotoxy(x,y);
for (i=0;i<10;i++)
{
lcd_putchar(lon[i]);
}
}
//---------------------void speed_display(unsigned char x, unsigned char
y)// 0.16
{
unsigned char i;
lcd_gotoxy(x,y);
for (i=0;i<4;i++)
{
lcd_putchar(speed[i]);
}
lcd_putsf(" Knots");
}
//---------------------void pass_x_char(unsigned char x_char)
{
for (i=0;i<x_char;i++)
{
Gps = getchar1();
}
}
//$GPRMC,020908.000,A,2057.2950,N,10550.3465,
E,0.16, 218.51,050510,,,A*6F Nha KHOA
void wait_RMC(void)
{
//----- wait for "$GPRMC" ---Gps = getchar1();
while (Gps != '$')
{
Gps = getchar1();
};
Gps = getchar1();
while (Gps != 'G')
{
Gps = getchar1();
};
Gps = getchar1();
while (Gps != 'P')
{
Gps = getchar1();
};
Gps = getchar1();
while (Gps != 'R')
{
Gps = getchar1();
};
Gps = getchar1();
while (Gps != 'M')
{
Gps = getchar1();
};
Gps = getchar1();
while (Gps != 'C')
{
Gps = getchar1();
};
//----- Hour detection -- $GPRMC,020908
pass_x_char(1); // ','
for (i=0;i<6;i++)
{
Gps = getchar1();
hour[i] = Gps;
hour[7] = '\0';
//lcd_gotoxy(i,0);
//lcd_putchar(Gps);
//delay_ms(1000);
}
//----- Latitude detection -$GPRMC,020908.000,A,2057.2950
pass_x_char(7); // ','
for (i=0;i<9;i++)
{
Gps = getchar1();
latx[i] = Gps;
latx[10] = '\0';
//lcd_gotoxy(i,1);
//lcd_putchar(Gps);
}
for (i=0;i<10;i++)
{
lat[i] = latx[i];
}
lat0 = lat[0];
//----- Longitude detection -$GPRMC,020908.000,A,2057.2950,N,10550.3465
pass_x_char(3); // ','
for (i=0;i<10;i++)
{
Gps = getchar1();
lon[i] = Gps;
lon[11] = '\0';
//lcd_gotoxy(i,0);
//lcd_putchar(Gps);
}
//----- Speed detection -$GPRMC,020908.000,A,2057.2950,N,10550.3465,E,
0.16
pass_x_char(3); // ','
for (i=0;i<4;i++)
{
Gps = getchar1();
speed[i] = Gps;
speed[5] = '\0';
//lcd_gotoxy(i,1);
//lcd_putchar(Gps);
}
//-----Date detection -$GPRMC,020908.000,A,2057.2950,N,10550.3465,E,
0.16, 218.51,050510,,,A*6F
pass_x_char(8); // ','
for (i=0;i<6;i++)
{
Gps = getchar1();
date[i] = Gps;
date[7] = '\0';
//lcd_gotoxy(i,0);
//lcd_putchar(Gps);
}
}
#include <p18f2610.h>
#include <delays.h>
#include <usart.h>
#include <adc.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char gps[100];
int i = 0;
int data=0;
char getc_GPS();
void putc_GPS(char xc);
OpenUSART(USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW, 64);
while(1){
//while(data<100)
if (received == 1) {
received = 0;
//GPS[data] = signal; //copy into array
putcUSART(signal);
//data++;
}
}
//putsUSART(GPS);
}