7565|6

131

帖子

0

TA的资源

五彩晶圆(初级)

楼主
 

自己写的 mini2440 控制步进电机(IO口或者LED)的驱动程序+测试程序,欢迎大家批评 [复制链接]

测试程序如下
#include
#include
#include
#include
int main(int argc, char **argv)
{     int step1[]={0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0};
      int step2[]={};
int step3[]={};
int step4[]={};
int on,i;
int led_no;
int fd;
/*if (argc != 3 || sscanf(argv[1], "%d", &led_no) != 1 || sscanf(argv[2],"%d", &on) != 1 ||
     on < 0 || on > 1 || led_no < 0 || led_no > 3) {
  fprintf(stderr, "Usage: leds led_no 0|1\n");
  exit(1);
}*/
fd = open("/dev/stepmotor0", 0);
if (fd < 0) {
  fd = open("/dev/stepmotor", 0);
}
if (fd < 0) {
  perror("open device stepmotor");
  exit(1);
}
while(1)
{
for(i=0;i<4;i++)
{
ioctl(fd, step1[0+i], 0);
ioctl(fd, step1[4+i], 1);
ioctl(fd, step1[8+i], 2);
ioctl(fd, step1[12+i], 3);
usleep(500*1000);
}
}
close(fd);
return 0;
}
驱动程序如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define DEVICE_NAME "stepmotor"
static unsigned long led_table [] = {
S3C2410_GPF0,
S3C2410_GPF1,
S3C2410_GPF2,
S3C2410_GPF3,
};
static unsigned int led_cfg_table [] = {
S3C2410_GPF0_OUTP,
S3C2410_GPF1_OUTP,
S3C2410_GPF2_OUTP,
S3C2410_GPF3_OUTP,
};
static int sbc2440_leds_ioctl(
struct inode *inode,
struct file *file,
unsigned int cmd,
unsigned long arg)
{
switch(cmd) {
case 0:
case 1:
  if (arg > 4) {
   return -EINVAL;
  }
  s3c2410_gpio_setpin(led_table[arg], !cmd);
  return 0;
default:
  return -EINVAL;
}
}
static struct file_operations dev_fops = {
.owner = THIS_MODULE,
.ioctl = sbc2440_leds_ioctl,
};
static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &dev_fops,
};
static int __init dev_init(void)
{
int ret;
int i;

for (i = 0; i < 4; i++) {
  s3c2410_gpio_cfgpin(led_table, led_cfg_table);
  s3c2410_gpio_setpin(led_table, 0);
}
ret = misc_register(&misc);
printk (DEVICE_NAME"\tinitialized\n");
return ret;
}
static void __exit dev_exit(void)
{
misc_deregister(&misc);
}
module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Andrew");

最新回复

你可以先找个开发板一先实现简单的程序,了解一下! 你可以先不了解系统,先裸跑学习基本功能及特性!  详情 回复 发表于 2009-12-23 08:28
点赞 关注

回复
举报

131

帖子

0

TA的资源

五彩晶圆(初级)

沙发
 
有兴趣的跟帖 我会把我所经历的问题说出来 给新手们参考!
 
 

回复

130

帖子

0

TA的资源

纯净的硅(中级)

板凳
 
听课。
 
个人签名就这样看着你慢慢离去.......
 
 

回复

2131

帖子

0

TA的资源

至上芯片

4
 
我支持楼主,大家一起和你学习!
继续努力!
 
个人签名处处留心皆学问!
 
 

回复

131

帖子

0

TA的资源

五彩晶圆(初级)

5
 
论坛的群 85824260
大家积极发言啊 前辈们也多多指教咱们新来的 哈哈
共同提高吧 呵呵
 
 
 

回复

2112

帖子

0

TA的资源

裸片初长成(初级)

6
 
我以前没接触过arm
但是现在想自己学学
不知怎么上手啊
 
 
 

回复

2131

帖子

0

TA的资源

至上芯片

7
 

回复 6楼 heningbo 的帖子

鏌ョ湅鏈笘鍏ㄩ儴璁ㄨ锛岃鐧诲綍鎴栬€�娉ㄥ唽
 
个人签名处处留心皆学问!
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
【TI有奖直播报名中】
直播主题:MSPM0 系列 MCU 再添新成员:高性能与高性价比的优秀组合 MSPM0G351x / MSPM0L111x
直播时间:4月24日(周四)上午10:00
直播奖励:好礼等您拿!

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网 2

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表