仿真原理圖:
#include <reg52.h>
#define uchar unsigned char
#define uint? unsigned? int
uchar duan[10]={0xc0,0Xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};???????? //所需的段的位碼
//uchar wei[4]={0XEf,0XDf,0XBf,0X7f};???????????????????????????????? //位的控制端???? (開發(fā)板)
uchar wei[4]={0X80,0X40,0X20,0X10};???????????????????????????????? //位的控制端????? (仿真)
uint z,x,c,v, date;??? //定義數(shù)據(jù)類型
uint dispcount=0;
uint lck=0;
uint disp=0;
/******************************************************************
P2=wei[3];
P0=duan[v];
delay(50);
}
/*************************************************************************
定時器初值1ms
**************************************************************************/
void initTimer(void)
{
TMOD=0x0;
TH0=0xe3;
TL0=0xc;
}
/*************************************************************************
定時器函數(shù)
**************************************************************************/
void timer0(void) interrupt 1
{
TH0=0xe3;
TL0=0xc;
lck++;
if(lck==1000)
{
disp=dispcount;
lck=0;
dispcount=0;
}
}
/*************************************************************************
中斷函數(shù)
**************************************************************************/
void int0(void) interrupt 0
{
dispcount++; //每一次中斷,計數(shù)加一
}
/*************************************************************************
主函數(shù)
**************************************************************************/
void main(void)
{
IT0=1;???? //INT0下降沿中斷
EX0=1;???? //允許INT1中斷
initTimer(); //裝入初值
TR0=1;
ET0=1;
EA=1;
while(1)
{
date=disp;
xianshi();