#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit out=P3^7;
sbit led1=P0^7;
sbit led2=P0^6;
sbit led3=P0^5;
sbit led4=P0^4;
sbit led5=P0^3;
sbit led6=P0^2;
sbit led7=P0^1;
sbit led8=P0^0;
sbit SCL=P1^2;
sbit DO=P1^3;
sbit CS=P1^0;
uchar h1,date;
unsigned char adval;
void delay(uint z)
{
uchar y;
for(;z>0;z--)
for(y=120;y>0;y--);
}
unsigned char ad0832read(bit SGL,bit ODD)
{
unsigned char i=0,value=0,value1=0;
SCL=0;
DO=1;
CS=0;
SCL=1;
SCL=0;
DO=ODD;
SCL=1;
SCL=0;
DO=SGL;
SCL=1;
DO=1;
for(i=0;i<8;i++)
{
SCL=1;
SCL=0;
value<<=1;
if(DO)
value++;
}
for(i=0;i<8;i++)
{
value1<<=1;
if(DO)
value1+=0x01;
SCL=1;
SCL=0;
}
if(value==value1)
return value;
return 0;
}
void penquan()
{
date=ad0832read(1,0);
h1=(255-date);
out=0;
delay(h1);
if(h1>30) led1=1; else led1=0;
if(h1>70) led2=1; else led2=0;
if(h1>100) led3=1; else led3=0;
if(h1>130) led4=1; else led4=0;
if(h1>160) led5=1; else led5=0;
if(h1>180) led6=1; else led6=0;
if(h1>200) led7=1; else led7=0;
if(h1>220) led8=1; else led8=0;
out=1;
delay(date);
}
void main()
{
while(1)
{
penquan();
}
}
|