CC2530+CC Debugger - Simple lighting control

foreword

I started to learn the Internet of Things and shared some ideas with you. I also urged myself to work hard ᕦ(・ㅂ・)ᕤ
I learned CC2530. The first lesson started with simple lights!

principle

This is mainly through P1DIR (0xFE), which is the input and output
setting register of P1 port. 0: input, 1: output .


the code

#include <ioCC2530.h> //把 CC2530 的头文件包含进来
#define uint unsigned int
#define uchar unsigned char
//定义控制灯的端口
#define YLED P1_0 //定义 YLED 为 P10 口控制
#define BLED P1_1 //定义 BLED 为 P11 口控制
//函数声明
void Delay(uint); //延时函数声明
void InitIO(void); //初始化函数声明
/****************************
//延时
*****************************/
void Delay(uint n)
{
    
    
 uint i,j;
 for(j = 0; j<5; j++)
 {
    
    
 for(i = 0;i<n;i++);
 } }
/****************************
//初始化程序,将 P10、P11 定义为输出口,并将 LED 灯初始化为灭
*****************************/
void InitIO(void)
{
    
    
 P1DIR= 0x03; //P10、P11 定义为输出
 BLED = 1;
 YLED = 1; //LED 灯初始化为灭
}
/***************************
//主函数
***************************/
void main(void)
{
    
    
InitIO(); 
 while(1)
 {
    
    
   for(int i=0;i<5;i++)
   {
    
    
    YLED = 0;
    Delay(5000);
    YLED = 1;
    Delay(5000);
   }
   for(int i=0;i<5;i++)
   {
    
    
    BLED = 0;
    Delay(5000);
    BLED = 1;
    Delay(5000);
   }
 
   for(int i=0;i<5;i++)
   {
    
    
    BLED = 0;
    YLED = 1;
    Delay(5000);
    BLED = 1;
    YLED = 0;
    Delay(5000);
   }

 } }

The nine-story high platform starts from the pile of soil; the journey of a thousand miles begins with a single step! (ง •_•)ง, come on

Guess you like

Origin blog.csdn.net/qq_44616044/article/details/115468717