实验作用如下:
#include
#define duan P0//段选
#define wei P2//位选
unsigned char code wei1[8] = {
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位选操控 查表的办法操控
unsigned char code duan1[17] = {
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//0、1、2、3、4、5、6、7、8、9、A、b、C、d、E、F的显现码
unsigned char ge,shi,bai,temp;
void DigDisplay(); //动态显现函数
void init(); //初始化函数
void main(void)
{
init();
while(1)
{
DigDisplay();
}
}
void DigDisplay()
{
unsigned char i,j;
bai=temp/100;
shi=temp%100/10;
ge=temp%10;
wei = wei1[i];//发送位选
duan = duan1[bai]; //发送段码
j = 10;//扫描间隔时间设定
while(j–);
duan = 0x00; //消隐
i++;
wei = wei1[i];//发送位选
duan = duan1[shi]; //发送段码
j = 10;//扫描间隔时间设定
while(j–);
duan = 0x00; //消隐
i++;
wei = wei1[i];//发送位选
duan = duan1[ge]; //发送段码
j = 10;//扫描间隔时间设定
while(j–);
duan = 0x00; //消隐
i=0;
}
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
EA=1;
TR1=1;
SM1=1;
REN=1;
ES=1;
}
void usb() interrupt 4
{
RI=0;
temp=SBUF;
}