1707 views|0 replies

2015

Posts

0

Resources
The OP
 

Adjust the brightness of the LED provided by Zigbee [Copy link]

#include <ioCC2530.h> //Include header file. Generally, no modification is required. The header file contains the definition of special function registers.

#define uint unsigned int
#define uchar unsigned char

//Define the port for controlling the light
#define LED1 P1_0 //Define LED1 to be controlled by port P10
#define KEY1 P0_0 //KEY1 to be controlled by port P00

//Function declaration
void Delay(unsigned int t); //Function declaration
void InitIO(void); //Initialize LED control IO port function
void InitKey();

/*------------------------------------------------
Main function
------------------------------------------------*/
void main (void)
{
unsigned int CYCLE=1000,PWM_LOW=0;//Define cycle and assign value
InitIO();
InitKey();
while (1) //Main loop
{

if(KEY1==0)
{
//S1按下,一直按着哦。
PWM_LOW++;
if(PWM_LOW>CYCLE)
{
PWM_LOW=CYCLE-1;
}
}
else
{
PWM_LOW--;
if(PWM_LOW<1)
{
PWM_LOW=1;
}
}

if(PWM_LOW==1)
{
LED1=0;
}
else if(PWM_LOW==CYCLE)
{
LED1=1;
}
else if(CYCLE>PWM_LOW)
{
LED1=1;
Delay(PWM_LOW);
LED1=0;
Delay(CYCLE-PWM_LOW);
}
}

}
/*------------------------------------------------
Delay function, contains input parameter unsigned int t, no return value.
Unsigned int is an unsigned integer variable, and its value range is
0~65535.
------------------------------------------------*/
void Delay(unsigned int t)
{
while(t)
{
t--;
t++;
t--;
}
}

/****************************
//Initialize IO port program
********************************/
void InitIO(void)
{
P1DIR |= 0x01; //P10 is defined as output
}


/****************************
Key initialization function
********************************/
void InitKey()
{
P0SEL &= ~0x01; //Set P0.0 to normal IO port
P0DIR &= ~0X01; //The button is connected to P00 port, set P00 to input mode
P0INP &= ~0x01; //Open the P00 pull-up resistor
}
Adjust the brightness of the led1 brought by Zigbee itself, suitable for the Zigbee board of Webee

This post is from RF/Wirelessly
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

快速回复 返回顶部 Return list