pawan kumar
Member level 4
I have a problem with arrays.I am interfacing LPC2148 with GPS module using both uarts.
I have an array of 70 elements named info[70]. I want another array, lat[9] to store only the first nine elements (as of now) and send them to the UART0.
the logic I ve used is as follows:
void latitude()
{
int i;
i=0;
for(i=0;i<9;i++) //this gets executed 9 times
lat=info;
}
but there is a strange issue : on printing the lat[] in hyperterminal, info[] is also printed along.pls see attached image
I have attached the code. please look through.
I am also attaching a screenshot of hyperterminal.
Please tell me where I am wrong.
Pawan
I have an array of 70 elements named info[70]. I want another array, lat[9] to store only the first nine elements (as of now) and send them to the UART0.
the logic I ve used is as follows:
void latitude()
{
int i;
i=0;
for(i=0;i<9;i++) //this gets executed 9 times
lat=info;
}
but there is a strange issue : on printing the lat[] in hyperterminal, info[] is also printed along.pls see attached image
I have attached the code. please look through.
Code:
#include<lpc214x.h>
static unsigned char lat[9];
static unsigned char info[70];
void init() //initializes both UARTS @9600,8bit, no pairity,1 stopbit
{
U0LCR=0x83;
U0DLL=0x61;
U0DLM=0x00;
U0LCR=0x03;
U1LCR=0x83;
U1DLL=0x61;
U1DLM=0x00;
U1LCR=0x03;
}
void senduart0(unsigned char a) //sends a byte through UART0
{
U0THR=a;
while(U0LSR!=0x60);
}
unsigned char recuart1() //recieves a byte from UART1
{
unsigned char p;
while ((U1LSR&0x01)!=1);
p=U1RBR;
return p;
}
void sendstring(const unsigned char *str) //A function to send a string on UART0
{
while(1)
{
if( *str == '\0' ) break;
senduart0(*str++);
}
}
void recgps() //Receive the 70 chrs to fill up info[]
{
int count=0;
for(count=0;count<70;count++)
{
info[count]=recuart1();
}
}
void latitude() //to extract the latitude coordinates
{
int i;
i=0;
for(i=0;i<9;i++)
lat[i]=info[i];
}
int main()
{
PINSEL0=0x00050005;
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000000;
init();
recgps();
latitude();
sendstring("latitude\n\r");
sendstring(lat);
sendstring("testing\r\n");
}
I am also attaching a screenshot of hyperterminal.
Please tell me where I am wrong.
Pawan
Attachments
Last edited: