当前位置: 代码迷 >> 单片机 >> 可否把端口当做函数参数
  详细解决方案

可否把端口当做函数参数

热度:88   发布时间:2016-04-28 15:38:39.0
可不可以把端口当做函数参数?
多个端口要完成同样的功能,
可不可以把端口当做函数参数?
比如把下面的两个函数合并为一个函数

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就行
------解决方案--------------------
typedef一个枚举类型,然后函数里switch
  相关解决方案