rs232 read & write

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
ananth.antony
Posts: 46
Joined: 21 Jan 2011 09:37
Location: United Arab emirates

rs232 read & write

#1 Post by ananth.antony » 08 Jul 2011 19:10

Hi All

I have a problem in the below code.

Code: Select all

while (1) {

 if (UART1_Data_Ready()) {
 speed = UART1_Read();

 LongIntToStrWithZeros(speed, txt);
 Lcd_Out(2,6,txt);


         if (UART1_Tx_Idle()==1) {
           
           UART1_Write(speed);
          }

          delay_ms(10);
}
From MIKROC USART terminal if i send multi digit decimal(ex.555) sending and receiving is okay. But on the lcd it shows only the ASCII value of 5(ie.53)

i need all digits to be received to operate the code correctly.

Please someone help me.

Regards

Ananth

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

Re: rs232 read & write

#2 Post by drdoug » 11 Jul 2011 02:26

You are writing the unsigned short in the same place on the LCD. I think you want to store all your received values in an array and then write it to the LCD.
also you could increment the LCD using LCD_Chr or similar.

ananth.antony
Posts: 46
Joined: 21 Jan 2011 09:37
Location: United Arab emirates

Re: rs232 read & write

#3 Post by ananth.antony » 11 Jul 2011 11:39

Hi

I have modified the code as below. Still i have problem. Can you please assist me and give a working example.

Code: Select all


int k;
int i;
char cnt[];
char txt[7];

while (1) {

if (UART1_Data_Ready()) {
for (i=0; i<3; i++) {
cnt[i] = Usart_Read();
}

IntToStr(cnt, txt);
for (k=0; k<3; k++) {
Lcd_Chr(2,k,txt);
}



         if (UART1_Tx_Idle()==1) {
           
           UART1_Write(cnt);
          }

          delay_ms(10);
}
Regards

Ananth

Lord Lucan
Posts: 60
Joined: 09 Dec 2010 14:41

Re: rs232 read & write

#4 Post by Lord Lucan » 13 Jul 2011 12:19

Have a look at your code...

Code: Select all

IntToStr(cnt, txt);
for (k=0; k<3; k++) {
Lcd_Chr(2,k,txt);
}
cnt is an array - not and integer, you have to use ByteToStr and access each element of the array in turn, something like this...

Code: Select all


for (k=0; k<3; k++) {
ByteToStr(cnt[k], txt);
Lcd_Chr(2,k,txt);
}

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

Re: rs232 read & write

#5 Post by drdoug » 13 Jul 2011 13:21

And use LCD_Chr_Cp() so you can increment on the LCD and not write over the previous text.

ananth.antony
Posts: 46
Joined: 21 Jan 2011 09:37
Location: United Arab emirates

Re: rs232 read & write

#6 Post by ananth.antony » 14 Jul 2011 22:08

Hi

Still have problem. i can see some unknown characters on LCD. Please advise me.

Code: Select all

int i;
int k;
char cn[4];
char tab[4];

while (1)  {
 if (UART1_Data_Ready()==1) {
for (i=0; i<3; i++) {
cn[i] = UART1_Read();
}
delay_ms(10);
for (k=0; k<3; k++) {
ByteToStr(cn, tab);
Lcd_Chr_CP(tab);

}
}
Regards

Ananth

Post Reply

Return to “mikroC PRO for PIC General”