#include <reg52.h>
#include <stdio.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int // 头文件及宏定义
uchar code table[]={
0x28,0x7b,0x1c,0x19,0x4b,
0x89,0x88,0x3b,0x08,0x09
};
sbit DI=P1^3;
sbit DO=P1^3;
sbit CS=P1^1;
sbit CLK=P1^2;
sbit w1=P2^2;
sbit w2=P2^0;
uchar data_f,data_b;
/***********************************************************/
void delay(uint z)
{
uint x,y;
for(x=0;x<z;x++)
for(y=110;y>0;y--);
}
void AD_deal() //0832测电压子程序
{
uchar i;
DI=1;
CS=1;
_nop_();
CS=0;
DI=1;
CLK=1;
_nop_();_nop_();
CLK=0;
_nop_();_nop_();
CLK=1;
DI=1;
_nop_();_nop_();
CLK=0;
_nop_();_nop_();
CLK=1;
DI=1;
_nop_();_nop_();
CLK=0;
_nop_();_nop_();
CLK=1;
_nop_();_nop_();
CLK=0;
_nop_();_nop_();
CLK=1;
for(i=8;i>0;i--)
{
data_f|=DO;
data_f<<=1;
_nop_();
CLK=1;
_nop_();
_nop_();
CLK=0;
_nop_();
_nop_();
}
for(i=8;i>0;i--)
{
data_b<<=1;
data_b|=DO;
_nop_();
CLK=1;
_nop_();
_nop_();
CLK=0;
_nop_();
_nop_();
}
CLK=1;
_nop_();_nop_();
CS=1;
}
void display()
{
int t0,t;
t0=data_f*1.93/5;
t=100-t0;
P0=0xff;
w1=0;
P0=table[t/10];
delay(5);
w1=1;
P0=0xff;
w2=0;
P0=table[t%10];
delay(5);
w2=1;
}
void main() //主函数
{
while(1)
{
AD_deal();
display();
}
} |