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

📄 testtda7540.c

📁 基于tda7540芯片的FM芯片
💻 C
字号:
#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <stdlib.h>#include <fcntl.h>#include <linux/soundcard.h>#include <unistd.h>#include <stdlib.h>#include "tda7540_ioctl_cmd.h"#define SIZE 16         /* quantize bits */#define FREQUENCE 6250  /* sample frequence */#define CHANNELS 1      /* number of channels */int main(int argc,char *argv[]){   int fd = -1;   int audio_fd = -1;   unsigned long int freq=106100;   int arg;   int status;   fd=open("/dev/tda7540",O_RDWR);   audio_fd=open("/dev/dsp",O_RDWR);      if(audio_fd < 0)   {       printf("\nopen audio device failure\n");       return -1;   }   arg=SIZE;   status=ioctl(audio_fd,SOUND_PCM_WRITE_BITS,&arg);      if(status == -1)   {         perror("SOUND_PCM_WRITE_BITS IOCTL FAILED\n");         return -1;   }      if(arg!=SIZE)   {         perror("unable to set sample size");         return -1;   }   arg=CHANNELS;//   printf("\narg=%d\n",arg);   status=ioctl(audio_fd,SOUND_PCM_WRITE_CHANNELS,&arg);//   printf("\nstatus=%d\n",status);   if(status==-1)   {         perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");         //return -1;   }   if(arg != CHANNELS)   {         perror("unable to set number of channels");         return -1;   }   arg=FREQUENCE;   status=ioctl(audio_fd,SOUND_PCM_WRITE_RATE,&arg);   if(status==-1)   {         perror("SOUND_PCM_WRITE_RATE IOCTL FAILED\n");         return -1;   }//printf("===================run tda7540===========================\n");   if(fd<0)   {     printf("\nopen failure\n ");   }   else   {//     printf("open successfully!\n");     if(argc>1)     {       freq=atoi(argv[1]);     }     ioctl(fd,TDA7540_INIT);     ioctl(fd,TDA7540_SET_FREQ,&freq);     //ioctl(fd,TDA7540_GET_FREQ,&freq);//     printf("\nread freq=%x\n",freq);//     printf("excute successfully!\n");   }   close(audio_fd);   close(fd);   return 0;}

⌨️ 快捷键说明

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