定時(shí)器控制LED Experiment 1 Timer control LED 1.1 實(shí)驗(yàn)要求 Experimental requirement利用51單片機(jī)產(chǎn)生占空比可變的PMW波,當(dāng)產(chǎn)生該波形的I/O口通過濾波電路與LED燈相接后,由于輸出PMW波占空比不斷變化,使得一個(gè)周期內(nèi)有一部分時(shí)間LED導(dǎo)通,一部分時(shí)間截止,從整體來看有一個(gè)變化的平均電壓加在LED燈上,從而達(dá)到動(dòng)態(tài)調(diào)節(jié)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 實(shí)驗(yàn)任務(wù) Tasks利用51單片機(jī)設(shè)計(jì)一個(gè)呼吸燈。所謂呼吸燈是指LED燈光在單片機(jī)的控制之下完成由亮到暗,再從暗到亮的逐漸變化,感覺好像是人在呼吸。 要求在P1.0口輸出占空比變化的PMW波,通過LC低通濾波電路接到LED燈,控制LED燈的亮度變化。這里濾波電路的作用是防止LED燈閃爍太快導(dǎo)致人眼感覺不到亮度的變化。 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 實(shí)驗(yàn)文檔 Report1、實(shí)驗(yàn)源程序(整理經(jīng)過運(yùn)行證明是正確的源程序,并加上分析注釋) - #include <reg52.h>//包含 寄存器的頭文件
- typedef unsigned char u8;//定義無符號數(shù)
- u8 Tcount,dutyfactor,direct;
- sbit LED=P1^0;//是將發(fā)光二極管 led1 接 P1口 0 位端
- void InterruptInit();//
- void Time0();//
- void breatheLED();//定義函數(shù)
- void main()
- {
- InterruptInit();
- while(1)//無限循環(huán)
- {
- breatheLED();
- }
- }
- void InterruptInit()
- {
- TMOD &= 0xf0;//TMOD高四位清零,并保存低四位不變化
- TMOD |= 0x02;//設(shè)定T0的工作模式為工作方式2
- TH0 = 0x48;
- TL0 = 0x48;//設(shè)置定時(shí)器
- ET0 = 1;
- EA = 1;
- TR0 = 1;//設(shè)置電頻
- }
- void Time0() interrupt 1
- {
- TH0 = 0x48;
- TL0 = 0x48;
- Tcount++;
- }
- void breatheLED()
- {
- if(Tcount >= 60)//條件判斷
- {
- Tcount = 0;
- if(direct == 0)
- {
- dutyfactor++;
- }
- else if(direct == 1)
- {
- dutyfactor--;
- }
- }
- if(dutyfactor <= 0)
- {
- direct=0;
- }
- else if(dutyfactor >= 60)
- {
- direct=1;
- }
- if(Tcount < dutyfactor)
- {
- LED=0;//燈亮
- }
- else
- {
- LED=1;//燈滅
- }
- }
復(fù)制代碼 
2、思考題回答(首先將問題翻譯成英文,然后用英文回答) 1、定時(shí)器和計(jì)數(shù)器的區(qū)別是什么? 2、單片機(jī)定時(shí)器/計(jì)數(shù)器T1、T0的工作方式2有什么特點(diǎn)?適用于哪些應(yīng)用場合? (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, 下載次數(shù): 10)
2020-12-17 20:57 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|