#include<reg52.h>typedef unsigned int u16;typedef unsigned char u8;sbit w1=P2^0;sbit w2=P2^1;sbit w3=P2^2;sbit w4=P2^3;sbit start=P3^0;sbit eoc=P3^1;sbit oe=P3^2;sbit clk=P3^3;sbit in1=P2^4;sbit in2=P2^5;sbit in3=P2^6;sbit in4=P2^7;sbit valve1=P3^4;sbit valve2=P3^5;sbit valve3=P3^6;sbit valve4=P3^7;
u8 getdata,table2[4];u16 t;
#define DATA1 P1#define DATA P0u8 code D_table[]={0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83, 0xc6,0xa1,0x86,0x8e};u8 code W_table[]={0x0e,0x0d,0x0b,0x07};
void init_interrupt(){ TMOD=0x02; TH0=0xfb; TL0=0xfb; EA=1; ET0=1; TR0=1;}
void delay(u16 num){ u16 x,y; for(x=num;x>0;x--) for(y=110;y>0;y--) { ; }
}
void display_led(u8 which_bit,u8 which_number){ P2=W_table[which_bit]; P0=D_table[which_number]; delay(1);}void shot(){
if(in1==1) { valve1=1; delay(5000); valve1=0; } if(in2==1) { valve2=1; delay(5000); valve2=0; } if(in3==1) { valve3=1; delay(5000); valve3=0; } if(in4==1) { valve4=1; delay(5000); valve4=0; }
}void adc0809(){
oe=0; start=0; start=1; start=0; while(eoc==1); oe=1; getdata=P1; oe=0; t=getdata*(5000.0/256); table2[3]=t/1000; table2[2]=(t-table2[3]*1000)/100; table2[1]=(t-table2[3]*1000-table2[2]*100)/10; table2[0]=0; display_led(0,table2[3]); display_led(1,table2[2]); display_led(2,table2[1]); display_led(3,table2[0]);
}
void main(void){ P0=0xff; P2=0xff; in1=in2=in3=in4=0; valve1=valve2=valve3=valve4=0; init_interrupt(); while(1) { adc0809(); shot();
}}void timer_T0(void) interrupt 1{ clk=~clk;}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
具体怎么改呢?新手不太会
一周热门 更多>