本程序是用模块写的使八段数码管显示从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[i];
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模块的基础上,在模块的初始化时调用了一个函数而已。
阅读(497) | 评论(0) | 转发(0) |