这是程序:
#include"reg51.h"
#include"stdio.h"
sbit sound=p1^7;
sbit ST=P2^0;
sbit EOC=p2^1;
sbit OE=p2^2;
sbit ADDA=p2^3;
sbit ADDB=p2^4;
sbit blue=p2^5;
sbit yellow=p2^6;
sbit red=p2^7;
sbit bit1=p3^2;
sbit bit2=p3^3;
sbit bit3=p3^4;
sbit bit4=p3^5;
sbit bit5=p3^6;
sbit bit6=p3^7;
int DATA[3];
char ch[4];
int chardata;
int right;
char led;
int xia=10,shang=40;
void display();
void delay_1ms(int);
int wendu(int);
void AD();
void baojing(int);
void Sound();
void init_serialcom();
void baojing(int d);
{
if(d<xia){blue=0;red=1;yellow=1;led='b’;Sound();}
if(d>xia&&d<shang){red=1;yellow=0;blue=1;led=’y’;}
if(d>shang){yellow=1;red=0;blue=1;led=’r’;Sound();}
}
void Sound();
{
int m=10;
While(m--)
{
delay_1ms(1);sound=1;
delay_1ms(1);sound=0;
}
}
Void AD()
{
in
ti=0;
for(i=0;i<5;i++)
{
ST=0;
ADDA=0;ADDB=0;
delay_1ms(10);
ST=1;
Delay_1ms(10);
ST=0;
while(EOC==0);
OE=1;
DATA[0]=P0;
OE=0;
}
}
void delay_1ms(int i)
{
int j;
while(i--)
{for(j=125;j>0;j--);}
}
/********************************/
Void display()
{int discod[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00}
int tab[]={0,1,2,3,4,5,6,7,8,9};
int disbit[]={5,4,3,2,1};
int dis[6],i,j;
int getdata;
for(i=0,j=0;i<3,j<6;i++)
{
getdata=DATA[i];
dis[j]=getdata/10;
dis[j+1]=getdata%10;
j+=2;
}
for(i=0;i<6;i++)
{
P3=0x0ff;
switch(disbit[1])
{
case0:bit1=0;break;
case1:bit2=0;break;
case2:bit3=0;break;
case3:bit4=0;break;
case4:bit5=0;break;
case5:bit6=0;break;
}
P1=discode[tab[dis[i]]];
}
}
/************************************/
int wd(int d)
{
float k=0.42735,b=6.4957;
int f1;
if(d<199){f1=k*d-b;returnf1;}
if(d>=199&d<200){return80;}
if(d>=200&d<201){return85;}
if(d>=201&d<202){return88;}
if(d>=202) {return98;}
}
/*********************************************/
void init_serialcom()
{
SCON=0x50;
TMOD=0x20;
PCON=0x00;
TH1=0xFD;
TL1=0XFD;
IE=0x90;
TR1=1;
TI=1;
}
/**************************************************/
void rec_int()interrupt 4
{
if(RI)
{
RI=0;
ch[0]=SBUF;
if(ch[0]==’0’)
{
while(RI==0){}RI=0;ch[1]=SBUF;
if(ch[1]==’r’){right=1;}
else
{
if(ch[1]=='t'){right=0;}
else
{
while(RI==0){}RI=0;ch[2]=SBUF;
while(RI==0){}RI=0;ch[3]=SBUF;
chardata=(ch[2]-48)*10+ch[3]-48;
if(ch[1]==’x’){xia=chardata;}
if(ch[1]==’s’){shang=chardata;}
}
}
}
}
}
/***********************************************************/
void main()
{
int j;
init_serialcom();
while(1)
{
AD();
if(led!=0&right==1){putchar(led);putchar(led);}
else
{
putchar(‘0’);
putchar(‘0’);
}
for(j=0;j<3;j++)
{
DATA[j]=wd(DATA[j]);
if(right==1)
{
switch(DATA[j])
{ case 80:printf(“80”);break;
case 85:printf(“85”);break;
case 88:printf(“87”);break;
case 98:printf(“95”);break;
default:printf(“%d”,DATA[j]);break;
}
}
}
if(right==1);{printf(“%d%d”,xia,shang);}
display();
baojing(DATA[0]);
}
}
-
这是电路图
不对啊,我将非门给删了,数码管还是不亮
一周热门 更多>