⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 70981e2661dc001c1d26f8cb9cfd5848

📁 LPC21XX series GSM+GPS interfacing and application of a vehicle tracking
💻
字号:
/************************************************************************   RFvygr_main.c									  ************************************************************************/#include<LPC21xx.h>#include<print.h>#define SevenLedOn  *IOSET1 = *IOSET1 |0x00FF0000#define SevenLedOff *IOCLR1 = *IOCLR1 |0x00FF0000#define  linefeed 	0x0D #define  send_cmd   0x00#define  ent_no 	0x01#define  snd_sms 	0x02#define  dial_cmd 	0x00 #define  ent_cmd    0x01#define  no		 	0x00 #define  yes        0x01unsigned char recv_ch[100];	unsigned char uart_int_flag;unsigned char sms_flag;unsigned char dial_flag;unsigned char sms_start;	void PollGSM(void);void recv_irq(void);void led_blink(void);void dela(void);void GetGPS(void);void init_com( )         /* Initialize Serial Interface       */{	*PINSEL0 = *PINSEL0 | 0x00000005;        // Enable RxD1 and TxD1              /	*U0LCR = 0x83;                          // 8 bits, no Parity, 1 Stop bit     /	//*U0DLL = 24;                            // 38400 Baud Rate @ 15MHz VPB Clock  /	*U0DLL = 97;	*U0LCR = 0x03;                          // DLAB = 0                          /		*PINSEL0 = *PINSEL0 | 0x00050000;    	/* Enable RxD1 and TxD1              */	*U1LCR = 0x83;                          /* 8 bits, no Parity, 1 Stop bit     */	*U1DLL = 97;                            /* 9600 Baud Rate @ 15MHz VPB Clock  */	*U1LCR = 0x03;                          /* DLAB = 0                          */}int c1_putchar (int ch)  	                  /* Write character to com Port 1    */{	*U0THR = ch;				/* Transmit the data */	while (!(*U0LSR & 0x20));	 /* Wait untill Transmit buffer is empty */	  	return 0;					/* Success	*/}int c2_putchar (int ch)  	                  /* Write character to com Port 2   */{		*U1THR = ch;				/* Transmit the data */	while (!(*U1LSR & 0x20));	 /* Wait untill Transmit buffer is empty */	  	return 0;					/* Success	*/}int c1_getchar (void)                       /* Read character from com Port 1   */{	while (!(*U0LSR & 0x01));		/* Wait untill Receive buffer is full */	return (*U0RBR);				/* Return the read value	*/}int c2_getchar (void)                       /* Read character from com Port 2  */{	while (!(*U1LSR & 0x01));		/* Wait untill Receive buffer is full */	return (*U1RBR);				/* Return the read value	*/	}void c1_putstr (char *p)                     // Write string {	unsigned char i;	//while (*p)	//while (*p != '\0')  	for(i=0;i<5;i++)  	{    	c1_putchar ((int) *p++);  	}}void c2_putstr (char *p)                     // Write string {	unsigned char i;	//while (*p)	//while (*p != '\0')  	for(i=0;i<5;i++)  	{    	c2_putchar ((int) *p++);  	}}/*void c1_getstr (char *p)                     // Write string {	unsigned char count;	while (*p != '\0')   	{    	c1_getchar ();  	}}void c2_getstr (char *p)                     // Write string {	while (*p != '\0')   	{    	c2_getchar ();  	}}*/void delay(){int i;for(i=0;i<100000;i++);}int main(void){  //  unsigned char buf; //   unsigned char buf_str[256]; unsigned char Com1Rcv[70]; unsigned char Com2Rcv[70];    unsigned char i;        sms_flag = send_cmd;    dial_flag = dial_cmd;    uart_int_flag=no;         *PINSEL2 = *PINSEL2 & 0xFFFFFFF7;	*IODIR1 = *IODIR1 |0x00FF0000;	for(i=0;i<=3;i++) 	{		SevenLedOn;		delay();		SevenLedOff;		delay();	}	 	init_com( ) ; 	q_printf("\r\n devloping tracking on voyger"); 	 	for(i=0;i<=5;i++) 	{ 		c1_putchar ('1');    	c2_putchar ('2'); 	}    while(1)    {    	PollGSM();    	if(uart_int_flag==yes)// check for the UART recv. flag		{			recv_irq();      // call function which will display message on LCD if valid.			uart_int_flag=no;			}    }	return 0;}void PollGSM(void){	unsigned char count;	unsigned char temp;	unsigned char start_flag;	start_flag = no;	if((*U0LSR & 0x01))		{		    		count=0 ;    		do			{						  		if(*U0LSR & 0x01)		  		{					temp=*U0RBR;	// Return the read value					if(start_flag == no)					{						if(temp == 'R' || temp == ':' ) // validating the incoming call/sms start char.						//if(temp == ':' ) // validating the incoming call/sms start char.						{							recv_ch[count++]=temp;							uart_int_flag=yes;							start_flag = yes;							if(recv_ch[0]== ':')							{									//q_printf("\r\n :");														do								{									if(*U0LSR & 0x01)										recv_ch[count++]=*U0RBR;																			}while(recv_ch[count-1]!= '\r');								recv_ch[count-1]= 0;									sms_start = count-1;	//real starting position of sms txt. 										}													}						else							break;					}					else						recv_ch[count++]=*U0RBR;				 }		  						}while(recv_ch[count-1]!= '\r');			start_flag = no;		}}void recv_irq(){		unsigned char count;		switch(recv_ch[0]) 	{		case 'R':                   // for validating and indicating incomming call.				if(recv_ch[1] == 'I')				{					if(recv_ch[2] == 'N')					{						if(recv_ch[3] == 'G')							{							q_printf("%c",27); //0x1b-> esc							q_printf("\r\nBOMLA");							//for(count=0;count<2;count++)															//led_blink();						}					}				}				break;						case ':':				// for validating and indicating incomming sms.		q_printf(":1");					if(recv_ch[1] == ' ')				{					if(recv_ch[2] == '"')					{						//for(count=(sms_start+1) ; count<(sms_start+16);count++)							//for(count=(sms_start+1) ; count!= '\r' ;count++)						 //  q_printf("%c",recv_ch[count]);							 q_printf("\r\n%c",recv_ch[(sms_start+1)]);											if(recv_ch[(sms_start+1)] == 'G')						{														if(recv_ch[(sms_start+2)] == 'E')							{								if(recv_ch[(sms_start+3)] == 'T')								{									if(recv_ch[(sms_start+4)] == '/')									{										q_printf(":4");											sms_start = 0;										GetGPS();										}								}							}						}						else if(recv_ch[(sms_start+1)] == 'L')							{							if(recv_ch[(sms_start+2)] == 'O')							{								if(recv_ch[(sms_start+3)] == 'N')								{									if(recv_ch[(sms_start+4)] == '/')									{										q_printf(":n");											sms_start = 0;										SevenLedOn;										}								}								else if(recv_ch[(sms_start+3)] == 'F')								{									if(recv_ch[(sms_start+4)] == '/')									{										q_printf(":f");											sms_start = 0;										SevenLedOff;										}								}							}													}												//q_printf("AT+CNMA\r"); //positive acknoledment to the sms server.						//dela();					}				}									break;						default:											break;			}}void led_blink(void)	{	SevenLedOn;	delay();	SevenLedOff;	delay();}void dela(void){	unsigned long int i,d;	for(i=0;i<100;i++)	{		for(d=0;d<100;d++);	}}void GetGPS(void){	unsigned char StringGPS[75];	unsigned char count;	unsigned char temp;		count=0;	do	{						if(*U1LSR & 0x01)		 {			temp=*U1RBR;	//  read value			if(temp == 'R' ) // validating the incoming  char.			{				StringGPS[count++]=temp;				do				{					if(*U1LSR & 0x01)						StringGPS[count++]=*U1RBR;															}while(StringGPS[count-1]!= '\r');			}										else				break;			 }			  				}while(StringGPS[count]!= '\r');		//q_printf("\r\n stored");	//unsigned char FlagGPS=0;		//for(count=0;count != 0x0A; count++)	for(count=0;count <=70 ; count++)	{		q_printf("%c",StringGPS[count]);	}		//if(StringGPS[0]== '$')	{	//	if(StringGPS[1]== 'G')		{			//if(StringGPS[2]== 'P')			//if(StringGPS[0]== 'P')			{			//	if(StringGPS[3]== 'R')		/*	q_printf("\r\n%c",StringGPS[0]);			q_printf("\r\n%c",StringGPS[1]);			q_printf("\r\n%c",StringGPS[2]);			q_printf("\r\n%c",StringGPS[3]);			q_printf("\r\n%c",StringGPS[4]);			q_printf("\r\n%c",StringGPS[5]);			q_printf("\r\n%c",StringGPS[6]);			q_printf("\r\n%c",StringGPS[7]);			q_printf("\r\n%c",StringGPS[8]);			q_printf("\r\n%c",StringGPS[9]);*/						if(StringGPS[0]== 'R')				{			//		if(StringGPS[4]== 'M')				if(StringGPS[1]== 'M')					{						if(StringGPS[2]== 'C')						{							//for(count=0;count != 0x0A; count++)							for(count=0;count <= 70; count++)							{								q_printf("%c",StringGPS[count]);							}						}							}				}			}		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -