用89C51單片機及8位共陽數碼管構成一個動態LED顯示器,能夠實現光標閃爍功能,按下L鍵,光標左移,按下R鍵,光標右移。
自己做的仿真情況亂七八糟 不知道問題在哪 麻煩大佬們了
代碼如下
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
sbit L=P3^0;
sbit R=P3^1;
uchar flash;
uchar disp_on;
uchar code segtab[]=
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x89,0x8c};
uchar dbuf[8]={1,1,1,1,1,1,1,1};
void delay(void)
{ uchar i;
for(i=0;i<200;i++);
}
void disp(void)
{ static uchar cn=0;
uchar n,bsel;
bsel=0x01;
for(n=0;n<8;n++)
{ P2=bsel&disp_on;
P0=segtab[dbuf[n]&0x7f];
if((dbuf[n]&0x80)!=0)
P0=P0&0x7f;
bsel=_crol_(bsel,1);
delay();
P0=0xff;
}
cn++;
if(cn==100)
{ disp_on=disp_on^flash;
cn=0;
}
if(L==0)
{flash=_crol_(flash,1);
disp_on=_cror_(disp_on,1);
}
if(R==0)
{flash=_cror_(flash,1);
disp_on=_crol_(disp_on,1);
}
}
void main(void)
{ flash=0x01;
disp_on=0xff;
while(1)
disp();
} |