拿去吧,这有定时器不同时间的应用!用数组给定时器值
#include<reg51.h>
#define uchar unsigned char
#define uchar unsigned char
#define uint unsigned int
unsigned int i=0; f=0;
unsigned char mm[ ] = {0x04,0xf5,0x56,0xef,0x14,0xb1,0xc7,0x98,0xe2,0x25,0xd4,0x02,0x11,0xa8,0xb7,0x03};
sbit led=P1^0;
void main()
{
TMOD=0x01; //T0工作在方式1下,16位定时功能
TH0=f; //定时器T1的高8位赋初值
TL0=f; //定时器T1的高8位赋初值
TF0=0; //清除TF0标志位
TR0=1; //启动T0
while(1)
{
if(TF0==1) //判断T0溢出标志位是否为1
{
TF0=0;
i++;
if(i==16)
f=mm[i];
TH0=f; //定时器T1的高8位赋初值
TL0=f; //定时器T1的高8位赋初值
led=~led;
i=0;
}
}}
|