本帖最后由 18903210028 于 2017-8-5 21:49 编辑
这是一个通过采集AD口然后点亮LED灯的实验,是新唐的M451库里带的程序。我今天单步仿真发现如果Number的值是2 i=0或1时,2在和后边的 & 0x01按位与。应该不是真,但还是会执行 *ptrLED = 0; //LED ON这条语句。还是会有两个灯亮,LED1和LED2。难道这个掩码不参与判断吗
while(1)
{
//Get Volume Knob Data 获取音量旋钮数据
Volume = Get_ADC_Knob(); //Volume Range: 0 ~ 4095
printf("%d\n", Volume);
//Use Volume Control to LED Flash Speed
// Write_LED_Color_Flash(Volume);
//Show Volume scale on LED Bar
LED_Value = Volume * (12 + 1) / 4096; //LED Bar Count Range: 0 ~ 12
Write_LED_Bar(LED_Value);
}
#define _LED_Bar_Count 7
#define _LED1 PB2
#define _LED2 PB3
#define _LED3 PC3
#define _LED4 PC2
#define _LED5 PA9
#define _LED6 PB1
#define _LED7 PC7
void Write_LED_Bar(uint32_t Number)
{
uint32_t i;
volatile uint32_t *ptrLED[_LED_Bar_Count] = {&_LED1, &_LED2, &_LED3, &_LED4, &_LED5, &_LED6, &_LED7};
for(i = 0; i < _LED_Bar_Count; i++)
{
if((Number > i)& 0x01 )
*ptrLED = 0; //LED ON
else
*ptrLED = 1; //LED OFF
}
}
|