赞
踩
STC89C52RC定时器:方法1
#include"reg52.h"
unsigned int count=0;
sbit fm=P2^3;
sbit led = P1^0;
void main()
{
led = 1;
TMOD = 0X20;
TH1 = 256-200;
TL1 = 256-200;
//中断
EA = 1;
ET1=1;
//定时器启动
TR1 = 1;
while(1)
{
if(--count == 2500)
{
count=0;
led = ~led;
}
}
}
void timer0() interrupt 3
{
//delay(500);
count++;
}
STC89C52RC定时器:方法二
#include"reg52.h"
unsigned int count=0;
sbit fm=P2^3;
sbit led = P1^0;
//————————————————————————————————————
//void delay(unsigned int xms)
//{
// unsigned int i,j;
// for(i=xms;i>0;i--)
// for(j=112;j>0;j--);
//}
//————————————————————————————————————
void main()
{
led = 1;
TMOD = 0X10;
TH1 = (65535-50000)/256;
TL1 = (65535-50000)%256;
//中断
EA = 1;
ET1=1;
//定时器启动
TR1 = 1;
while(1)
{
if(--count == 200)
{
count=0;
led = ~led;
}
}
}
void timer0() interrupt 3
{
//delay(500);
TH1 = (65535-50000)/256;
TL1 = (65535-50000)%256;
count++;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。