本文主要是介绍day30.buzzer蜂鸣器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
第30节:buzzer蜂鸣器1、编写编译运行测试
root@ubuntu:/home/linuxsystemcode/buzzer# cat buzzer.c
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#define BUZZER_C 2
int main(int argc,char *argv[]){
char *buzzer_ctl = "/dev/buzzer_ctl";
int fd,ret,buzzer_c;
buzzer_c = BUZZER_C;if(atoi(argv[1])>= buzzer_c){
printf("argv[1] is 0 or 1\n");
exit(1);
}
if((fd = open(buzzer_ctl,O_RDWR|O_NOCTTY|O_NDELAY))<0){
printf("open %s failed\n",buzzer_ctl);
exit(1);
}
ret = ioctl(fd,atoi(argv[1]),atoi(argv[2]));
close(fd);
return 0;
}
2、进行文件编译
root@ubuntu:/home/linuxsystemcode/buzzer# arm-none-linux-gnueabi-gcc -o buzzer buzzer.c -static
root@ubuntu:/home/linuxsystemcode/buzzer# ls
buzzer buzzer.c
3、将文件拷贝到TF卡上,并传入开发板上运行结果
Please press Enter to activate this console.
[root@iTOP-4412]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 302360 14640 287720 5% /
tmpfs 307092 0 307092 0% /dev/shm
[root@iTOP-4412]# mount /dev/mmcblk1p1 /mnt
[root@iTOP-4412]# cd /mnt
[root@iTOP-4412]# ls
System Volume Information creat read
argvc creat.c read.c
argvc.c led write
buzzer led.c write.c
buzzer.c open
[root@iTOP-4412]# ./buzzer 0 1
[ 199.256459] itop4412_buzzer_ioctl: cmd = 0
第1个0是蜂鸣器不响
[root@iTOP-4412]# ./buzzer 1 1
[ 229.092276] itop4412_buzzer_ioctl: cmd = 1
第1个1是蜂鸣器响
这篇关于day30.buzzer蜂鸣器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!