3619 views|9 replies

3

Posts

0

Resources
The OP
 

Guys, please help me, I've been stuck for 3 days and can't figure it out [Copy link]

Why is it that in Figure 2, the light matrix can be lit up using the sub-function format, but in Figure 1 the format only lights up for a moment and never lights up again?
This post is from 51mcu

Latest reply

You can use the second method to write in the future and pass the value into a temporary variable. or unsigned char temp=0x80; for(i = 0; i < 8; i++) { temp=0x80; if(TRUE == hang & temp) { /* Corresponding operation*/ } else { /* Corresponding operation*/ } temp >>= 1; /* Similarly, perform bit judgment from high to low */ }   Details Published on 2021-12-30 23:26
 

3

Posts

0

Resources
2
 

This post is from 51mcu
 
 
 

1412

Posts

3

Resources
3
 

You copied the code into the post, the photo is not clear

This post is from 51mcu
 
Personal signature

没有什么不可以,我就是我,不一样的烟火! 

 
 

4

Posts

0

Resources
4
 

Sorry, I don't see what the problem is. If you solve it, please give me a kick.

This post is from 51mcu
 
 
 

6062

Posts

4

Resources
5
 

hang =hang<<1;

Changes the contents of the hang[] array.

To:

dat=hang[b]; //后面内容同右边试下。

for(i=0;i<8;i++)

{

  ....

}

A function that takes a variable as a parameter will not change the contents of the parameter. The contents of the parameter can only be changed if it takes a pointer or array as a parameter.

That dat=hang ; can't be changed, so I changed it below:

This post is from 51mcu
 
 
 

6062

Posts

4

Resources
6
 

dat=hang[b];

This post is from 51mcu
 
 
 

6742

Posts

2

Resources
7
 

The above answer is correct. In Figure 1, the [hang] array has been modified, and in Figure 2, an intermediate variable dat is used, and the [hang] array has not been modified.

This post is from 51mcu
 
 
 

4005

Posts

0

Resources
8
 

My understanding is that it is optimized. The compiler thinks that hang[b]=hang[b]<<1; is unnecessary to execute. You can check the assembly code to verify it.

In addition, for (i = 0; i < 8... and then look up 8421 in the table is a bit cumbersome, so it is smoother to change it to for (i = 1; i! = 0; i <<= 1)

This post is from 51mcu
 
 
 

4

Posts

0

Resources
9
 

Absolutely, after reading the above, I realized the original poster's question:

Can only be output once.

At this point, the problem is indeed as described above. I always thought that this operation could output data, which is quite different from what the poster asked.

After the first output, each byte of data is shifted right by 8 bits. Generally speaking, right or left shifts (unsigned numbers) are filled with 0. That is to say, after the first output, the host's data has all become 0, which is why there is no output.

This post is from 51mcu
 
 
 

4

Posts

0

Resources
10
 

You can use the second method to write in the future and pass the value into a temporary variable.

or

unsigned char temp=0x80;

for(i = 0; i < 8; i++) {

temp=0x80;

if(TRUE == hang[i] & temp) {

/* Corresponding operation*/

} else {

/* Corresponding operation*/

}

temp >>= 1;

/* Similarly, perform bit judgment from high to low */

}

This post is from 51mcu
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list