//很简单,P0显示段码,P2为位选,要P2.0控制数码管个位闪烁,但是在PROTEUSS上仿真并不闪烁,这到底是为什么啊???
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code seg7[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit d1=P2^0;
sbit d2=P2^1;
uchar t;
void delaynms(uchar i)
{
uchar j,m;
for(j=0;j<i;j++)
{
for(m=0;m<121;m++);
}
}
void ininttime0(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer_int0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
if(t=20){t=0;d1=~d1;}//个位闪烁
}
void displayled(void)
{
P0=seg7[0];//个位显示0
d1=0;
delaynms(20);
d1=1;
P0=seg7[1];//十位显示1
d2=0;
delaynms(20);
d2=1;
}
void main(void)
{
ininttime0();
while(1)
displayled();
} |