|
下載東西還要黑幣 這么黑 還是來要人幫忙的?
給你個程序看看吧!
#include<STC15F2K60S2.H>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define VCC 4.97
uchar code dsp_duan[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0x3e,0xe0,0xfe,0xf6};
uchar code dsp_dian[]={0xfd,0x61,0xdb,0xf3,0x67,0xb7,0xbf,0xe1,0xff,0xfd};
sbit du=P1^1;
sbit we=P1^0;
uint AVG=0;
uint aa,bb,cc,dd;
//_____________________________________
void delay1ms() //@22.1184MHz
{
unsigned char i, j;
_nop_();
_nop_();
i = 22;
j = 128;
do
{
while (--j);
} while (--i);
}
void display()
{
du=1;
P3=dsp_dian[aa];
du=0;
P3=0Xff;
we=1;
P3=0X7F; //For table[8];
we=0;
delay1ms();
du=1;
P3=dsp_duan[bb];
du=0;
P3=0Xff;
we=1;
P3=0XBF;
we=0;
delay1ms();
du=1;
P3=dsp_duan[cc];
du=0;
P3=0XFF;
we=1;
P3=0Xdf;
we=0;
delay1ms();
}
void adc_init()
{
uint i;
ADC_CONTR|=0X80;
for(i=0;i<10000;i++);
P1ASF|=0X80;
ADC_CONTR=0XE7;
delay1ms();
ADC_CONTR|=0X08;
EADC=1;
EA=1;
}
void main()
{
float Vin;
adc_init();
while(1)
{
Vin=(VCC*AVG)/1023;
dd=(Vin*1000);
aa=dd/1000;
bb=dd/100%10;
cc=dd%100/10;
display();
}
}
void adc() interrupt 5
{
uint AD_DAT=0;
uchar TMP=0;
ADC_CONTR&=0XE7;
AD_DAT=ADC_RES;
AD_DAT<<=2;
TMP=ADC_RESL;
TMP&=0X03;
AD_DAT|=TMP;
AVG=AD_DAT;
ADC_CONTR|=0X88;
}
只是個簡單的 沒有做平均求值!也是開始學(xué)ADC時候?qū)懙某绦颍崿F(xiàn)最簡單的功能 |
|