The numerical value writing method of 51MCU is introduced

The numerical value writing method of 51MCU is introduced

tenco 2019-03-23

1. In MCU, the calculation is carried out in binary form.

2. In programming, we usually use decimal numerical form and hexadecimal numerical form, such as 52,0 xfe;

3. The size of the value depends on the type of data.

4. Commonly used are "unsigned int" and "unsigned char".

The range of "unsigned char" is "0-255", which corresponds to the maximum 8-bit (0xff) of the MCU port.

The range of "unsigned int" is "0-65535", which corresponds to "0xffff".


5. Numerical writing:

In 51 MCU, the values written can be decimal and hexadecimal, but not binary.

Such as: P1 = 4;P1 = 0 x04;

When writing the statement "P1=4;"when

P1 ^ 0 - P1 ^ 7 level of "0010 0000"

When writing the statement "P1=65;"when

P1 ^ 0 - P1 ^ 7 level of "1000 0010";The hex code of 65 is: 0x41

As can be seen from the above two values, the low order of the port corresponds to the low order of the value, and the high order of the port corresponds to the high order of the value.

6 in the use of digital display Numbers, is a digit number, a digit write, such as 26, write 2 first, then write 6.

Using digital tube to write 2, for example: chose digital tube broken abcdefgdp respectively from P1 ^ 0, P1 ^ 1...P1 ^ 7;

To display 2, abcdefgdp is required: 1101 1010

It would be wrong to write P1=0xda according to the corresponding port.

The binary is also the high order before the low order, so the port should also be low to low and high to high when writing data, so "1101 1010" should be

"0101, 1011"

So the hexadecimal code of digital tube display 2 is "P1=0x5b"

Similarly, the hex code for "0-9" is "0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f"

TENCO-TECH