整理如下,通过编译:
#include
void
sleep(int
ms)
{
int
i
for(
ms
>
0
ms--
)
{
for(
i
=
0
i
<
124
i++
)
{
}
}
}
void
main(void)
{
while(1)
{
sleep(10000)
p1=0xff
sleep(10000)
}
}
有一个现成的相关程序,你参考参考
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^4
sbit key2=P3^5
sbit key3=P3^6
sbit key4=P3^7
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0xb0,0x8e}
uchar numt0,num
void delayms(uint xms)
{
uint i,j
for(i=xmsi>0i--)
for(j=110j>0j--)
}
void display(uchar numdis)
{
uchar shi,ge
shi=numdis/10
ge=numdis%10
P0=table[shi]
P2=0x0b
delayms(5)
P0=table[ge]
P2=0x07
delayms(5)
}
void init()
{
TMOD=0x01
TH0=(65536-45872)/256
TL0=(65536-45872)%256
EA=1
ET0=1
}
void keyscan()
{
if(key1==0)
{
delayms(10)
if(key1==0)
{
num++
if(num==60)
num=0
while(!key1) //等待按键释放
}
}
if(key2==0)
{
delayms(10)
if(key2==0)
{
if(num==0)
num=60
num--
while(!key2)
}
}
if(key3==0)
{
delayms(10)
if(key3==0)
{
num=0
while(!key3)
}
}
if(key4==0)
{
delayms(10)
if(key4==0)
{
while(!key4)
TR0=~TR0
}
}
}
void main()
{
init()
while(1)
{
keyscan()
display(num)
}
}
void T0_time()interrupt 1
{
TH0=(65536-45872)/256
TL0=(65536-45872)%256
numt0++
if(numt0==20)
{
numt0=0
num++
if(num==60)
num=0
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)