此文章是vip文章,如何查看?  

1,点击链接获取密钥 http://nicethemes.cn/product/view29882.html

2,在下方输入文章查看密钥即可立即查看当前vip文章


定时器/计数器实验报告

  • 时间:
  • 浏览:
  • 来源:互联网

/*************************************************

实验名称:定时器实验一

实验目的:利用定时器/计数器让发光二极管以1HZ闪烁

*************************************************/

#include<reg52.h>


sbit P10 = P1^0;


unsigned char flag;


void main()

{

flag = 0;

P10 = 0;

TH0 = 0xfe;

TH0 = 0xff;

EA = 1;

ET0 = 1;

TR0 = 1;

while(1);

{

if(flag == 1)

{

flag = 0;

P10 = ~P10;

}

}

}


void Timer_0() interrupt 1

{

TH0 = 0xfe;

TH0 = 0xff;

flag = 1;

}


/*************************************************

实验名称:定时器实验二

实验目的:利用定时器/计数器T1产生定时时钟,由P1口

 控制8个发光管。使8个指示灯依次一个一个闪

 动,闪动频率为10次/秒

*************************************************/

#include<reg52.h>

#include<intrins.h>


unsigned char Flag = 0;


sbit SPK = P2^3;


void main()

{

TMOD = 0x01;

TH0 = (65535-23040)/256;

TL0 = (65535-23040)%256;

EA = 1;

ET0 =1;

TR0 = 1;

P1 = 0x7f;

SPK = 0;

while(1)

{

if(Flag == 5)

{

Flag = 0;

P1 = _cror_(P1,1);

SPK = ~SPK;

}

}

}


void Timer0() interrupt 1

{

TH0 = (65535-23040)/256;

TL0 = (65535-23040)%256;

Flag++;

}


/*************************************************

实验名称:定时器实验三

实验目的:利用定时器以间隔500ms在6位数码管上依次

 显示0、1、2、3。。。C、D、E、F,重复。

*************************************************/

#include<reg52.h>


sbit DUAN = P2^6;

sbit WEI = P2^7;


#define uchar unsigned char

#define uint unsigned int


//uchar code wei_table[]=

//{};

uchar code duan_table[]=

{0x3f,0x06,0x5b,0x4f,

 0x66,0x6d,0x7d,0x07,

 0x7f,0x6f,0x77,0x7c,

 0x39,0x5e,0x79,0x71};


uchar Flag = 0;

uchar i = 0;

void main()

{


TMOD = 0x01;

EA = 1;

ET0 = 1;

TH0 = (65535-46080)/256;

TL0 = (65535-46080)%256;

TR0 = 1;

while(1)

{

if(Flag == 10)

{

Flag = 0;

P0 = duan_table[i];

DUAN = 1;

DUAN = 0;

P0 = 0xff;

P0 = 0;

WEI = 1;

WEI = 0;

i++;

if(i == 16)

i = 0;

}

}

}


void Timer0() interrupt 1

{

TH0 = (65535-46080)/256;

TL0 = (65535-46080)%256;

Flag++;

}

本文链接http://element-ui.cn/news/show-576848.aspx