//CD4094 20120302 8路基準(zhǔn)電壓源使用測(cè)試//程序... #include #include #define uint unsigned int #define uchar unsigned char sbit k6=P1^7;sbit k5=P1^6;sbit k4=P1^5;sbit k3=P1^4;sbit k2=P1^3;sbit k1=P1^2;sbit LED_ON=P1^1;sbit led=P3^7;sbit A_=P3^3;sbit B_=P3^4;sbit C_=P3^5;sbit DEL=P1^0;sbit STR = P3^2;//定義CD4094各端口; sbit DATA = P3^1; sbit CLK = P3^0;uchar tt,tt1,K=0;uchar KEY();uchar code table[]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41}; //code unsigned char C51BOX2[3] _at_ 0x43; void Out_4094(uchar data1);//CD4094寫數(shù)據(jù)子函數(shù); void Delay(uint a); //延時(shí)子函數(shù); //主程序開始; void timer0(void) interrupt 1 using 0{TH0 =5000/256;TL0 =5000%256;if(K==0){tt++;if(K==0&&tt==7){{tt=0;LED_ON=~LED_ON;}}}Out_4094(table[K]);if(K!=0) LED_ON=0;tt1++;if(tt1==7){tt1=0;led=~led;}} void main() { uchar i,f,g; //無限循環(huán);TMOD=0x01;TH0 =5000/256;TL0 =5000%256;EA=1;ET0=1;TR0=1;A_=0;B_=0;C_=0;DEL=0; while(1) { /*for(g=0;g<6;g++){Delay(30000);f=table[g];Out_4094(f); //調(diào)用顯示子函數(shù); Delay(30000); //延時(shí); } */KEY();if(K==0){A_=0;B_=0; C_=0; DEL=0 ;}if(K==1){A_=0;B_=1; C_=1; DEL=0 ;}if(K==2){A_=1;B_=0; C_=1; DEL=0 ;}if(K==3){A_=0;B_=0; C_=1; DEL=0 ;}if(K==4){A_=1;B_=1; C_=0; DEL=0 ;}if(K==5){A_=0;B_=1; C_=0; DEL=1 ;}if(K==6){A_=1;B_=0; C_=0; DEL=1 ;}}} void Out_4094(uchar data1) //寫CD4094子函數(shù); { uchar i; //定義子函數(shù); STR=0; //保持然來的狀態(tài)不變; for(i=0;i<8;i++) //寫八位數(shù)據(jù)進(jìn)CD4094; { if(data1&0x01) //判斷并發(fā)串行數(shù)據(jù); { DATA=1; //發(fā)高電平; } else { DATA=0; //發(fā)低電平; } CLK=0; //形成上升延脈沖; _nop_(); _nop_(); //延時(shí); _nop_(); CLK=1; data1>>=1; //數(shù)據(jù)移位,送下一位數(shù)據(jù); } STR=1; //數(shù)據(jù)送完;更新顯示; } void Delay(uint a) //延時(shí)子函數(shù); { uint b; for(b=0;b
評(píng)論