Home > other >  ZigBee serial debugging leds a variety of effects
ZigBee serial debugging leds a variety of effects

Time:11-16

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* documents name: the main c
* : SanMu
* take order: 2020-11-9
* this:
1.1* description: set the serial debugging assistants baud rate: 9600 BPS 8 n1
* serial debugging assistant CC2530 string to control Led lights, the command is as follows:
* # make LED1, LED2, LED3, water lights, B# make three lights shining at the same time, the c # open three lights, D# closed three lights,
* 1 # change state of LED1, 2 # change LED2 state, 3 # change LED3 state,
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include
#include

Typedef unsigned char uchar;
Typedef unsigned int uint;

# define UART0_RX 1
# define UART0_TX 2
# define CONTROL_LED 3
# define SIZE 4
# define ON 0
# define OFF 1
# define LED1 P1_0//define P1.0 port is the control side LED1
# define LED2 P1_1//define P1.1 port is the control side LED2
# define LED3 P1_4
Char RxBuf;
Char UartState;
Uchar count;
Char RxData [SIZE];//store send string

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* name said DelayMS ()
* can work: in milliseconds delay
* entry parameters: msec delay parameters, the greater the value, the longer delay
No
* export parameters:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void DelayMS (uint msec)
{
Uint I, j;

for (i=0; ifor (j=0; j<1070; j++);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* name said LedOnOrOff ()
* can work: light up or put out all the LED lights
LED lights when * entrance parameters: the mode of 0 mode to 1 LED lights
No
* export parameters:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void LedOnOrOff (uchar mode)
{
LED1=mode;
LED2=mode;
LED3=mode;//as a result of P1.4 Shared with the simulator, it is necessary to pull the plug of the emulator to see LED3 change
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* name said InitLed ()
* can work: set the LED corresponding IO mouth
No
* entrance parameters:No
* export parameters:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void InitLed (void)
{
P1DIR |=0 x13;//P1.1 and P1.0
is defined as the outputLedOnOrOff (1);//the default for all LED lights put out state
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* name said InitUart ()
* will work: a serial port initialization function
No
* entrance parameters:No
* export parameters:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void InitUart (void)
{
PERCFG=0 x00;//IO control register USART 0 of the peripheral location: 0 for P0 mouth position 1
P0SEL=0 x0c;//P0_2 P0_3, used as a serial port (peripherals)
P2DIR & amp;=~ 0 xc0;//P0 priority as UART0

U0CSR |=0 x80;//set to the UART mode
U0GCR |=8;
U0BAUD |=59;//baud rate is set to 9600
UTX0IF=0;//UART0 TX interrupt flag initial setting 0
U0CSR |=0 x40;//allow receiving
IEN0 |=0 x84;//total interrupts allow receiving
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* name said UartSendString ()
* will work: a serial port to send function
* entry parameters: Data: send buffer len: send length
No
* export parameters:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void UartSendString (char * Data, int len)
{
Uint I;

for(i=0; i{
U0DBUF=* Data++;
While (UTX0IF==0);
UTX0IF=0;
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* name said UART0_ISR (void) serial port interrupt handlers
* description: when a serial port receiving interrupt 0, will receive the data stored in RxBuf
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# pragma vector=URX0_VECTOR
__interrupt void UART0_ISR (void)
{
URX0IF=0;//clear interrupt flag
RxBuf=U0DBUF;
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* program entry function
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void main (void)
{
CLKCONCMD & amp;=~ 0 x40;//set the system clock source for 32 MHZ crystals
While (CLKCONSTA & amp; 0 x40);//wait for stable crystals to 32 m
CLKCONCMD & amp;=~ 0 x47;//set the system master clock frequency is 32 MHZ

InitLed ();//set the LED corresponding IO mouth
InitUart ();//serial port initialization function
UartState=UART0_RX;//serial port 0, the default is in receiving mode
Memset (RxData, 0, SIZE);

While (1)
{
If (UartState==UART0_RX)//receiving state
{
If (RxBuf!=0)
{
If ((RxBuf!='#') & amp; & (count & lt; 2))//with a '#' as the terminator
RxData [count++]=RxBuf;
The else
{
If (count & gt;=2)//to judge data validity, prevent overflow
{
count=0;//count clear 0
Memset (RxData, 0, SIZE);//empty the receive buffer
}
The else
UartState=CONTROL_LED;//send the state
}
RxBuf=0;
}
}

If (UartState==CONTROL_LED)//control LED lights
{
//judge the received data validity
If (RxData [0]=='A' | | RxData [0]=='B' | | RxData [0]=='C' | | RxData [0]=='D'
| | RxData [0]=='1' | | RxData [0]=='2' | | RxData [0]=='3')
{
If (RxData [0]=='A')
{
LED1=ON;//light LED1
DelayMS (500);
LED1=OFF;//out LED1
LED2=ON;
DelayMS (500);
LED2=OFF;
LED3=ON;
DelayMS (500);
LED3=OFF;
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related