⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 1) 复制libminigui-str-1.6.2.tar.gz至任意用户目录。 2) 解压此文件 tar zxvf libminigui-str-1.6.2.tar.gz 4) 将zl
💻 C
字号:
/* to produce a pwm of 100khz(10us)and 20% duty cycle with system clock of 14.7456Mhz
   
   Caculate Pwmtermcnt (14.7456M/0.1M) -1 = 146.456 
   Caculate PwmDutyCycle 0.2*(146.456+1)-1= 28.4912
Attention:
   the lowst frequency of pwmout is 224hz,mean that the max cycle is 4.44ms
   the freqency our humanbeing can hear is from 20HZ to 20000HZ
   so the number arrange of  TC is from 737 to 65536 
*/  
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
int main(void)
{
  int buttons_fd;
  unsigned char key_value;

  buttons_fd = open("/dev/zlg7289", 0);
  if (buttons_fd < 0) {
    perror("open device buttons");
    exit(1);
  }

  for (;;) {
    fd_set rds;
    int ret;

    FD_ZERO(&rds);
    FD_SET(buttons_fd, &rds);

    ret = select(buttons_fd + 1, &rds, NULL, NULL, NULL);
    if (ret < 0) {
        perror("select");
        exit(1);
    }
    if (ret == 0) {
        printf("Timeout.\n");
    } else if (FD_ISSET(buttons_fd, &rds)) {
        int ret = read(buttons_fd, &key_value, sizeof(key_value));
        if (ret != sizeof key_value) {
            if (errno != EAGAIN)
              perror("read buttons\n");
            continue;
        } else {
            printf("buttons_value: %x\n", key_value);
            if(key_value == 7)break;
        }
            
    }
  }
  if(close(buttons_fd)<0) {
       perror("close");
       exit(EXIT_FAILURE);
  }
  printf("finished 7289 key test\n");
  exit(EXIT_SUCCESS);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -