?? ad.c
字號:
#include <stdio.h>#include <sys/time.h>#include <signal.h>#include "../include/44b.h"struct timeval tpstart;#define MAX_VALUE 0x3ff#define MIN_VALUE 0x0 char display_buffer[6];int refresh_index = 0; unsigned char seg7table[16] ={ /* 0 1 2 3 4 5 6 7*/ 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, /* 8 9 A B C D E F*/ 0x80, 0x90, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e,};void poll_timer(int signo){ if(refresh_index == 2) refresh_index ++; if(refresh_index == 5) refresh_index =0; *((unsigned char*) 0x02000006) = 0x3f & ~(0x01 << refresh_index); *((unsigned char*) 0x02000004) = seg7table[display_buffer[refresh_index]]; refresh_index ++;}void init_sigaction(void){ struct sigaction act; act.sa_handler=poll_timer; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGPROF,&act,NULL); /* begin get the time */ gettimeofday(&tpstart,NULL);}void init_time(){ struct itimerval value; value.it_value.tv_sec=0; value.it_value.tv_usec=1; value.it_interval=value.it_value; setitimer(ITIMER_PROF,&value,NULL);}char trans_input(int value){ if(value == MAX_VALUE) return 50; return(char )(value * 50 / (MAX_VALUE-MIN_VALUE));}/* * timer application code * compile : * $arm-elf-gcc -Wl,-elf2flt -o ad ad.c * $cp ad /tftpboot/examples * run in target: * #cd /var * #ftp 192.168.1.180 * ftp>bin * ftp>cd /tftpboot/examples * ftp>get ad * ftp>by * #./ad */int main(int argc, char **argv){ int loop_delay; int data = 0; int get_index; rCLKCON=0x7ff8; init_sigaction(); init_time(); while(1) { int value; int rADCDAT_TEMP0,rADCDAT_TEMP1,rADCDAT_TEMP2,rADCDAT_TEMP3, rADCDAT_TEMP4,rADCDAT_TEMP5,rADCDAT_TEMP6,rADCDAT_TEMP7; rADCPSR=0x0; data = 0; for(get_index = 0; get_index < 16; get_index++) { rADCCON=0x1|(0x2<<2); // AIN2 while(!(rADCCON & 0x40)); data+=rADCDAT; } data /= 32; value = trans_input(data); display_buffer[0] = value / 10; display_buffer[1] = value % 10; data = 0; for(get_index = 0; get_index < 16; get_index++) { rADCCON=0x1|(0x3<<2); // AIN3 while(!(rADCCON & 0x40)); data+=rADCDAT; } data /= 32; value = trans_input(data); display_buffer[3] = value / 10; display_buffer[4] = value % 10; } exit(0);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -