目前,我添加的按键程序如下:
void key_control(void)
{
key_s1 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_1);
key_s2 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_2);
key_s3 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_3);
{
key_s1 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_1);
key_s2 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_2);
key_s3 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_3);
if(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x) ==LOW)
{
usDelay(50);
if(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x)==LOW)
{
while(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x)==LOW);
return LOW;
}
else
return HIGH;
}
else
return HIGH;
{
usDelay(50);
if(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x)==LOW)
{
while(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x)==LOW);
return LOW;
}
else
return HIGH;
}
else
return HIGH;
while(1)
{
if(key_s1==LOW)
{
gMotorVars.SpeedRef_krpm = 0.8;
}
if(key_s2==LOW)
{
gMotorVars.SpeedRef_krpm = -0.8;
}
while(1)
{
if(key_s3==LOW)
{
gMotorVars.SpeedRef_krpm = 0.8;
usDelay(500);
gMotorVars.SpeedRef_krpm = -0.8;
usDelay(500);
}
}
{
if(key_s1==LOW)
{
gMotorVars.SpeedRef_krpm = 0.8;
}
if(key_s2==LOW)
{
gMotorVars.SpeedRef_krpm = -0.8;
}
while(1)
{
if(key_s3==LOW)
{
gMotorVars.SpeedRef_krpm = 0.8;
usDelay(500);
gMotorVars.SpeedRef_krpm = -0.8;
usDelay(500);
}
}
}
}
遇到的问题,如下:
1、无法用按键进行正反的切换
2、在CCS的监视窗口中,基准速度为1800ramp,这部分的程序在哪里?在main.h中,已经设为0,但在监视窗口中还是1800ramp,为什么?
rookiecalf:前面都是return,后面的程序执行不了。后面的while(1)也要考虑一下,是否能这么写?
目前,我添加的按键程序如下:
void key_control(void)
{
key_s1 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_1);
key_s2 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_2);
key_s3 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_3);
{
key_s1 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_1);
key_s2 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_2);
key_s3 = HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_3);
if(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x) ==LOW)
{
usDelay(50);
if(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x)==LOW)
{
while(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x)==LOW);
return LOW;
}
else
return HIGH;
}
else
return HIGH;
{
usDelay(50);
if(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x)==LOW)
{
while(HAL_readGpio(halHandle, (GPIO_Number_e)HAL_keyGpio_x)==LOW);
return LOW;
}
else
return HIGH;
}
else
return HIGH;
while(1)
{
if(key_s1==LOW)
{
gMotorVars.SpeedRef_krpm = 0.8;
}
if(key_s2==LOW)
{
gMotorVars.SpeedRef_krpm = -0.8;
}
while(1)
{
if(key_s3==LOW)
{
gMotorVars.SpeedRef_krpm = 0.8;
usDelay(500);
gMotorVars.SpeedRef_krpm = -0.8;
usDelay(500);
}
}
{
if(key_s1==LOW)
{
gMotorVars.SpeedRef_krpm = 0.8;
}
if(key_s2==LOW)
{
gMotorVars.SpeedRef_krpm = -0.8;
}
while(1)
{
if(key_s3==LOW)
{
gMotorVars.SpeedRef_krpm = 0.8;
usDelay(500);
gMotorVars.SpeedRef_krpm = -0.8;
usDelay(500);
}
}
}
}
遇到的问题,如下:
1、无法用按键进行正反的切换
2、在CCS的监视窗口中,基准速度为1800ramp,这部分的程序在哪里?在main.h中,已经设为0,但在监视窗口中还是1800ramp,为什么?
user6024771:
回复 rookiecalf:
我把return那部分删除了。while(1)是按键程序存在的循环,我把whike(1)删除,硬件还是没反应,这是为什么呢?