Chinaunix首页 | 论坛 | 博客
  • 博客访问: 641477
  • 博文数量: 128
  • 博客积分: 4385
  • 博客等级: 上校
  • 技术积分: 1546
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-22 14:05
文章分类

全部博文(128)

文章存档

2012年(2)

2011年(51)

2010年(75)

分类: C/C++

2010-09-13 20:13:25

ARM程序设计---led控制
注意赋值方式,利用移位操作,提高程序可读性
 

/*************************************************
Function name: 这是基础实验的一个模版
Parameter : 无
Description     : 做基础实验,直接调用该模板即可
Return         : 无
Argument : 无
Autor & date : Daniel
**************************************************/

#define    GLOBAL_CLK        1
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
#include "profile.h"
#include "memtest.h"


#define LED1_ON ~(1<<5)
#define LED2_ON ~(1<<6)
#define LED3_ON ~(1<<7)
#define LED4_ON ~(1<<8)

#define LED1_OFF (1<<5)
#define LED2_OFF (1<<6)
#define LED3_OFF (1<<7)
#define LED4_OFF (1<<8)

void delay(int times)
{
    int i;
    for(;times>0;times--)
      for(i=0;i<400;i++);
}

void set_gpio_led(void)
{
    rGPBCON &=~((3<<10)|(3<<12)|(3<<14)|(3<<16));
    rGPBCON |= (1<<10)|(1<<12)|(1<<14)|(1<<16);
}

void Led_on_all(void)
{
    rGPBDAT = rGPBDAT &(LED1_ON)&(LED1_ON)&(LED2_ON)&(LED3_ON)&(LED4_ON);
}
void Led_off_all(void)
{
     rGPBDAT = rGPBDAT|(LED1_OFF)|(LED2_OFF)|(LED3_OFF)|(LED4_OFF);
}
void Main(void)
{
    set_gpio_led();
    while(1)
    {
     delay(1000);
     Led_on_all();
     delay(1000);
     Led_off_all();
    }
}


阅读(1635) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-09-14 14:56:15

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com