免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 845 | 回复: 0
打印 上一主题 下一主题

模块编程(二) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-10-21 16:48 |只看该作者 |倒序浏览

                本程序是用模块写的使八段数码管显示从0-F(已在LPC3250开发板上运行过)
程序源代码:
#include
#include
#include
#include
#include
#define p3_out  (*(volatile unsigned long *) io_p2v(0x40028004))
#define p3_clr  *(volatile unsigned long *) io_p2v(0x40028008)
#define p3_state *(volatile unsigned long *) io_p2v(0x4002800c)
unsigned long num[16]={
/*下面这些数字与你连接的引脚有关,你连接了哪个引脚就用哪个*/
(1<<14|1<<17|1<<20|1<<19|1<<7|1<<6),
(1<<17|1<<20),
(1<<14|1<<17|1<<19|1<<7|1<<5),
(1<<14|1<<17|1<<20|1<<19|1<<5),
(1<<17|1<<20|1<<6|1<<5),
(1<<14|1<<20|1<<19|1<<6|1<<5),
(1<<14|1<<20|1<<19|1<<7|1<<6|1<<5),
(1<<14|1<<17|1<<20),
(1<<14|1<<17|1<<20|1<<19|1<<7|1<<6|1<<5),
(1<<14|1<<17|1<<20|1<<19|1<<6|1<<5),
(1<<14|1<<17|1<<20|1<<7|1<<6|1<<5),
(1<<20|1<<19|1<<7|1<<6|1<<5),
(1<<14|1<<19|1<<7|1<<6),
(1<<17|1<<20|1<<19|1<<7|1<<5),
(1<<14|1<<19|1<<7|1<<6|1<<5),
(1<<14|1<<7|1<<6|1<<5)};
static int numled(void)
{
   int i;
   p3_out |=(1<<14|1<<17|1<<20|1<<19|1<<7|1<<6|1<<5);
        /*循环16次,显示0-F*/
        for(i=0;i<16;i++)
        {
          p3_clr |= num;
      printk("***************");
          mdelay(1000);
          p3_out |=(1<<14|1<<17|1<<20|1<<19|1<<7|1<<6|1<<5);
         
        }
   return 0;
}
static __init int numled_init(void)
{
   printk("numled init\n");
   numled();
   return 0;
}
static __exit void numled_exit(void)
{
printk("numled exit\n");
return ;
}
module_init(numled_init);
module_exit(numled_exit);
MODULE_LICENSE("GPL");
本程序还是在hello模块的基础上,在模块的初始化时调用了一个函数而已。
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/103858/showart_2075016.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP