请看我程序
#include "reg52.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
#define DM P0
#define WM P1
sbit CS = P2^0;
sbit CLK = P2^1;
sbit DO = P2^2;
sbit DI = P2^3;
uchar code SMG_DM[]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code SMG_WM[]={0x01,0x02};
uchar dis[2];
uchar temp;
uchar adc0832_data()
{
uchar i,Dat1=0,Dat2=0;
CLK = 0;DI = 1;CS = 0;
CLK = 1;CLK = 0;
DI = 1;CLK = 1;CLK = 0;
DI = 0;CLK = 0;CLK = 1;
for(i=0;i<8;i++)
{
CLK = 1;
CLK = 0;
_nop_();_nop_();
if(DO) Dat1|=0x80>>i;
}
for(i=0;i<8;i++)
{
if(DO) Dat2|=0x01<<i;
CLK = 1;
CLK = 0;
_nop_();_nop_();
}
CS = 1;DI = 1; CLK = 1;
if(Dat1==Dat2)
return Dat1;
}
//-------延时程序-------------------------------------------------------------------------------
void delay(uint k)
{
uint i;
for(i=0;i<k;i++);
}
//-------数码管数据拆分-------------------------------------------------------------------------
void SMG_data(uchar tmp)
{
dis[1] = tmp/10;
dis[0] = tmp%10;
}
//-------中断初始化-----------------------------------------------------------------------------
void InitTimer0(void)
{
TMOD = 0x01;
TH0 = 0x0FC;
TL0 = 0x18;
EA = 1;
ET0 = 1;
TR0 = 1;
}
//========主程序================================================================================
void main()
{
InitTimer0();
while(1)
{
temp=adc0832_data();
temp=(temp/127.0*50.0);
SMG_data(temp);
//delay(60000);
}
}
//========中断程序==============================================================================
void Timer0Interrupt(void) interrupt 1
{
static uchar i;
TH0 = 0x0FC;
TL0 = 0x18;
if(i==1)
{
WM=SMG_WM[i];DM=SMG_DM[dis[i]]&0x7f;
}
else
{
WM=SMG_WM[i];DM=SMG_DM[dis[i]];
}
i++;
if(i>1)
i = 0;
}
主程序里面对ADC0832读出的数据进行处理 按理说ADC0832是8位分辨率 读出的数除以255再乘5 (我乘的50是为了方便数码管现实)得出的就是当前电压值, 为什么我的程序除以255 最大就能显示到24 而不是50 而除以127却可以正常显示?