YuxiangWang_0525的博客
不忘初心,牢记使命,只争朝夕,不负韶华
首页
友情链接
DMCA Takedown请求页面
关于我
服务器状态
CC2530 闪烁LED项目代码开源
2023-10-29 |YuxiangWang0525 | 动态
#include "ioCC2530.h"
#include <stdio.h>
#include <stdlib.h>
#define D3 P1_0
#define D4 P1_1
#define D5 P1_3
#define D6 P1_4
#define SW1  P1_2
long i = 71;
//延时
void Delay(unsigned int t)
{
  while (t--);
}
//引脚定义
void Init_Port()
{
  //1-设置4个引脚为通用I/O
  P1SEL &= ~0x1B;  //0001 1011 --> 1110 0100
  //2-设置4个引脚的方向:输出
  P1DIR |= 0x1B;  //0001 1011
  //3-关闭4个LED灯
  D3 = 0;
  D4 = 0;
  D5 = 0;
  D6 = 0;
  P1DIR &= ~0x04;  //设置P1_2口为输入口
  P1INP &= ~0x04;  //设置P1_2口为上拉或下拉
  P2INP &= ~0x40;  //设置P1口所有引脚使用上拉
}
void all_light_on(){
  D3 = 1;
  D4 = 1;
  D5 = 1;
  D6 = 1;
}void all_light_off(){
  D3 = 0;
  D4 = 0;
  D5 = 0;
  D6 = 0;
}
void Routering(){
  D3 = 1;
  Delay(56000);
  D3 = 0;
  D4 = 1;
  Delay(56000);
  D4 = 0;
  D5 = 1;
  Delay(56000);
  D5 = 0;
  D6 = 1;
  Delay(56000);
  D6 = 0;
}
void Flashing(){
  all_light_on();
  Delay(56000);
  all_light_off();
  Delay(56000);
}
void LED_Running()
{
  static int count = 0;
  switch (count)
    {
      case 1:
        all_light_on();
        break;
      case 2:
        Routering();
        break;
      case 3:
        Flashing();
        break;
      default:
        count = 0;
        break;
    }
  if (SW1 == 0)  //经过延时后按键仍旧处在按下状态
  {
    count++;
    }
    while (!SW1)
    {
      //等待按键松开
    }
    
  
}
/*==========================主函数============================*/
void main()
{
  Init_Port();
  while (1)
  {
    LED_Running();
  }
}
respond-post-93
November 14th, 2024 at 10:51 pm

bookmarked!!, I love your webb site!

November 15th, 2024 at 05:03 am

It's actually a nice and useful piece of information. I aam satjsfied
tha yyou simply shared this hedlpful info wih us.

Pleaase keep uus up tto dare llike this. Thank
you for sharing.

February 4th, 2025 at 08:25 am

I really luke your blog.. very nice colors & theme.
Did you create thbis website yourselff or ddid you hire someeone to doo itt foor
you? Plz respond aas I'm looking too creaqte mmy own blopg aand would ike
to kno wuere u gott this from. thanks a lot

添加新评论

请填写称呼
请填写合法的电子邮箱地址
请填写合法的网站地址
请填写内容