Chinaunix首页 | 论坛 | 博客
  • 博客访问: 354739
  • 博文数量: 79
  • 博客积分: 1270
  • 博客等级: 中尉
  • 技术积分: 1370
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-12 08:48
个人简介

freedom~~~~~~~~~~

文章分类

全部博文(79)

文章存档

2014年(10)

2013年(2)

2012年(13)

2011年(54)

分类: 嵌入式

2011-10-15 12:55:51

  1. //0x4002 1000 - 0x4002 13FF 复位和时钟控制(RCC)
  2. #define RCC_BASE        0x40021000
  3. #define RCC_APB2ENR        (RCC_BASE+0x18)
  4. //LED接在GPIOF上,是APB2上的外设,是RCC_APB2ENR寄存器的第7位

  5. //APB20x4001 1c00 GPIO端口F
  6. #define GPIOF_BASE        0x40011c00
  7. #define GPIOF_CHL        (0x000+GPIOF_BASE)
  8. #define GPIOF_CHR        (0x004+GPIOF_BASE)
  9. #define GPIOF_IDR        (0x008+GPIOF_BASE)
  10. #define GPIOF_ODR         (0x00c+GPIOF_BASE)
  11. #define GPIOF_BSRR         (0x010+GPIOF_BASE)
  12. #define GPIOF_BRR        (0x014+GPIOF_BASE)
  13. #define GPIOF_LCKR        (0x014+GPIOF_BASE)

  14. void delay(int num)
  15. {
  16.     int i,j;
  17.     for(i=0;i<num;i++)
  18.         for(j=0;j<5000;j++)
  19.             ;    
  20. }

  21. int main(void)
  22. {
  23.     *(unsigned int *)RCC_APB2ENR=1<<7;//开gpiof时钟
  24.     //设置gpiof的管脚为开漏输出,电平为0,外部电流灌入6,7,8,9管脚
  25.     //设置成开漏输出,频率无所谓,那么cny为0101,mode为0101
  26.     *(unsigned int *)GPIOF_CHL=0x55555555;
  27.     *((unsigned int *)GPIOF_CHR)=0x55555555;
  28.     *((unsigned int *)GPIOF_ODR)=0xffff;
  29.     while(1)
  30.     {
  31.         *((unsigned int *)GPIOF_BSRR)=1<<22;
  32.         delay(200);
  33.         *((unsigned int *)GPIOF_BSRR)=1<<23;
  34.         delay(200);
  35.         *((unsigned int *)GPIOF_BSRR)=1<<24;
  36.         delay(200);
  37.         *((unsigned int *)GPIOF_BSRR)=1<<25;
  38.         delay(200);
  39.         *((unsigned int *)GPIOF_ODR)=0xffff;
  40.         delay(200);
  41.     }    
  42. }
阅读(9076) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~