数码管按键移动位数闪烁实验
#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}; //数码管码表
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">数码管位选
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();
}
}
51单片机数码管按键移动位数闪 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)