Method of Unsigned Char string in single chip microcomputer

xiaoxiao2021-03-05  20

In the microcontroller, common to the figures and characters, all use ITOA functions, C51 also have this function, but the 8051 RAM is very limited, so try to avoid using INT, usually Unsigned Char. It is still a bit waste when you need to convert to a string. Still self-reliance, write one, the code is as follows:

Typedef unsigned char BYTE; BYTE * BYTETOSTR (Byte N) {byte Str [4]; Byte * PSTR; PSTR = Str; if (n> 99) {* PSTR = N / 100; N% = 100; * PSTR = '0'; PSTR ; * pstr = N / 10; N% = 10; * pstr = '0'; PSTR ;} if (n> 9) {* pstr = n / 10; n% = 10; * PSTR = '0'; PSTR ;} if (n <10) {* pstr = n '0'; PSTR ;} * pstr = 0; Return Str;}

With 5Byte memory, I don't know if I'm streamlined, first use it! String turn Unsigned char must be reversed first down to '0', but to check if it is less than or equal to 255. Waiting for it, put it up.

转载请注明原文地址:https://www.9cbs.com/read-32751.html

New Post(0)