为什么这个代码在数码管上显示的都是零,没有数值?
#include <REGX52.H>
#include "iic.h"
#include <intrins.h>
unsigned char Collect_dat1=0;
float Result_dat1=0;
unsigned int Display_dat1=0;
unsigned char Collect_dat3=0;
float Result_dat3=0;
unsigned int Display_dat3=0;
unsigned char channel=0;
code unsigned char Seg_Table[] =
{
0xc0, //0
0xf9, //1
0xa4, //2
0xb0, //3
0x99, //4
0x92, //5
0x82, //6
0xf8, //7
0x80, //8
0x90, //9
0x88, //A
0x83, //b
0xc6, //C
0xa1, //d
0x86, //E
0x8e //F
};
unsigned char code SMG_Dot[10]={0x40,0x79,
0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
void SelectHC573(unsigned char n)
{
switch(n)
{
case 4:
P2=(P2&0x1f)|0x80;
break;
case 5:
P2=(P2&0x1f)|0xa0;
break;
case 6:
P2=(P2&0x1f)|0xc0;
break;
case 7:
P2=(P2&0x1f)|0xe0;
break;
case 0:
P2=(P2&0x1f)|0x00;
break;
}
}
void Delay(unsigned int x) //@11.0592MHz
{
unsigned char i, j;
while(x--)
{
_nop_();
_nop_();
_nop_();
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
}
}
void Initsystem()
{
SelectHC573(4);
P0=0xff;
SelectHC573(5);
P0=0x00;
}
void DisplayBit(unsigned char position,unsigned char value)
{
SelectHC573(6);
P0=0x01<<position;
SelectHC573(7);
P0=value;
}
void DisplayNixie()
{
DisplayBit(0,SMG_Dot[Display_dat3/100]);
Delay(2);
DisplayBit(1,Seg_Table[(Display_dat3/10)%10]);
Delay(2);
DisplayBit(2,Seg_Table[Display_dat3%10]);
Delay(2);
DisplayBit(5,SMG_Dot[Display_dat1/100]);
Delay(2);
DisplayBit(6,Seg_Table[(Display_dat1/10)%10]);
Delay(2);
DisplayBit(7,Seg_Table[Display_dat1%10]);
Delay(2);
}
unsigned char ReadPCF8591(unsigned char dat)
{
unsigned char temp;
I2CStart();
I2CSendByte(0x90);
I2CWaitAck();
if(dat==1)
{
I2CSendByte(0x01);
}
else if(dat==3)
{
I2CSendByte(0x03);
}
I2CWaitAck();
I2CStop();
I2CStart();
I2CSendByte(0x91);
I2CWaitAck();
temp=I2CReceiveByte();
I2CSendAck(1);
I2CStop();
return temp;
}
void Write_Read()
{
Collect_dat1=ReadPCF8591(1);
Collect_dat3=ReadPCF8591(3);
Result_dat1=Result_dat1*(5.0/255);
Result_dat3=Result_dat3*(5.0/255);
Display_dat1=Result_dat1*100;
Display_dat3=Result_dat3*100;
}
void main()
{
Initsystem();
while(1)
{
DisplayNixie();
Write_Read();
}
}