/******实现模数转换********/
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar bai,shi,ge,temp;
sbit w1=P2^0;
sbit w2=P2^1;
sbit w3=P2^2;
sbit cs="P2"^3;
sbit rd="P2"^4;
sbit wr="P2"^5;
void delay(uint z);
void display(uchar b,uchar s,uchar g);
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
https://static.assets-stash.eet-china.com/album/old-resources/2009/5/13/6986c7c6-a30f-425c-83fd-4082c72bda0a.rar" target=_blank>0x6f};
void main()
{
cs=0; //打开片选
while(1)
{
wr=1;
delay(10);
wr=0;
delay(10);
wr=1;
display(bai,shi,ge);
delay(100);
rd=1;
delay(10);
rd=0;
delay(10);
temp=P1;
rd=1;
bai=temp/100;
shi=temp%100/10;
ge=temp%10;
_nop_();
}
}
void display(uchar b,uchar s,uchar g) //显示函数
{
P0=0;
w1=0;
P0=table;
delay(10);
w1=1;
P0=0;
w2=0;
P0=table;
delay(10);
w2=1;
P0=0;
w3=0;
P0=table[g];
delay(10);
w3=1;
}
void delay(uint z) //延时函数
{
uint x,y;
for(x=z;x>0;x--);
for(y=110;y>0;y--);
}
/***************结束********************/
声明:本博客内容全部原创,若要转载,请注明出处,谢谢合作!
用户602342 2009-6-13 14:15