testpwm.c
来自「c语言在LINUX平台下开发PWM驱动程序.可以实现波形的调整」· C语言 代码 · 共 48 行
C
48 行
/******************************* file : testpwm.c ****************************** Version : 1.0 Function: The PWM driver test Auther: BIT 11/2006*******************************************************************************/#include <stdio.h>#include <unistd.h>#include <fcntl.h>#include <stdlib.h>#include <math.h>#include "disp_pic.h"/******************************************************************************output a pwm wave*******************************************************************************/main(){ int fd; unsigned int pwm_data; unsigned char str_temp[32]; unsigned char temp; printf("\n******************\n"); printf(" PWM Test Program.\n"); printf("******************\n"); fd=open("/dev/pwm",O_RDWR); if(fd<0) { printf("Can't open device file: pwm\n"); perror("Open: "); exit(-1); } while(1) { printf("\n\n****************************************************\n"); printf("Input the decimal of the PWM (0-4095) :\n"); printf("--For example, if you input '654', then the H:L of the pwm output is (654 : 4095-654)\n"); fgets(str_temp,32,stdin); pwm_data=atoi(str_temp); pwm_data&=0xfff; printf("What you input is : 0x%x\n",pwm_data); ioctl(fd,0,pwm_data); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?