多个端口要完成同样的功能,
可不可以把端口当做函数参数?
比如把下面的两个函数合并为一个函数
void offStep_0()
{
char j = 0;
unsigned char state= 0x0; // 全亮
unsigned char t = 0x01; //
for(j = 0; j < 8; ++j)
{
state = state | t;
P0 = state;
delay(TimeDelay);
t <<= 1;
}
}
void offStep_1()
{
char j = 0;
unsigned char state= 0x0; // 全亮
unsigned char t = 0x01; //
for(j = 0; j < 8; ++j)
{
state = state | t;
P1 = state;
delay(TimeDelay);
t <<= 1;
}
}
------最佳解决方案--------------------
可以,最简单的方法是typedef一个枚举类型,然后函数里switch就行了
------其他解决方案--------------------
可以,最简单的方法是typedef一个枚举类型,然后函数里switch就行
------其他解决方案--------------------
这个和switch case一样
------其他解决方案--------------------
嗯 有理
------其他解决方案--------------------
void offStep_01()
{
char j = 0;
unsigned char state= 0x0; // 全亮
unsigned char t = 0x01; //
for(j = 0; j < 8; ++j)
{
state = state
------其他解决方案--------------------
t;
P0 = state;
P1 = state;
delay(TimeDelay);
t <<= 1;
}
}
P0 = state;
P1 = state;
------其他解决方案--------------------
P0 , P1 是 寄存器地址。
------其他解决方案--------------------