📄 f04ef5b8dadb001c145ca6ba85d01f2c
字号:
/************************************************************************ 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 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) { //========for transmission===// //c2_putchar(c1_getchar()); //for(i=0 ; i<10 ; i++) //for(i=0;i!= '\0';i++) //buf_str[i] = c1_getchar(); //c2_putstr(buf_str); //--------------working 0-9 //delay(); //c2_putchar('\n'); //for(i=0; i<=9 ; i++) //{ // c2_putchar('0'+i); //} ////========for RECEIVER===// //c1_putchar('1'); c2_putchar('2'); 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; } //------working //for(i=0 ; i<5 ; i++) //buf_str[i] = c2_getchar(); //c1_putstr(buf_str); ///////////////////////////////////////////// } return 0;}void PollGSM(void){ unsigned char count; unsigned char temp; unsigned char start_flag; start_flag = no; //if((*U0LSR & 0x01)) // polling for the data available on UART recv. //while(!(*U0LSR & 0x01)); if((*U0LSR & 0x01)) { q_printf("\r\n POLL IF"); 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. { q_printf("\r\n R || :"); recv_ch[count++]=temp; uart_int_flag=yes; start_flag = yes; if(recv_ch[0]== ':') { 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; // break; }}void recv_irq(){ unsigned char count; q_printf("\r\n IRQ"); 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\nRING"); for(count=0;count<2;count++) led_blink(); } } } break; case ':': // for validating and indicating incomming sms. 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]); sms_start = 0; for(count=0;count<2;count++) led_blink(); 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++); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -