免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1622 | 回复: 0

STM32简单的LED流水灯程序 [复制链接]

论坛徽章:
0
发表于 2011-12-23 02:29 |显示全部楼层
  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. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP