|
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
程序:
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define d_code P1
#define d_wei P3
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar sec;
uchar count = 0;
void delay(uchar m);
void InitTimer0(void)
{
TMOD = 0x01;
TH0 = -50000 / 256;
TL0 = -50000 % 256;
ET0 = 1;
EA = 1;
TR0 = 1;
}
void main(void)
{
uchar shi,ge;
InitTimer0();
sec = 0;
while(1)
{
shi = sec / 10;
ge = sec % 10;
d_code = 0xff;
d_code = ~tab[shi];
d_wei = 0x02;
delay(10);
d_code = 0xff;
d_code = ~tab[ge];
d_wei = 0x01;
delay(10);
}
}
void Timer0Interrupt(void) interrupt 1
{
TH0=-50000 / 256;
TL0=-50000 % 256;
count ++ ;
if( count > 19 )
{
count = 0;
sec ++ ;
if( sec > 59 )
sec = 0;
}
}
void delay(uchar m) //M ms 延时程序 (12M)
{
unsigned char a,b,c;
for(c=m;c>0;c--)
for(b=142;b>0;b--)
for(a=2;a>0;a--);
}
|
-
-
仿真.7z
41.31 KB, 下载次数: 11, 下载积分: 黑币 -5
评分
-
查看全部评分
|