📄 p8.c
字号:
#include <LPC21xx.H>
#include "stdio.h"
#define baudrate_uart1 0x0f //@115200;SYS_CLK/16*2*COUNT=0x0f
#define sender_no "+919876338933"
#define CR 0x0D
#define LF 0x0A
void gprs_commands(void);
void delay(void);
void getch (char ch);
char *gps_strchr(char *src, char ch);
int gps_strncmp( char *s1, char *s2, unsigned char length);
int gps_strcpy1(unsigned char *s1,char *s2);
const char *uart1Puts(const char *string);
int uart1Putch(int ch);
void uart1_interrupt(void);
void uart1_initialize(void);
void check_response(char *sentence);
void instwrt(void);
void datawrt(void);
void delay(void);
char at_get_running;
char at_get_buff[160],*at_get_idx;
int route_table_length;
char sms_location_sim;
char valid_sms_flag=0;
char response_ok=0;
int main()
{
VPBDIV=2;
IODIR0=IODIR0|0xffff;
while(1)
{
IOSET0|=0x03800;//P0=0x38;
IOCLR0|=~(0x03800);//
instwrt();
delay();
delay();
IOSET0|=0x00e00;//
IOCLR0|=~(0x00e00);//
instwrt();
delay();
delay();
IOSET0|=0x00100;//
IOCLR0|=~(0x00100);//
instwrt();
delay();
delay();
IOSET0|=0x00600;//
IOCLR0|=~(0x00600);//
instwrt();
delay();
delay();
IOSET0|=0x08300;//
IOCLR0|=~(0x08300);//
instwrt();
delay();
delay();
IOSET0|=0x04100;//
IOCLR0|=~(0x04100);
datawrt();
}
}
/*
* FUNCTION : UART1 interrupt
* PURPOSE : for data capturig at baudrate 115.2kbps
* INPUTS : receive interrupt
* RETURNS : none
*/
void uart(void)__irq
{
char status,temp;
if((U0LSR & 0x01)==0x01)
{
status=U0RBR;
getch(status);
}
VICVectAddr=0;
temp=U0IIR;
}
/*****************************************************************************
* FUNCTION : get_ch
* PURPOSE : gets the ch from GPRS and findout gprs responses and route table information
* INPUTS : passing ch receive from uart1 receive interrupt
* RETURNS : none
*****************************************************************************/
void getch (char ch)
{
static char array1[160];
static char ch_count1=0;
if( ch_count1<150)
{
array1[ch_count1]=ch;
ch_count1++;
}
else
ch_count1=0;
if((ch ==LF)&&(!at_get_running)) //start of response
{
at_get_running = 1; //sentence being recieved flag true
at_get_idx = at_get_buff;
}
if(at_get_running)
{
if((ch== LF)&&(at_get_idx == (at_get_buff+1))) //start of response received
{
at_get_idx = at_get_buff;
}
else
if((ch == CR)&&(at_get_idx > (at_get_buff+1))) //end of response
{
at_get_running = 0;
*at_get_idx = 0;
check_response( at_get_buff);
}
else
{
if(ch!=LF)
*at_get_idx++ = ch; //update buffer with response on uart
}
}
}
/*****************************************************************************
* FUNCTION : int check_response(void)
* PURPOSE : check AT response type from response strored in buffer and
* return appropriate value according to type
* INPUTS : sentence: address of buffer
* RETURNS :1 on success 0 on error/busy
*****************************************************************************/
void check_response(char *sentence)
{
if(gps_strncmp(sentence, "OK", 2) == 0)
response_ok=1; //correctly send cmd (OK)
}
/*****************************************************************************
* FUNCTION : gps_strchr
* PURPOSE : Searches for the character and returns the location
*
* INPUTS : char *src - source string
* char ch - character to be searched
* RETURNS : address location of character in string
*****************************************************************************/
char *gps_strchr(char *src, char ch)
{
char *ptr;
while((*src != ch)&&(*src!=0))
{
src++;
}
if( *src==0)
return NULL;
ptr = src;
return ptr;
}
/********************************************copy string*********************/
int gps_strcpy1(unsigned char *s1,char *s2)
{
int lenght = 0;
while((*s1++ = *s2++)!=0)
lenght++;
return lenght;
}
/*****************************************************************************
* FUNCTION : gps_strncmp
* PURPOSE : Compare two strings for given nos of char
*
* INPUTS : char *s1 - string to be compared
* char *s2 - string with which to compaere with
* length - no of characters to compare
* RETURNS : integer value 0 if match, 1 if not match
*****************************************************************************/
int gps_strncmp( char *s1, char *s2, unsigned char length)
{
unsigned char count,match;
match = 0;
while(*s1 != 0)
{
if(*s1 == *s2)
{
for(count = 0;count < length ;count++)
{
if(*s1++ != *s2++)
{
match = 0;
break;
}
match = 1;
}
}
else
s1++;
}
if(match)
return 0;
else
return 1;
}
/******************************************************************************
* Function Name: uart1Puts()
*
* Description:
* This function writes a NULL terminated 'string' to the UART output
* queue, returning a pointer to the next character to be written.
*
* Calling Sequence:
* address of the string
*
* Returns:
* a pointer to the next character to be written
* (\0 if full string is written)
*****************************************************************************/
const char *uart1Puts(const char *string)
{
register char ch;
while ((ch = *string) && (uart1Putch(ch) >= 0))
string++;
return string;
}
int uart1Putch(int ch)
{
U0THR=(unsigned char)ch;
while(!(U0LSR & 0x40)){}
return (unsigned char)ch;
}
/*****************************************************************/
void uart1_interrupt(void)
{
VICIntSelect=0x0; //Ifq=1,irq=0 select
VICIntEnable |=0x40; //enable uart VIC-channal(pg-86) 32 bit register bit no=channel
VICVectCntl0 |=0x26; // 2 is fixed,6 is uart chennal,0 is slot
VICVectAddr0=(unsigned long)uart;
}
/***************UART1 INITIALIZE************************************/
void uart1_initialize(void)
{
PINSEL0 |=0x05; //set uart0 pin no P0.08,9
U0IER=0x01; // receive data inerrupt enable MUST BE first declared
U0FCR=0x7; //Enable FIFO,clear Rx,Tx
U0LCR=0x83; //DLAB set, word length,parity bit
U0DLL=baudrate_uart1; //4800 baud rate count LSB 60Mhz/16x2xbaud
U0DLM=0x00; //baud rate count MSB
U0LCR=0x03; //clear DLAB at last declare
}
void instwrt(void)
{
IOCLR0|=0x00001;// RS=0;
IOSET0|=0x00002; //E=1;
delay();
IOCLR0|=0x00002;// E=0;
}
void datawrt(void)
{
IOSET0|=0x00001;// RS=1;
IOSET0|=0x00002; //E=1;
delay();
IOCLR0|=0x00002; //E=0;
}
void delay(void)
{
unsigned int i;
for(i=0;i<=30000;i++)
{}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -