int main(void)
{GPIO_WriteBit(GPIOD,GPIO_Pin_0,Bit_RESET);
GPIO_WriteBit(GPIOD,GPIO_Pin_1,Bit_SET);
GPIO_WriteBit(GPIOD,GPIO_Pin_2,Bit_SET);
GPIO_WriteBit(GPIOD,GPIO_Pin_3,Bit_SET);
while(1)
{
if(flag==1)
{
Toggle_Num++;
switch(Toggle_Num)
{
case 1: case 3: case 5: case 7: case 9: case 11: case 13: case 15:
break;
case 2:
case 6:
case 10:
case 14:
IO_Toggle(GPIOD,GPIO_Pin_0|GPIO_Pin_1);
break;
case 4:
case 12:
IO_Toggle(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2);
break;
case 8:
case 16:
IO_Toggle(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3);
Toggle_Num =0;
break;
}
我这样设定不应该是PD0和PD1为互补方波且频率相同,PD2和PD3分别为PD1频率的1/2和1/4吗?然而我用示波器测试,情况并不是这样,PD0和PD1完全一样,PD2和PD3变成了一条电平,哪位大佬能看看是我哪里设置的有问题吗?GPIO_Mode = GPIO_Mode_Out_PP; //éèa£aêè£ê éóóú£aμ1μêè GPIO_Init(GPIOD, &GPIO_InitStructure);[ /backcolor] GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //éèa£aêè£ê GPIO_Init(GPIOD, &GPIO_InitStructure); /backcolor] I should set PD0 and PD1 as complementary square waves with the same frequency, and PD2 and Are the frequencies of PD0 and PD1 the same, and PD2 and PD3 the same, respectively? I tested it with an oscilloscope, but it was not the case. PD0 and PD1 were exactly the same, and PD2 and PD3 became one level. Can anyone tell me what is going on? Is there something wrong with my settings?GPIO_Mode = GPIO_Mode_Out_PP; //éèa£aêè£ê éóóú£aμ1μêè GPIO_Init(GPIOD, &GPIO_InitStructure);[ /backcolor] [backcolor =rgb(209, 217, 226)] GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //éèa£aêè£ê GPIO_Init(GPIOD, &GPIO_InitStructure); /backcolor] I should set PD0 and PD1 as complementary square waves with the same frequency, and PD2 and Are the frequencies of PD0 and PD1 the same, and PD2 and PD3 the same, respectively? I tested it with an oscilloscope, but it was not the case. PD0 and PD1 were exactly the same, and PD2 and PD3 became one level. Can anyone tell me what is going on? Is there something wrong with my settings?
I thought about it for a long time and really didn't know what the problem was. I shielded the switching state in the while loop, PD0 was low and PD1 was high, but the switching state in the while loop was wrong, the two were exactly the same.
I cannot flip multiple IO ports at the same time. I can flip IO ports one by one. Maybe the flip function I set cannot flip multiple ports at a time. I don't know why.
This post was last edited by huo_hu on 2018-8-9 13:11 I see, it's the 1- that's causing the trouble, 1-1=0 1-0=1 Other situations don't hold, think about it again