创维特试验箱上实现步进电机的运转

上传人:mg****2 文档编号:122127249 上传时间:2020-03-01 格式:DOC 页数:8 大小:81KB
返回 下载 相关 举报
创维特试验箱上实现步进电机的运转_第1页
第1页 / 共8页
创维特试验箱上实现步进电机的运转_第2页
第2页 / 共8页
创维特试验箱上实现步进电机的运转_第3页
第3页 / 共8页
创维特试验箱上实现步进电机的运转_第4页
第4页 / 共8页
创维特试验箱上实现步进电机的运转_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《创维特试验箱上实现步进电机的运转》由会员分享,可在线阅读,更多相关《创维特试验箱上实现步进电机的运转(8页珍藏版)》请在金锄头文库上搜索。

1、. 嵌入式系统实验报告一、实验时间2015年5月5日14:3021:30二、实验地点一实验楼401机房三、实验目的1、在创维特试验箱上实现步进电机的运转。四、实验步骤1、了解步进电机的运作方式。2、编译驱动代码代码:static struct timer_list ttimer;static int Device_Open = 0;static int num=2; /*used to control the speed of the stepper*/static enumoff,clockwise,anticlockwise status=off; /*used to indicate a

2、nd set the status of the stepper*/static int row=0;unsigned char pulse_table = 0x05, 0x09, 0x0a, 0x06,;static char* out_base;/* kernel addr*/intdevice_ioctl(struct inode *,struct file *,unsigned int ,unsigned long ); static void time_tick(unsigned long data)static int i=0;/printk(time_tickn);switch(

3、status) case off: break; case clockwise: if(+i=num) i=0; if( row = 4 ) row = 0;writeb(pulse_tablerow+,out_base); ttimer.expires=jiffies+5;/set timer add_timer(&ttimer);/add timer break; case anticlockwise: if(+i=num) i=0; if( row = -1 ) row = 3; writeb(pulse_tablerow-,out_base); ttimer.expires=jiffi

4、es+5;/set timer add_timer(&ttimer);/add timer break; default: break;/* This function is called whenever a process attempts * to open the device file */static int device_open(struct inode *inode, struct file *file) printk(Device Openn); /* We dont want to talk to two processes at the * same time */ i

5、f (Device_Open) return -EBUSY; Device_Open+; MOD_INC_USE_COUNT; return 0;/* This function is called when a process closes the * device file. It doesnt have a return value because * it cannot fail. Regardless of what else happens, you * should always be able to close a device (in 2.0, a 2.2 * device

6、file could be impossible to close). */static int device_release(struct inode *inode, struct file *file) printk(Device Releasen); /* Were now ready for our next caller */ Device_Open -; MOD_DEC_USE_COUNT; return 0;/* This function is called whenever a process which * has already opened the device fil

7、e attempts to * read from it. */static ssize_t device_read( struct file *file, char *buffer, /* The buffer to fill with the data */ size_t length, /* The length of the buffer */ loff_t *offset) /* offset to the file */return 0;/* This function is called when somebody tries to * write into our device

8、 file. */ static ssize_t device_write(struct file *file, const char *buffer, size_t length, loff_t *offset)return 0;/* This function is called whenever a process tries to * do an ioctl on our device file. We get two extra * parameters (additional to the inode and file * structures, which all device

9、functions get): the number * of the ioctl called and the parameter given to the * ioctl function. * * If the ioctl is write or read/write (meaning output * is returned to the calling process), the ioctl call * returns the output of this function. */int device_ioctl( struct inode *inode, struct file

10、*file, unsigned int ioctl_num,/* The number of the ioctl */ unsigned long ioctl_param) /* The parameter to it */ struct stepper * s; printk(Device Ioctln); /* Switch according to the ioctl called */ switch (ioctl_num) case IOCTL_SET_MSG: /* Receive a pointer to a message (in user space) * and set th

11、at to be the devices message. */ /* Get the parameter given to ioctl by the process */ s = (struct stepper*) ioctl_param; printk(CmdID=%dn,s-CmdID); switch (s-CmdID) case 0: /*start*/ status=clockwise; ttimer.expires=jiffies+1; /start the timer add_timer(&ttimer); /add timer printk(clockwisen); brea

12、k; case 1: /*stop*/ status=off; /change the status of the stepper printk(offn); break; case 2: /*reverse*/ if(status=clockwise) status=anticlockwise;/change the status of the stepper printk(anticlockwisen); else if(status=anticlockwise) status=clockwise; printk(clockwisen); break; case 3: /*speed up

13、*/ if(num!=1)num-; break; case 4: /*speed down*/ num+; break; break; case IOCTL_GET_MSG: printk(Device Ioctl GET_MSGn); break; return 0;/* Module Declarations * */* This structure will hold the functions to be called * when a process does something to the device we * created. Since a pointer to this structure is kept in * the devices table, it cant be local to * init_module. NULL is for unimplemented functions. */struct file_operations Fops = .read = device_r

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 教学/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号