晶振为12M
#include
void
main
{
TOMD
=
0X01;
//配置定时器0工作于方式一
TH1
=
(65536-50000)/256
//高八位装入初值
TL1
=
(65536-50000)%256
//低八位装入初值
ET0
=
1
//开定时器0中断
EA
=
1
//开总中断
TR0
=
1
//启动定时器0
while(1)
{
;
}
}
void
Timer0_int()
interrupt
1
{
//重新装初值
TH1
=
(65536-50000)/256
//高八位装入初值
TL1
=
(65536-50000)%256
//低八位装入初值
}
/***************************************************************************************************************/
上面是比较好理解的。唤闹如果实在要求简洁的话,看下面的,跟上面功能一样
#include
void
main
{
TOMD
=
0X01;
//配置定时弊渣器0工作于方式一
TH1
=
0x3c
//高八位装入初值
TL1
=
0xb0
//低八位装入初值
IE
=
0x82//开总中断并开定时器0中断
TR0
=
1
//租链悄启动定时器0
while(1)
{
;
}
}
void
Timer0_int()
interrupt
1
{
//重新装初值
TH1
=
0x3c
//高八位装入初值
TL1
=
0xb0
//低八位装入初值}
#include<reg51.h>毕闹#include<intrins.h>
#define uchar unsigned char
uchar distab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00} //0到f
uchar number,dat,time
void 纯嫌t0isr() interrupt 1
{
TH0=(65536-5000)/256
TL0=(65536-5000)%256
number++
if(number>做数手1)number=0
switch(number)
{
case 0:P2=0x02P0=distab[dat/10]
break
case 1:P2=0x01P0=distab[dat%10]
break
default:break
}
}
void t1isr() interrupt 3
{
TH1=(65536-50000)/256
TL1=(65536-50000)%256
time++
if(time%2)P1=_crol_(P1,1)
if(time%4)dat++
dat%=100
}
main()
{
TMOD=0x11
TH0=(65536-5000)/256
TL0=(65536-5000)%256
TH1=(65536-50000)/256
TL1=(65536-50000)%256
time=0
dat=0
TR1=1
ET1=1
TR0=1
ET0=1
EA=1
P1=0xfe
while(1)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)