新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 數(shù)碼管按鍵移動位數(shù)閃爍實驗

數(shù)碼管按鍵移動位數(shù)閃爍實驗

作者: 時間:2016-11-30 來源:網絡 收藏
#include
#define uchar unsigned char
#define uint unsigned int
sbit k1=P1^0;
void delay(uint k)
{
while(k--);
}

code uchar seg[]={0x28,0x7e,0xa2,0x62,0x74,0x61,0x21,0x7a,0x20,0x60}; //數(shù)碼管碼表
code uchar tab[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; //adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=17&is_app=0&jk=fb94c0fae2a73ad&k=%CA%FD%C2%EB%B9%DC&k0=%CA%FD%C2%EB%B9%DC&kdi0=0&luki=3&n=10&p=baidu&q=98059059_cpr&rb=0&rs=1&seller_id=1&sid=ad732aaef4cb90f&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F2141%2Ehtml&urlid=0" id="1_nwl" mpid="1" target="_blank">數(shù)碼管位選
uchar move,flag;
void time0_init()
{
TMOD=0x01;
TH0=0x00;
TL0=0x00;
TR0=1;
}
void str_init() //中斷初始化
{
EA=1;
ET0=1;
}
void time0_event() interrupt 1//中斷事件
{
static uchar i;
i++;
if(i==15)
{
flag=~flag;i=0;
}
}
void show()
{
uchar i;
for(i=0;i<4;i++)
{
if(i==move)
{
P0=seg[i]|(0xdf&flag);
}
else
{
P0=seg[i];
}
P2=tab[i];
delay(100);
P0=0xff;
P2=0xff;
}
}
void key()
{
static uchar i,j;
if(k1==0)
{
if(i==0)
{
j++;
if(j>10)
{
if(k1==0)
{
i=1;j=0;
move++;
if(move==4)move=0;
}
}
}
}
else
{
i=0;
j=0;
}
}
void main()
{
time0_init();
str_init();
while(1)
{
key();
show();
}
}


評論


技術專區(qū)

關閉