《TQ2440在linux下控制AD实验总结OK》由会员分享,可在线阅读,更多相关《TQ2440在linux下控制AD实验总结OK(5页珍藏版)》请在人人文库网上搜索。
1、TQ2440在linux下控制 AD实验总结myadc.c:#include #include Vinux/delay .h#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vola。
2、tile unsigned long *adccon = NULL; /adc 控制寄存器volatile unsigned long *adctsc = NULL; /adc触摸屏控制寄存器volatile unsigned long *adcdly = NULL; /adc起始延迟寄存器volatile unsigned long *adcdatO = NULL; /adc转换数据寄存器volatile unsigned long *adcdat1 = NULL; /adc转换数据寄存器volatile unsigned long *intmsk = NULL;#define MYADC_。
3、MAJOR 150/*预设的 globalmem 的主设备号 */static int myadc_major = MYADC_MAJOR; struct cdev* adc_cdev;ssize_t drive_read(struct file *file, char *buf, size_t count, loff_t *f_ops)int val;printk(drive read okn);*adccon |= (1 ops = &drive_ops;cdev_init (&adc_cdev, &drive_ops);cdev_add(&adc_cdev, dev, 1);adccon。
4、 = (volatile unsigned long *)ioremap(0x58000000, 16); adctsc = (volatile unsigned long *)ioremap(0x58000004, 8); adcdly = (volatile unsigned long *)ioremap(0x58000008, 16); adcdat0 = (volatile unsigned long *)ioremap(0x5800000c, 16); adcdat1 = (volatile unsigned long *)ioremap(0x58000010, 16); intms。
5、k = (volatile unsigned long *)ioremap(0x4a000008, 32); printk(drive button init okn);return 0;static void __exit exit_drive(void)dev_t dev;dev = MKDEV(myadc_major, 0);cdev_del(&adc_cdev);unregister_chrdev_region(dev, 1);printk(drive button exit okn);module_init(init_drive); module_exit(exit_drive);M。
6、ODULE LICENSE(GPL);Makefile :ifneq ($(KERNELRELEASE),)obj-m :=myadc.oelseKERNELDIR ?= /home/book/opt/EmbedSky/linux-2.6.30.4/PWD := $(shell pwd)default:$(MAKE) -C $(KERNELDIR) M=$(PWD) modulesclean:rm -rf *.o * core .depend .*cmd *ko *mod.cendiftest.c:#include #include #include #include #include int。
7、 main(int argc, char *argv)int fd, ret;int val;fd = open(/dev/myadc, O_RDWR);if(fd = -1)printf(cant open device mknod %s c zhu ci n, /dev/myadc); return 0;whileread(fd,&val,sizeof(val);printf(appn);printf(val=%dn,val);sleep(3);ret = close(fd);if (ret = -1)printf(app close error!n);return 0;return 0;。
8、实验现象:拨动可调电阻改变电压,发现数值会随之发生变化。rootEmbedSky /# insmod myadc.kodrive button init okrootEmbedSky /# ls -l /dev/myadccrw-rw-1 root root10, 55 Feb 24 11:38 /dev/myadcrootEmbedSky /# cat /proc/devicesCharacter devices:7 vcs10 misc13 inputrootEmbedSky/# ./testdrive read okdrive val=518drive-close-okappval=518drive read okdrive val=520drive-close-okappval=520rootEmbedSky /# rmmod myadc.kodrive button exit ok。