刚学定时器自己写了这样的程序,从0秒到9999秒的显示
单片机源程序如下:
#include<reg51.h>
#define uchar unsigned char#define uint unsigned int
uchar code duanma[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code xuanma[4]={0x08,0x04,0x02,0x01};
uint m=0;
void delayms(uint j)
{uchar i;
for(;j>0;j--)
{i=250;
while(--i);
i=249;
while(--i);
} }
void display()
{P0=0xff;
P2=xuanma[0];
P0=duanma[m%10];
delayms(2);
P2=xuanma[1];
P0=duanma[(m/10)%10];
delayms(2);
P2=xuanma[2];
P0=duanma[(m/100)%10];
delayms(2);
P2=xuanma[3];
P0=duanma[m/100/10];
delayms(2);}
void time0() interrupt 1 using 1
{uchar j;
j++;
if(j==20)
{
m++;j=0;}
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
}
void main()
{EA=1;ET0=1;
TMOD=0X01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
TR0=1;
while(1)
{display();}}
为什么用Proteus仿真会出现这种情况?求大佬不吝赐教
|