01-02-2012 12:31 AM
I am using Spartan-6 LX9 board and running the code of decimal multiplication,which i have attached already. In this i am entering the value of a and b from keyboard and giving the result of value c on hyperterminal.But this exactly not doing the multiplication correctly.
so kindly give me idea or provide the sample code.....
01-03-2012 07:47 AM
First off, this is more a general coding question, not really specific to the Spartan-6 LX9 MicroBoard. Thus this forum
may not be the right spot for this question.
The problem may be that you are reading ASCII bytes from the UART. Reading from UARTs is always a challenging.
See an ASCII table. So you have a couple of options. If only multiplying single digit numbers, you could
just subtract 48 from the value to give you a decimal number. Else you can use scanf to read in a decimal number:
Try that and see if that helps.
01-04-2012 01:19 PM
Jayson is correct and your code is producing the correct output even though it is not the output you might expect.
The input being read from the terminal via XUartLite_RecvByte() will be encoded in ASCII and you will need to convert to the decimal equivalent before performing the math operation. Likewise, the multiplication product will need to be encoded back into ASCII, one digit at a time and sent out the the XUartLite_SendByte (most significant digit first) which can be a little tricky. If you can afford to link in xil_printf() function, that works very well for most output formatting and will save you some time.
I have come up with a quick proof of concept solution for what I think you are trying to accomplish (it really was thrown together quickly and you may come up with a much better solution). Try this on your end and see if this works better for you.