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

📄 ad_convert_display.c

📁 工ARM_LINUX的几个源代码
💻 C
字号:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <syslog.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <syslog.h>
#include <signal.h>


#include "led_ioctl.h"


#include "adc0809_ioctl.h"
#define NOKEY 0
int main()
{
	int adc_fd,count;
	int bit1,bit2,bit3;//定义显示时的百位、十位、个位
	int select = 0;	//输入AD的路号 
   char buf[2];//定义AD变换后的存放缓冲区 
	char aaa[2];  //存放显示的代码 
	int i = 0;
	int keybd_fd,led_fd,count;	
    char ret[7];  //ret[i] is the data send to LED[i]
      
        keybd_fd = open("/dev/keybd", O_RDONLY);      //open keyboard
       	if(keybd_fd<=0)
	    {
                printf("open keybd device error!\n");
		return 0;
	    }
	//************************************数码管初始化部分 
	

        led_fd = open("/dev/led",O_RDWR);              //open led.
        	if (led_fd <= 0){
		       printf("open led device error\n");
               return 0;
	                     }

                      ret[0] = NOKEY;                           //maintain the latest key value
        for (count=1; count<7; count++)
        {
                ret[count] = 0xdf;               //initiate to char '8'.
        }
                      
        ioctl(led_fd,IOCTRL_LED_1);             //light the first led:led[1]
        count = write(led_fd,ret+1,1);
	if (count != 1){
		printf("write device led error\n");
		return 0;
	}

                                        //light led[2]~led[6] with the init value '8'
        ioctl(led_fd,IOCTRL_LED_2);
	count = write(led_fd,ret+2,1);
        ioctl(led_fd,IOCTRL_LED_3);
	count = write(led_fd,ret+3,1);
        ioctl(led_fd,IOCTRL_LED_4);
	count = write(led_fd,ret+4,1);
        ioctl(led_fd,IOCTRL_LED_5);
	count = write(led_fd,ret+5,1);
        ioctl(led_fd,IOCTRL_LED_6);
	count = write(led_fd,ret+6,1);
     
    
       //*****************数码管初始化完成
      //下面读取AD变换值  
    adc_fd = open("/dev/adc0809",O_RDWR); /*打开ADC0809*/
	if (adc_fd <= 0){
		printf("open adc0809 device error\n");
		return 0;
	}
	printf("please input which input do u want:\n");
	scanf("%d",&select);
	ioctl(adc_fd,select,select);        //start collect and convert
	count = read(adc_fd,buf,1);//read ad converter's result
	if (count != 0){
	printf("key = %d\n", buf[0]);
	// 在数码管显示
	 	bit1=(int)(buf[0]/100);       //百位
        bit2=(int)((buf[0]-bit1*100)/10);  //十位
        bit3=(int)(buf[0]-bit1*100-bit2*10);//个位
        switch (bit1)
        {case 0:aaa[0]=0xde;
        case 1:aaa[0]=0x50;
        case 2:aaa[0]=0x9d;
        case 3:aaa[0]=0x5d;
        case 4:aaa[0]=0x53;
        case 5:aaa[0]=0x4f;
        case 6:aaa[0]=0xcf;
        case 7:aaa[0]=0x58;
        case 8:aaa[0]=0xdf;
        case 9:aaa[0]=0x5f;              
        } 		
        ioctl(led_fd,IOCTRL_LED_1);
        count = write(led_fd,aaa,1);
        switch (bit2)
        {case 0:aaa[0]=0xde;
        case 1:aaa[0]=0x50;
        case 2:aaa[0]=0x9d;
        case 3:aaa[0]=0x5d;
        case 4:aaa[0]=0x53;
        case 5:aaa[0]=0x4f;
        case 6:aaa[0]=0xcf;
        case 7:aaa[0]=0x58;
        case 8:aaa[0]=0xdf;
        case 9:aaa[0]=0x5f;      
        }
        ioctl(led_fd,IOCTRL_LED_2);
        count = write(led_fd,aaa,1);
        switch (bit3)
        {case 0:aaa[0]=0xde;
        case 1:aaa[0]=0x50;
        case 2:aaa[0]=0x9d;
        case 3:aaa[0]=0x5d;
        case 4:aaa[0]=0x53;
        case 5:aaa[0]=0x4f;
        case 6:aaa[0]=0xcf;
        case 7:aaa[0]=0x58;
        case 8:aaa[0]=0xdf;
        case 9:aaa[0]=0x5f;      
        }
        ioctl(led_fd,IOCTRL_LED_3);
        count = write(led_fd,aaa,1);  
                
   	    usleep(100000);
       	}	
       	close(adc_fd);
       	close(led_fd);
        close(keybd_fd); 
       	return 0;
    
}

⌨️ 快捷键说明

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