#include <reg52.h>
#define DataPort P0 //定义数据端口
sbit LATCH_Seg = P2^2;//定义锁存使能端口,段锁存
sbit LATCH_Bit = P2^3;// 位
unsigned char DuanMa[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
#define DataPort P0 //定义数据端口
sbit LATCH_Seg = P2^2;//定义锁存使能端口,段锁存
sbit LATCH_Bit = P2^3;// 位
unsigned char DuanMa[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char WeiMa[] ={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void Delay(unsigned char i)
{
unsigned char j,k;
for(j = 0 ; j < 100 ; j++)
for(k = 0 ; k < i ; k++)
;
}
//display//
void display(unsigned char Firstbit,unsigned char num)//firstbit表示从第几个段开始,num表示位数
{
unsigned char i;
for (i=0;i<num;i++)
{
DataPort = 0;//清空数据,防止交替重影
LATCH_Seg = 1;
LATCH_Seg = 0;
DataPort = WeiMa[i+Firstbit];
LATCH_Bit = 1;
LATCH_Bit= 0;
DataPort = DuanMa[i];
LATCH_Seg = 1;
LATCH_Seg = 0;
Delay(1);
}
}