"); //-->
/******************************************************************************
函数:void IOInitial(unsigned char ionum,unsigned char iomod)
时间:2007.11.05
编者:zhangfazhong
状态:已测通过
******************************************************************************/
void IOInitial(unsigned char ionum,unsigned char iomod)
/*ionum io口 iomod io模式
//0 1 2 3 M0 M1 功能
0 0 准双向口
0 1 推挽输出
1 0 仅为输入
1 1 开漏极输出
*/
{
switch (ionum)
{
case 0:
switch (iomod)
{
case 0x00:
P0M0 = 0x00;
P0M1 = 0x00;
break;
case 0x01:
P0M0 = 0x00;
P0M1 = 0xff;
break;
case 0x10:
P0M0 = 0xff;
P0M1 = 0x00;
break;
case 0x11:
P0M0 = 0xff;
P0M1 = 0xff;
break;
default: break;
}
break;
case 1:
switch (iomod)
{
case 0x00:
P1M0 = 0x00;
P1M1 = 0x00;
break;
case 0x01:
P1M0 = 0x00;
P1M1 = 0xff;
break;
case 0x10:
P1M0 = 0xff;
P1M1 = 0x00;
break;
case 0x11:
P1M0 = 0xff;
P1M1 = 0xff;
break;
default: break;
}
break;
case 2:
switch (iomod)
{
case 0x00:
P2M0 = 0x00;
P2M1 = 0x00;
break;
case 0x01:
P2M0 = 0x00;
P2M1 = 0xff;
break;
case 0x10:
P2M0 = 0xff;
P2M1 = 0x00;
break;
case 0x11:
P2M0 = 0xff;
P2M1 = 0xff;
break;
default: break;
}
break;
case 3:
switch (iomod)
{
case 0x00:
P3M0 = 0x00;
P3M1 = 0x00;
break;
case 0x01:
P3M0 = 0x00;
P3M1 = 0xff;
break;
case 0x10:
P3M0 = 0xff;
P3M1 = 0x00;
break;
case 0x11:
P3M0 = 0xff;
P3M1 = 0xff;
break;
default: break;
}
break;
default: break;
}
}
/******************************************************************************
函数:PortBitSet(unsigned char ionum,unsigned char bitnum,unsigned char bitmod)
日期:2007.11.04
编者:zhangfazhong
状态:已测通过
******************************************************************************/
void PortBitSet(unsigned char ionum,unsigned char bitnum,unsigned char bitmod)
/*
ionum bitnum bitmod
0 0 00
01
10
11
1 00
01
10
11
*
*
*
*/
{
switch (ionum)
{
///////////////////////////////////////////////////////////////////////////
case 0: //P0口
switch (bitnum)
{
case 0: //0位
switch (bitmod)
{
case 0x00:
P0M0 = P0M0 & 0xfe;
P0M1 = P0M1 & 0xfe;
break;
case 0x01:
P0M0 = P0M0 & 0xfe;
P0M1 = P0M1 | 0x01;
break;
case 0x10:
P0M0 = P0M0 | 0x01;
P0M1 = P0M1 & 0xfe;
break;
case 0x11:
P0M0 = P0M0 | 0x01;
P0M1 = P0M1 | 0x01;
break;
default : break;
}
break;
case 1:
switch (bitmod)
{
case 0x00:
P0M0 = P0M0 & 0xfd;
P0M1 = P0M1 & 0xfd;
break;
case 0x01:
P0M0 = P0M0 & 0xfd;
P0M1 = P0M1 | 0x02;
break;
case 0x10:
P0M0 = P0M0 | 0x02;
P0M1 = P0M1 & 0xfd;
break;
case 0x11:
P0M0 = P0M0 | 0x02;
P0M1 = P0M1 | 0x02;
break;
default : break;
}
break;
case 2:
switch (bitmod)
{
case 0x00:
P0M0 = P0M0 & 0xfb;
P0M1 = P0M1 & 0xfb;
break;
case 0x01:
P0M0 = P0M0 & 0xfb;
P0M1 = P0M1 | 0x04;
break;
case 0x10:
P0M0 = P0M0 | 0x04;
P0M1 = P0M1 & 0xfb;
break;
case 0x11:
P0M0 = P0M0 | 0x04;
P0M1 = P0M1 | 0x04;
break;
default : break;
}
break;
case 3:
switch (bitmod)
{
case 0x00:
P0M0 = P0M0 & 0xf7;
P0M1 = P0M1 & 0xf7;
break;
case 0x01:
P0M0 = P0M0 & 0xf7;
P0M1 = P0M1 | 0x08;
break;
case 0x10:
P0M0 = P0M0 | 0x08;
P0M1 = P0M1 & 0xf7;
break;
case 0x11:
P0M0 = P0M0 | 0x08;
P0M1 = P0M1 | 0x08;
break;
default : break;
}
break;
case 4:
switch (bitmod)
{
case 0x00:
P0M0 = P0M0 & 0xef;
P0M1 = P0M1 & 0xef;
break;
case 0x01:
P0M0 = P0M0 & 0xef;
P0M1 = P0M1 | 0x10;
break;
case 0x10:
P0M0 = P0M0 | 0x10;
P0M1 = P0M1 & 0xef;
break;
case 0x11:
P0M0 = P0M0 | 0x10;
P0M1 = P0M1 | 0x10;
break;
default : break;
}
break;
case 5:
switch (bitmod)
{
case 0x00:
P0M0 = P0M0 & 0xdf;
P0M1 = P0M1 & 0xdf;
break;
case 0x01:
P0M0 = P0M0 & 0xdf;
P0M1 = P0M1 | 0x20;
break;
case 0x10:
P0M0 = P0M0 | 0x20;
P0M1 = P0M1 & 0xdf;
break;
case 0x11:
P0M0 = P0M0 | 0x20;
P0M1 = P0M1 | 0x20;
break;
default : break;
}
break;
case 6:
switch (bitmod)
{
case 0x00:
P0M0 = P0M0 & 0xbf;
P0M1 = P0M1 & 0xbf;
break;
case 0x01:
P0M0 = P0M0 & 0xbf;
P0M1 = P0M1 | 0x40;
break;
case 0x10:
P0M0 = P0M0 | 0x40;
P0M1 = P0M1 & 0xbf;
break;
case 0x11:
P0M0 = P0M0 | 0x40;
P0M1 = P0M1 | 0x40;
break;
default : break;
}
break;
case 7:
switch (bitmod)
{
case 0x00:
P0M0 = P0M0 & 0x7f;
P0M1 = P0M1 & 0x7f;
break;
case 0x01:
P0M0 = P0M0 & 0x7f;
P0M1 = P0M1 | 0x80;
break;
case 0x10:
P0M0 = P0M0 | 0x80;
P0M1 = P0M1 & 0x7f;
break;
case 0x11:
P0M0 = P0M0 | 0x80;
P0M1 = P0M1 | 0x80;
break;
default : break;
}
break;
default : break;
}
break;
///////////////////////////////////////////////////////////////////////////////
case 1:
switch (bitnum)
{
case 0: //0位
switch (bitmod)
{
case 0x00:
P1M0 = P1M0 & 0xfe;
P1M1 = P1M1 & 0xfe;
break;
case 0x01:
P1M0 = P1M0 & 0xfe;
P1M1 = P1M1 | 0x01;
break;
case 0x10:
P1M0 = P1M0 | 0x01;
P1M1 = P1M1 & 0xfe;
break;
case 0x11:
P1M0 = P1M0 | 0x01;
P1M1 = P1M1 | 0x01;
break;
default : break;
}
break;
case 1:
switch (bitmod)
{
case 0x00:
P1M0 = P1M0 & 0xfd;
P1M1 = P1M1 & 0xfd;
break;
case 0x01:
P1M0 = P1M0 & 0xfd;
P1M1 = P1M1 | 0x02;
break;
case 0x10:
P1M0 = P1M0 | 0x02;
P1M1 = P1M1 & 0xfd;
break;
case 0x11:
P1M0 = P1M0 | 0x02;
P1M1 = P1M1 | 0x02;
break;
default : break;
}
break;
case 2:
switch (bitmod)
{
case 0x00:
P1M0 = P1M0 & 0xfb;
P1M1 = P1M1 & 0xfb;
break;
case 0x01:
P1M0 = P1M0 & 0xfb;
P1M1 = P1M1 | 0x04;
break;
case 0x10:
P1M0 = P1M0 | 0x04;
P1M1 = P1M1 & 0xfb;
break;
case 0x11:
P1M0 = P1M0 | 0x04;
P1M1 = P1M1 | 0x04;
break;
default : break;
}
break;
case 3:
switch (bitmod)
{
case 0x00:
P1M0 = P1M0 & 0xf7;
P1M1 = P1M1 & 0xf7;
break;
case 0x01:
P1M0 = P1M0 & 0xf7;
P1M1 = P1M1 | 0x08;
break;
case 0x10:
P1M0 = P1M0 | 0x08;
P1M1 = P1M1 & 0xf7;
break;
case 0x11:
P1M0 = P1M0 | 0x08;
P1M1 = P1M1 | 0x08;
break;
default : break;
}
break;
case 4:
switch (bitmod)
{
case 0x00:
P1M0 = P1M0 & 0xef;
P1M1 = P1M1 & 0xef;
break;
case 0x01:
P1M0 = P1M0 & 0xef;
P1M1 = P1M1 | 0x10;
break;
case 0x10:
P1M0 = P1M0 | 0x10;
P1M1 = P1M1 & 0xef;
break;
case 0x11:
P1M0 = P1M0 | 0x10;
P1M1 = P1M1 | 0x10;
break;
default : break;
}
break;
case 5:
switch (bitmod)
{
case 0x00:
P1M0 = P1M0 & 0xdf;
P1M1 = P1M1 & 0xdf;
break;
case 0x01:
P1M0 = P1M0 & 0xdf;
P1M1 = P1M1 | 0x20;
break;
case 0x10:
P1M0 = P1M0 | 0x20;
P1M1 = P1M1 & 0xdf;
break;
case 0x11:
P1M0 = P1M0 | 0x20;
P1M1 = P1M1 | 0x20;
break;
default : break;
}
break;
case 6:
switch (bitmod)
{
case 0x00:
P1M0 = P1M0 & 0xbf;
P1M1 = P1M1 & 0xbf;
break;
case 0x01:
P1M0 = P1M0 & 0xbf;
P1M1 = P1M1 | 0x40;
break;
case 0x10:
P1M0 = P1M0 | 0x40;
P1M1 = P1M1 & 0xbf;
break;
case 0x11:
P1M0 = P1M0 | 0x40;
P1M1 = P1M1 | 0x40;
break;
default : break;
}
break;
case 7:
switch (bitmod)
{
case 0x00:
P1M0 = P1M0 & 0x7f;
P1M1 = P1M1 & 0x7f;
break;
case 0x01:
P1M0 = P1M0 & 0x7f;
P1M1 = P1M1 | 0x80;
break;
case 0x10:
P1M0 = P1M0 | 0x80;
P1M1 = P1M1 & 0x7f;
break;
case 0x11:
P1M0 = P1M0 | 0x80;
P1M1 = P1M1 | 0x80;
break;
default : break;
}
break;
default : break;
}
break;
///////////////////////////////////////////////////////////////////
case 2:
switch (bitnum)
{
case 0: //0位
switch (bitmod)
{
case 0x00:
P2M0 = P2M0 & 0xfe;
P2M1 = P2M1 & 0xfe;
break;
case 0x01:
P2M0 = P2M0 & 0xfe;
P2M1 = P2M1 | 0x01;
break;
case 0x10:
P2M0 = P2M0 | 0x01;
P2M1 = P2M1 & 0xfe;
break;
case 0x11:
P2M0 = P2M0 | 0x01;
P2M1 = P2M1 | 0x01;
break;
default : break;
}
break;
case 1:
switch (bitmod)
{
case 0x00:
P2M0 = P2M0 & 0xfd;
P2M1 = P2M1 & 0xfd;
break;
case 0x01:
P2M0 = P2M0 & 0xfd;
P2M1 = P2M1 | 0x02;
break;
case 0x10:
P2M0 = P2M0 | 0x02;
P2M1 = P2M1 & 0xfd;
break;
case 0x11:
P2M0 = P2M0 | 0x02;
P2M1 = P2M1 | 0x02;
break;
default : break;
}
break;
case 2:
switch (bitmod)
{
case 0x00:
P2M0 = P2M0 & 0xfb;
P2M1 = P2M1 & 0xfb;
break;
case 0x01:
P2M0 = P2M0 & 0xfb;
P2M1 = P2M1 | 0x04;
break;
case 0x10:
P2M0 = P2M0 | 0x04;
P2M1 = P2M1 & 0xfb;
break;
case 0x11:
P2M0 = P2M0 | 0x04;
P2M1 = P2M1 | 0x04;
break;
default : break;
}
break;
case 3:
switch (bitmod)
{
case 0x00:
P2M0 = P2M0 & 0xf7;
P2M1 = P2M1 & 0xf7;
break;
case 0x01:
P2M0 = P2M0 & 0xf7;
P2M1 = P2M1 | 0x08;
break;
case 0x10:
P2M0 = P2M0 | 0x08;
P2M1 = P2M1 & 0xf7;
break;
case 0x11:
P2M0 = P2M0 | 0x08;
P2M1 = P2M1 | 0x08;
break;
default : break;
}
break;
case 4:
switch (bitmod)
{
case 0x00:
P2M0 = P2M0 & 0xef;
P2M1 = P2M1 & 0xef;
break;
case 0x01:
P2M0 = P2M0 & 0xef;
P2M1 = P2M1 | 0x10;
break;
case 0x10:
P2M0 = P2M0 | 0x10;
P2M1 = P2M1 & 0xef;
break;
case 0x11:
P2M0 = P2M0 | 0x10;
P2M1 = P2M1 | 0x10;
break;
default : break;
}
break;
case 5:
switch (bitmod)
{
case 0x00:
P2M0 = P2M0 & 0xdf;
P2M1 = P2M1 & 0xdf;
break;
case 0x01:
P2M0 = P2M0 & 0xdf;
P2M1 = P2M1 | 0x20;
break;
case 0x10:
P2M0 = P2M0 | 0x20;
P2M1 = P2M1 & 0xdf;
break;
case 0x11:
P2M0 = P2M0 | 0x20;
P2M1 = P2M1 | 0x20;
break;
default : break;
}
break;
case 6:
switch (bitmod)
{
case 0x00:
P2M0 = P2M0 & 0xbf;
P2M1 = P2M1 & 0xbf;
break;
case 0x01:
P2M0 = P2M0 & 0xbf;
P2M1 = P2M1 | 0x40;
break;
case 0x10:
P2M0 = P2M0 | 0x40;
P2M1 = P2M1 & 0xbf;
break;
case 0x11:
P2M0 = P2M0 | 0x40;
P2M1 = P2M1 | 0x40;
break;
default : break;
}
break;
case 7:
switch (bitmod)
{
case 0x00:
P2M0 = P2M0 & 0x7f;
P2M1 = P2M1 & 0x7f;
break;
case 0x01:
P2M0 = P2M0 & 0x7f;
P2M1 = P2M1 | 0x80;
break;
case 0x10:
P2M0 = P2M0 | 0x80;
P2M1 = P2M1 & 0x7f;
break;
case 0x11:
P2M0 = P2M0 | 0x80;
P2M1 = P2M1 | 0x80;
break;
default : break;
}
break;
default : break;
}
break;
////////////////////////////////////////////////////////////////////////////
case 3:
switch (bitnum)
{
case 0: //0位
switch (bitmod)
{
case 0x00:
P3M0 = P3M0 & 0xfe;
P3M1 = P3M1 & 0xfe;
break;
case 0x01:
P3M0 = P3M0 & 0xfe;
P3M1 = P3M1 | 0x01;
break;
case 0x10:
P3M0 = P3M0 | 0x01;
P3M1 = P3M1 & 0xfe;
break;
case 0x11:
P3M0 = P3M0 | 0x01;
P3M1 = P3M1 | 0x01;
break;
default : break;
}
break;
case 1:
switch (bitmod)
{
case 0x00:
P3M0 = P3M0 & 0xfd;
P3M1 = P3M1 & 0xfd;
break;
case 0x01:
P3M0 = P3M0 & 0xfd;
P3M1 = P3M1 | 0x02;
break;
case 0x10:
P3M0 = P3M0 | 0x02;
P3M1 = P3M1 & 0xfd;
break;
case 0x11:
P3M0 = P3M0 | 0x02;
P3M1 = P3M1 | 0x02;
break;
default : break;
}
break;
case 2:
switch (bitmod)
{
case 0x00:
P3M0 = P3M0 & 0xfb;
P3M1 = P3M1 & 0xfb;
break;
case 0x01:
P3M0 = P3M0 & 0xfb;
P3M1 = P3M1 | 0x04;
break;
case 0x10:
P3M0 = P3M0 | 0x04;
P3M1 = P3M1 & 0xfb;
break;
case 0x11:
P3M0 = P3M0 | 0x04;
P3M1 = P3M1 | 0x04;
break;
default : break;
}
break;
case 3:
switch (bitmod)
{
case 0x00:
P3M0 = P3M0 & 0xf7;
P3M1 = P3M1 & 0xf7;
break;
case 0x01:
P3M0 = P3M0 & 0xf7;
P3M1 = P3M1 | 0x08;
break;
case 0x10:
P3M0 = P3M0 | 0x08;
P3M1 = P3M1 & 0xf7;
break;
case 0x11:
P3M0 = P3M0 | 0x08;
P3M1 = P3M1 | 0x08;
break;
default : break;
}
break;
case 4:
switch (bitmod)
{
case 0x00:
P3M0 = P3M0 & 0xef;
P3M1 = P3M1 & 0xef;
break;
case 0x01:
P3M0 = P3M0 & 0xef;
P3M1 = P3M1 | 0x10;
break;
case 0x10:
P3M0 = P3M0 | 0x10;
P3M1 = P3M1 & 0xef;
break;
case 0x11:
P3M0 = P3M0 | 0x10;
P3M1 = P3M1 | 0x10;
break;
default : break;
}
break;
case 5:
switch (bitmod)
{
case 0x00:
P3M0 = P3M0 & 0xdf;
P3M1 = P3M1 & 0xdf;
break;
case 0x01:
P3M0 = P3M0 & 0xdf;
P3M1 = P3M1 | 0x20;
break;
case 0x10:
P3M0 = P3M0 | 0x20;
P3M1 = P3M1 & 0xdf;
break;
case 0x11:
P3M0 = P3M0 | 0x20;
P3M1 = P3M1 | 0x20;
break;
default : break;
}
break;
case 6:
switch (bitmod)
{
case 0x00:
P3M0 = P3M0 & 0xbf;
P3M1 = P3M1 & 0xbf;
break;
case 0x01:
P3M0 = P3M0 & 0xbf;
P3M1 = P3M1 | 0x40;
break;
case 0x10:
P3M0 = P3M0 | 0x40;
P3M1 = P3M1 & 0xbf;
break;
case 0x11:
P3M0 = P3M0 | 0x40;
P3M1 = P3M1 | 0x40;
break;
default : break;
}
break;
case 7:
switch (bitmod)
{
case 0x00:
P3M0 = P3M0 & 0x7f;
P3M1 = P3M1 & 0x7f;
break;
case 0x01:
P3M0 = P3M0 & 0x7f;
P3M1 = P3M1 | 0x80;
break;
case 0x10:
P3M0 = P3M0 | 0x80;
P3M1 = P3M1 & 0x7f;
break;
case 0x11:
P3M0 = P3M0 | 0x80;
P3M1 = P3M1 | 0x80;
break;
default : break;
}
break;
default : break;
}
break;
default :break;
}
}
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。