Page 1 of 1
can I read two digit number using UART1_Read()?
Posted: 27 Mar 2024 13:55
by kumar123
Hi,
I have a doubt, can I read two digit number using UART1_Read() function, number can be any two digit number.
If yes then how ?
Any suggestions will be appreciated!
Reagrds,
kumar
Re: can I read two digit number using UART1_Read()?
Posted: 07 Apr 2024 09:30
by IvanJeremic
Hi,
Uart1_read can read two digit numbers, you can see it used in multiple examples for click boards where it reads a lot larger numbers.
You can also find examples for using UART without click boards where you can read larger numbers.
Regards,
Ivan.
Re: can I read two digit number using UART1_Read()?
Posted: 07 Apr 2024 19:35
by paulfjujo
hello,
what is your definition of a digit ?
Uart1_Read ( a_byte);
a value on 2 digits : ex: 65
MSB=6 LSB=5
BCD coded as
0110 00101
On other side : how are send theses 2 digits ?
in binary format 0100 0001
ascii format "65"
BCD format 0110 00101
Re: can I read two digit number using UART1_Read()?
Posted: 08 Apr 2024 05:15
by kumar123
Hello IvanJeremic,
Could you provide any example or link of that query from where I can get something
Regards,
Kumar
Re: can I read two digit number using UART1_Read()?
Posted: 08 Apr 2024 05:20
by kumar123
Hello paulfjujo,
I am sending these number in ascii formate.
for example:
Code: Select all
unsigned int number;
number = UART1_Read(); //input = 65
UART1_Write(number); //output = 6
Lets say if I want to read 65 from the above code It will only read 6
Regards,
Kumar
Re: can I read two digit number using UART1_Read()?
Posted: 08 Apr 2024 19:34
by paulfjujo
try this
char c:
int value;
int i=0;
.. somme init here....
do
{
i=0;
if ( (UART1_Data_Ready())&& (i==0))
{
c=UART1_Read() ;
UART1_Write (c); // echo '6' en ascii
value=( c-48)*10; // value=6*10=60
i++;
}
if ((UART1_Data_Ready()) && (i==1))
{
c=UART1_Read() ;
UART1_Write (c); // echo '5' ascii
value= value +( c-48); // value = 60 + 5 = 65
i++;
}
}
while(i<2);
at exit , value=65 ..if you send "65" by keyboard terminal !
Re: can I read two digit number using UART1_Read()?
Posted: 16 Apr 2024 10:59
by kumar123
Hello paulfjujo,
Your code is working fine. but if print number in next line it will not work.
Code: Select all
char c:
int value;
int i=0;
.. somme init here....
do
{
i=0;
if ( (UART1_Data_Ready())&& (i==0))
{
c=UART1_Read() ;
UART1_Write (c); // echo '6' en ascii
value=( c-48)*10; // value=6*10=60
i++;
}
if ((UART1_Data_Ready()) && (i==1))
{
c=UART1_Read() ;
UART1_Write (c); // echo '5' ascii
value= value +( c-48); // value = 60 + 5 = 65
i++;
}
}
while(i<2);
/*
* The output of the above code shoud be like this :
* 65
* 23
* 78
* 90
* but your code is giving output in one line 65 23 78 90 etc...
*/
Regards,
Kumar
Re: can I read two digit number using UART1_Read()?
Posted: 17 Apr 2024 15:04
by paulfjujo
hello,
kumar123 wrote: ↑16 Apr 2024 10:59
.....Your code is working fine. but if print number in next line it will not work.
Code: Select all
char c:
int value;
int i=0;
.. somme init here....
do
{
i=0;
if ( (UART1_Data_Ready())&& (i==0))
{
c=UART1_Read() ;
UART1_Write (c); // echo '6' en ascii
value=( c-48)*10; // value=6*10=60
i++;
}
if ((UART1_Data_Ready()) && (i==1))
{
c=UART1_Read() ;
UART1_Write (c); // echo '5' ascii
value= value +( c-48); // value = 60 + 5 = 65
i++;
}
// add here LF +CR => to change to the begining of next line
UART1_Write (10);
UART1_Write (13);
}
while(i<2);