收到的价值“R”
蓄能器“X”
X = 0
R =“2”(0x32)
X = X +(R - 0x30)[当前值2]
X = X * 10
R =“0”(0x30)
X = X +(R - 0x30)[当前值20]
X = X * 10
R =“1”(0x31)
X = X +(R - 0x30)[当前值201]
X = X * 10
R =“7”(0x37)
X = X +(R - 0x30)[当前值2017]
每个阶段对X的处理是相同的,因此您可以反复重复使用相同的硬件。
乘以10可以通过DSP切片或使用移位和加法(X 以下为原文
Assuming you get it in as a stream (eg. over UART) then you can handle the numbers sequentially:
Received value "R"Accumulator "X"X = 0R = "2" (0x32)X = X + (R - 0x30) [current value 2]X = X * 10R = "0" (0x30)X = X + (R - 0x30) [current value 20]X = X * 10R = "1" (0x31)X = X + (R - 0x30) [current value 201]X = X * 10R = "7" (0x37)X = X + (R - 0x30) [current value 2017]The processing on X at each stage is identical, so you can re-use the same hardware over and over again. The multiply by 10 can be done either with a DSP slice or with a shift-and-add (X << 3) + (X << 1).
View solution in original post


淘帖
3262

/9 


