最近在5438上写IO控制时,总结如下代码,发现如此简单
使用方法:
使P7OUT的BIT3位,电平翻转
复制代码 - #define SW_ON 0
- #define SW_OFF 1
- #define SW_FLASH 2
- #define P12OUT (PJOUT_L) /* Port 11 Output */
- unsigned char volatile *PT_CTL[12] =
- {
- &P1OUT,
- &P2OUT,
- &P3OUT,
- &P4OUT,
- &P5OUT,
- &P6OUT,
- &P7OUT,
- &P8OUT,
- &P9OUT,
- &P10OUT,
- &P11OUT,
- &P12OUT,
- };
- void IoCtl( int index_port,unsigned int _chan, unsigned char _onoff )
- {
- unsigned char volatile * p = &PAOUT_L;
- p = PT_CTL[index_port];
- switch(_onoff)
- {
- case SW_ON :
- *p &= ~(BIT0 << _chan);
- break;
- case SW_OFF :
- *p |= (BIT0 << _chan);
- break;
- case SW_FLASH :
- *p ^= (BIT0 << _chan);
- break;
- default:
- break;
- }
- }
#define LED {IoCtl(7-1, 3, SW_FLASH);}
LED;(只测试过P7,其它端口未测试) |