|
灰原姐姐 发表于 2013-2-17 12:51
贴完整代码出来。包括变量申明。
#include<STC15F2K60S2.H>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit RCK=P4^1;
sbit DS=P4^4;
sbit CLK=P4^2;
void write_595(uint dat);
void display_595(uchar i,uchar j);
void display_595_1(uchar i,uchar j);
uchar code wei[]={0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar code duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code duan_1[]={0x40,0x79,0x24,0x30,0x19,0x02,0x02,0x78,0x00,0x10};
uchar result;
float vin;
void main()
{
uchar i;
uchar a=0,b=0,c=0,status;
uint temp=0;
P1ASF=0x10;
ADC_CONTR=0x84;
for(i=0;i<10;i++)
{for(i=0;i<100;i++);}
while(1)
{
ADC_CONTR=0x8c;
_nop_();
_nop_();
_nop_();
_nop_();
status=0;
while(status==0)
{
status=ADC_CONTR&0x10;
}
ADC_CONTR=0x81;
result=ADC_RES;
vin=(result*5.0)/256.0;
temp=vin*100;
a=temp/100;
b=(temp/10)%10;
c=(temp%100)%10;
display_595_1(1,a);
display_595(2,b);
display_595(3,c);
P0=~result;
}
}
void write_595(uint dat)
{
uchar i;
for(i=0;i<16;i++)
{
CLK=0;
if((dat&0x8000)==0x8000)
{
DS=1;
}
else
{
DS=0;
}
CLK=1;
dat<<=1;
}
RCK=0;
RCK=1;
}
void display_595(uchar i,uchar j)
{
uint a=0x0000;
uchar b=wei;
uchar c=duan[j];
a=b<<8;
a=a+c;
write_595(a);
}
void display_595_1(uchar i,uchar j)
{
uint a=0x0000;
uchar b=wei;
uchar c=duan_1[j];
a=b<<8;
a=a+c;
write_595(a);
}
|
|