找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2425|回复: 0
收起左侧

基于c51单片机的呼吸灯实验中英文技术文档

[复制链接]
ID:861693 发表于 2020-12-17 20:57 | 显示全部楼层 |阅读模式

定时器控制LED Experiment 1 Timer control LED

1.1 实验要求 Experimental requirement

利用51单片机产生占空比可变的PMW波,当产生该波形的I/O口通过滤波电路与LED灯相接后,由于输出PMW波占空比不断变化,使得一个周期内有一部分时间LED导通,一部分时间截止,从整体来看有一个变化的平均电压加在LED灯上,从而达到动态调节LED灯亮度的目的。


Student use C51 to produce a variable PMW wave. The I/O ports generate the wave through the filter circuit and connect with LED lights. As the output PWM wave duty cycle is constantly changing, a part of the time period LED turns on, part of the time cut off. From the overall point of view there is a change in the average voltage added to the LED lights, so as to achieve the purpose of dynamically adjust the brightness of LED lights

1.2 实验任务 Tasks

利用51单片机设计一个呼吸灯。所谓呼吸灯是指LED灯光在单片机的控制之下完成由亮到暗,再从暗到亮的逐渐变化,感觉好像是人在呼吸。

要求在P1.0口输出占空比变化的PMW波,通过LC低通滤波电路接到LED灯,控制LED灯的亮度变化。这里滤波电路的作用是防止LED灯闪烁太快导致人眼感觉不到亮度的变化。

Design a breathing light with C51 MCU. The so-called breathing light is the LED lights in the MCU control, and the light from the br ight to the dark, and then from dark to bright gradually change, feeling like people are breathing.





1.3 硬件电路 hardware circuit
1.4 实验文档 Report

1、实验源程序(整理经过运行证明是正确的源程序,并加上分析注释)

  1. #include <reg52.h>//包含 寄存器的头文件
  2. typedef unsigned char u8;//定义无符号数
  3. u8 Tcount,dutyfactor,direct;
  4. sbit LED=P1^0;//是将发光二极管 led1 接 P1口 0 位端
  5. void InterruptInit();//
  6. void Time0();//
  7. void breatheLED();//定义函数
  8. void main()
  9. {
  10. InterruptInit();
  11. while(1)//无限循环
  12.               {
  13.                             breatheLED();
  14.               }
  15. }
  16. void InterruptInit()
  17. {
  18.               TMOD &= 0xf0;//TMOD高四位清零,并保存低四位不变化
  19.               TMOD |= 0x02;//设定T0的工作模式为工作方式2
  20.               TH0 = 0x48;
  21.               TL0 = 0x48;//设置定时器
  22.               ET0 = 1;
  23.               EA  = 1;
  24.               TR0 = 1;//设置电频
  25. }
  26. void Time0() interrupt 1
  27. {
  28.               TH0 = 0x48;
  29.               TL0 = 0x48;
  30.               Tcount++;
  31. }
  32. void breatheLED()
  33. {
  34.               if(Tcount >= 60)//条件判断
  35.               {
  36.                             Tcount = 0;
  37.                             if(direct == 0)
  38.                             {
  39.                                           dutyfactor++;
  40.                             }
  41.                             else if(direct == 1)
  42.                             {
  43.                                           dutyfactor--;
  44.                             }
  45.               }
  46.               if(dutyfactor <= 0)
  47.               {
  48.                             direct=0;
  49.               }
  50.               else if(dutyfactor >= 60)
  51.               {
  52.                             direct=1;
  53.               }
  54.               if(Tcount < dutyfactor)
  55.               {
  56.                             LED=0;//灯亮
  57.               }
  58.               else
  59.               {
  60.                             LED=1;//灯灭
  61.               }
  62. }
复制代码



2、思考题回答(首先将问题翻译成英文,然后用英文回答)

1、定时器和计数器的区别是什么?

2、单片机定时器/计数器T1、T0的工作方式2有什么特点?适用于哪些应用场合?

(1)What is the difference between a timer and a counter?

A counter is the one that keeps counting when you start counting from zero! Unless you stop him, he won't keep remembering! The timer is different! You need to set a time for yourself before you start counting! When your time has been counted down, it stops automatically

  • What are the characteristics of working mode 2 of timer / counter T1 and t0? For which applications?

Mode 2 is an 8-bit timer / counter automatically loaded with initial value, which overcomes the problem of cycle timing or cycle counting application            There is a problem that the counting initial value is loaded repeatedly with the instruction, which affects the timing accuracy.


  • 问题分析及实验心得

In this experiment, we need to select the appropriate crystal frequency and use LC low-pass filter circuit to prevent the LED from changing too fast to feel the change of brightness.Through this experiment, I have a better understanding of the combination circuit and programming of single-chip computer.The experiment is time-consuming and uncomplicated, and can be completed quickly with the help of the teachers and classmates.Finally, thank you for your teacher's instruction and your classmates'warm help.

完整的Word格式文档51黑下载地址:
c51呼吸灯.docx (508.93 KB, 下载次数: 9)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表