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

📄 float.c

📁 美国tern公司开发的嵌入式开发平台586E
💻 C
字号:
/*********************************************************
	586_ad1.c		Fast single channel ADS7852 		11-18-2002
	U12, AD7852, 8 channles, 12-bit, parallel interface
 	CLKT=J1.4 output 18.432 MHz as ADC clock for U12
		outportb(0x18f0+i,0);	will start conversion on channel i.
	 	inport(0x18f0) returns the previous conversion result !
	ADC busy signal is not routed out, low indicates busy,
	software must waits 16 ADC clocks.
	In this sample, about 2.8 microseconds time to do one convertion:
	Start ADC, process previous data and wait, read in ADC)

	350 KHz Sample Rate can be done with this sample.
********************************************************/
#include	<dos.h>
#include <math.h>
#include <float.h>
#include	<string.h>
#include	"586.h" // 586 initialization
unsigned int ledd,i,cai[10000];
unsigned long int j;
unsigned int a,b,c,d,e,f,x;
float average;
double sum;
#define AD7852 0x18f0
#define MMCR 0xdf00
#define ERR_LIMIT 0.000001
unsigned char led1[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,   //0,1,2,3,4,5
                       //0   1   2   3   4   5
                      0x7D,0x07,0x7F,0x6F,0x77,0x7C,    //6,7,8,9,A,B
                      //6   7   8   9   10  11
                      0x39,0x5E,0x79,0x71,0x73,0x3E,    //C,D,E,F,P,U
                      // 12  13  14  15  16  17
                      0x76,0x38,0x40,0x6E,0x0FF,0x00,   //H,L,-,Y, 全屏  ,'全暗'
                      //18  19  20  21  22   23
                      0x37,0x3F,0x6D,0x06,0x2F,0x6F,   //N,O,S,I,error,G,
                      //24  25  26  27  28  29
                      0x0E,0x67,0x50,0x31};             //J,Q,R,T
                      //30  31  32  33
void main(void)
{
	sc_init();	 // 586 initialization */
// AD7852 uses CLKT as external clock
	clkt_sel(2); // CLKT=J1.4 output 18.432 MHz
   pokeb(MMCR,	_GPCSRT_, 0); // set the GP CS recovery time
 	pokeb(MMCR,	_GPCSPW_, 6); // set the GP CS width
 	pokeb(MMCR,	_GPCSOFF_, 2); // set the GP CS offset
 	pokeb(MMCR,	_GPRDW_, 4); // set the GP RD pulse width
 	pokeb(MMCR,	_GPRDOFF_, 3); // set the GP RD offset
 	pokeb(MMCR,	_GPWRW_, 4); // set the GP WR pulse width
 	pokeb(MMCR,	_GPWROFF_, 3); // set the GP WR offset
 	poke(MMCR,_BOOTCSCTL_,peek(MMCR,_BOOTCSCTL_)&0xffc9);	// ROM 1 wait
 	poke(MMCR,_ROMCS2CTL_,peek(MMCR,_ROMCS2CTL_)&0xffc8);	// SRAM 0 wait
	ledd=0;
   for(i=2;i<27;i++){
		pio_init(i, 2); // PIO 2-26 as output
		}
	pio_init(28, 2); // PIO 28 as output
	pio_init(29, 2); // PIO 29 as output
	pio_init(30, 2); // PIO 30 as output


while(1)
{     for(i=0;i<100;i++)   //100 sample
	{
   outportb(AD7852,0); // This outportb starts conversion for the next read
	led(ledd);
	ledd=~ledd;
	cai[i]=inport(AD7852); // starts conversion on Channel 0 for the next read
   cai[i]=cai[i]>>4;
   }
   for(i=0;i<100;i++)
   {cai1[i]=(float)cai[i];}
   //}	// process and store data, wait for 16 clocks, while busy
   for(i=0;i<100;i++)
   {sum=sum+cai[i];}

   average=sum/100.0;  //average value
   j=(long int)(sum*100.0);

   //bcd transfer//
   j=(long int)(sum*100.0);


   //bcd transfer//
   a=j/100000;
   j=j%100000;
   b=j/10000;
   j=j%10000;
   c=j/1000;
   j=j%1000;
   d=j/100;
   j=j%100;
   e=j/10;
   j=j%10;
   f=j;

   // display//
   x=led1[a]|0xfe00; //千位
   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);  //can not use outport command
   delay_ms(10);
	x=led1[b]|0xfd00; //百位
   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);
   delay_ms(10);
   x=led1[c]|0xfb00; //十位
   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);
   delay_ms(10);
   x=led1[d]|0xf780; //个位,加上小数点
   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);
   delay_ms(10);
   x=led1[e]|0xef00; //十分位
   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);
   delay_ms(10);
   x=led1[f]|0xdf00; //百分位?   x=x<<2;
   poke(MMCR, _PIODATA15_0_,x);
   delay_ms(10);


	}
}

⌨️ 快捷键说明

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