Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] How to store data from Usart to array

Status
Not open for further replies.

AndroPic

Newbie level 3
Newbie level 3
Joined
Oct 19, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
21
Hi Guys

I need a help to parse received data from usart. I use PIC16F877A I want to store data that i receive from usart to array. this is my code:

void main()
{
char data[5];
int i;
Usart_Init(9600);
delay_ms(100);
while(1)
{

if(Usart_Data_Ready())
{
for(i=0;i<5;i++)
{
data=Usart_Read();
}
Usart_Write(data[0]); //
Usart_Write(data[1]); //
Usart_Write(data[2]); //check all data
Usart_Write(data[3]); //
Usart_Write(data[4]); //
}
}
}


but I always got wrong data when i execute it. Example when I send 123 from usart terminal in Mikro C, I will get 1111123333. The when I send 12345, also I will get 1111123333. could someone tell how to store data that I received via usart to array

Thanks Before.
 

Don't send data as single characters.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
unsigned char uartData[40] = "";
 
void main()
{
    unsigned int i = 0;
    TRISC = TRISC | 0x80;
    PORTC = 0x00;
    
    Usart_Init(9600);
    delay_ms(100);
 
    while(1)
    {
 
        if(UART1_Data_Ready())  //Send data as string from PC and terminate data with CR LF
            Usart_Read_Text(uartData, "\r\n", 40);
            
        UART1_Write_Text(uartData);
        
    }
}

 

It doesn't work jayanth, I just got error message.

thanks before
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top