【Title requirements】
On the CT107D MCU comprehensive training platform, NE555 is used to generate a square wave signal and measure its frequency. The specific functional requirements are as follows:
[1] Turn off the buzzer, relay and 8 LED indicators when it is powered on and running.
[2] Use a short-circuit ring to short-circuit NAL in J13 and P34 , and the signal generated by NE555 is input to the P34 pin of the microcontroller.
[3] The single-chip microcomputer measures the frequency of the signal and displays it in the digital tube. The frequency data is displayed with a 6-digit digital tube , and the unit is Hz. When the display length is less than 6 digits, the unused digital tube will go out, and the 1 digit on the far left The nixie tube uses " F " as a prompt. The display format is as follows :
【Special Note】
This question is a part of the programming question of the 10th Blue Bridge Cup Provincial Competition.
Because many candidates reported that because they did not understand the NE555 chip, they would not do this question. In fact, you don't need to know the NE555 chip to do this problem. For the NE555 circuit on the CT107D board of the Blue Bridge Cup competition platform, you only need to know 2 points :
[1] The NE555 circuit is a signal generating circuit, and its signal output is connected to the P34 pin of the microcontroller, that is, the T0 pin of the microcontroller.
[2] The frequency of the signal can be changed by the Rb3 adjustable potentiometer .
Because the NE555 chip is basically a pure hardware design, there is no programmable content, therefore, once the circuit is determined, there will be no change, and the microcontroller does not need any configuration for it. Therefore, in the whole process of measuring the frequency of the single-chip microcomputer, it has nothing to do with the NE555 chip . In fact, what is examined is the technology you use to measure the frequency of the signal with the timer/counter.
【Reference Code】
/*=====================================================================
***案例名称:基于NE555的信号发生与频率测量
***编程模式:MM模式
***作者信息:广东职业技术学院 欧浩源(小蜜蜂老师)
***电子邮箱:[email protected]
***设计时间:2019-04-06
=====================================================================*/
#include "reg52.h"
#include "absacc.h"
unsigned char code SMG_DM_NoDot[18]=
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
0x88,0x80,0xc6,0xc0,0x86,0x8e,0xbf,0x7f};
unsigned int count_f = 0;
unsigned char count_t = 0;
unsigned int dat_f = 0;
void DelaySMG(unsigned int t)
{
while(t--);
}
void DisplaySMG_Bit(unsigned char pos, unsigned char value)
{
XBYTE[0xE000] = 0xFF;
XBYTE[0xC000] = 0x01 << pos;
XBYTE[0xE000] = value;
}
void DisplaySMG_F()
{
DisplaySMG_Bit(0, SMG_DM_NoDot[15]);
DelaySMG(500);
if(dat_f > 9999)
DisplaySMG_Bit(3, SMG_DM_NoDot[dat_f / 10000]);
DelaySMG(500);
if(dat_f > 999)
DisplaySMG_Bit(4, SMG_DM_NoDot[(dat_f / 1000) % 10]);
DelaySMG(500);
if(dat_f > 99)
DisplaySMG_Bit(5, SMG_DM_NoDot[(dat_f / 100) % 10]);
DelaySMG(500);
if(dat_f > 9)
DisplaySMG_Bit(6, SMG_DM_NoDot[(dat_f / 10) % 10]);
DelaySMG(500);
DisplaySMG_Bit(7, SMG_DM_NoDot[dat_f % 10]);
DelaySMG(500);
}
void Init_Timer()
{
TH0 = 0xff;
TL0 = 0xff;
TH1 = (65536 - 50000) / 256;
TL1 = (65536 - 50000) % 256;
TMOD = 0x16; //定时器1用方式1,定时;定时器0用方式2,计数
ET0 = 1;
ET1 = 1;
EA = 1;
TR0 = 1;
TR1 = 1;
}
void Service_T0() interrupt 1
{
count_f++;
}
void Service_T1() interrupt 3
{
TH1 = (65536 - 50000) / 256;
TL1 = (65536 - 50000) % 256;
count_t++;
if(count_t == 20)
{
dat_f = count_f;
count_f = 0;
count_t = 0;
}
}
void main()
{
Init_Timer();
XBYTE[0x8000] = 0xff;
XBYTE[0xA000] = 0x00;
while(1)
{
DisplaySMG_F();
}
}
[ Guangdong Vocational and Technical College Ou Haoyuan ]: [email protected]
[ Little Bee Note Network ]: www.xmf393.com
[ Technical WeChat ]: gzyohy