?? wanyong1.c
字號:
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit ALE=P2^3;
sbit START=P2^4;
sbit OE=P2^5;
sbit EOC=P3^7;
sbit xs=P1^7;
sbit key1=P3^5;
sbit key2=P3^6;
uchar code disp[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code wei[]={0xf1,0xf2,0xf4,0xf8};
uint data adder[8];
uint data dis[5];
uchar q=1,w=0,k,s;
void delay(uchar p)
{
uchar i,j;
for(i=0;i<p;i++)
for(j=0;j<50;j++);
}
void key()
{
if(key1==0)
{
delay(10);
if(key1==0)
{q=!q;while(key1==0);}
}
if(q==0)
{if(key2==0)
{
delay(10);
if(key2==0)
{w++;
if(w==8){w=0;}while(key2==0);
}
}
} }
void display()
{
uchar m,n=0x00;
uchar h,l,u;
for(m=0;m<8;m++)
{
if(q==1){l=m,u=200;}else {l=w;u=1;key();}
dis[3]=l;
dis[4]=adder[l]*100/51;
dis[0]=dis[4]%10;
dis[1]=dis[4]/10%10;
dis[2]=dis[4]/100%10;
for(h=0;h<u;h++)
{
for(k=0;k<4;k++)
{
P3=wei[k];
P1=disp[dis[k]];
if(k==2){xs=0;}
delay(1);
}
if(key1==0)goto key;
}
}
key:key();
}
void adc0809()
{
uchar a;
P2=0x00;
for(a=0;a<8;a++)
{
ALE=1;_nop_();_nop_();ALE=0;
START=1;_nop_();_nop_();START=0;
_nop_();_nop_();_nop_();_nop_();
while(EOC==0);
OE=1;adder[a]=P0;OE=0;P2++;
}
}
void main()
{
P0=0xff;
P2=0x00;
P1=0xff;
P3=0xff;
while(1)
{
adc0809();
display();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -