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
September 27th, 2024 at 01:33 pm

怎么收藏这篇文章?

October 1st, 2024 at 09:25 pm

不错不错,我喜欢看 https://www.237fa.com/

添加新评论

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