一、寄存器
1.P1SEL:端口1功能选择。P1.7到P1.0功能选择,置0表示通用IO功能,置1表示外设功能。
2.P1DIR:端口1方向,0表示输入,1表示输出。
3.P1INR:端口1输入模式,0表示上下拉,1表示三态。
三个寄存器默认值都是0x00。
二、使用步骤
1.引入库
代码如下(示例):
#include <ioCC2530.h>
#include <string.h>
typedef unsigned char uchar;
typedef unsigned int uint;
#define LED1 P1_2
#define LED2 P1_3
/****************************************************************************
* 名 称: DelayMS()
* 功 能: 以毫秒为单位延时 16M时约为535,32M时要调整,系统时钟不修改默认为16M
* 入口参数: msec 延时参数,值越大延时越久
* 出口参数: 无
****************************************************************************/
void DelayMS(uint msec)
{
uint i,j;
for (i=0; i<msec; i++)
for (j=0; j<1070; j++);
}
void LEDInit(void)
{
P1DIR|=0x0c;//00001100,P1.2,P1.3为输出,这里我的板子上灯是P1.2,P1.3
LED1=1;//熄灭灯
LED2=1;
}
void main(void)
{
LEDInit();
while(1)
{
LED1=0;
DelayMS(500);
LED2=0;
DelayMS(500);
}
}
这里就是简单实现点灯效果。