# Blue Bridge Cup shock 10-NE555 square wave generator

To learn NE555 square wave generator, first paste the schematic diagram: We can find that the NE555 on board has been connected, and the controllable port only leaves NET_SIG, that is, square wave output terminal. Observe the CT107D development board, and we can find the array pin of square wave output port on the far right We use jumper cap to connect SIGNAL and P34, then the SIGNAL output terminal is connected to the count port of timer 0

Basic ideas:

The square wave generator of NE555 is connected with the interface of timer 0P3^4. We need to turn on timer 1 first, and then turn timer 0 into a counter within the specified time of timer 1
The frequency can be obtained by calculating the frequency formula

Here's the code:

```/*
NE555 Timer experiment, CT107D has prepared the circuit of NE555 square wave generator for us. We only need to rotate the Rb3 potentiometer
To adjust its output frequency, we need to use timer and counter to calculate its frequency;
Basic idea: the square wave generator of NE555 is connected with the interface of timer 0P3^4. We need to turn on timer 1 first, and then turn timer 0 into a counter within the specified time of timer 1
The frequency can be obtained by counting the times of falling edge of square wave
*/

#include <reg52.h>

#define uchar unsigned char
#define uint unsigned int

uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,0xbf,0x7f};
uchar DisplayData[]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};

uint NE555_Falling,NE555_Time,NE555_Frequency;   //Number of falling edge / 555 time / frequency
uchar DisplaySite;

void ChooseNixie(uchar site,uchar num);
void Delay(uint i);
void Display();

void main()
{
TMOD=0x16;  //Timer 0 uses counting mode, 8-bit counter 0110 for automatic initial value reassembly; enable timer 1 as timer, and count the time between pulses of NE555
TH0=0xFF; TL0=0xFF;   //The initial value of the counter is full, so that an interrupt can be triggered when a falling edge is detected
TH1=(65536-5000)/256; TL1=(65536-5000)%256;  //Timer 1: 5ms at the middle end
ET0=1; ET1=1; EA=1;
TR0=1; TR1=1;
while (1)
{
Display();
}
}

void Timer0() interrupt 1   //Timer 0 is used as counter to trigger interrupt when falling edge is detected
{
NE555_Falling++;
}
void Timer1() interrupt 3  //Timer 1 as timer, calculating cycle
{
TH1=(65536-5000)/256; TL1=(65536-5000)%256;  //Timer 1: 5ms at the middle end
NE555_Time++;
if (NE555_Time==20)   //100ms / / calculate the number of falling edges of NE555 in 100ms, and then calculate the frequency
{
NE555_Frequency = NE555_Falling*10;   //If the frequency is the number of falling edges in 1s, and the timing is 0.1s, it needs * 10
NE555_Falling=0;
NE555_Time=0;
}
}

void ChooseNixie(uchar site,uchar num)
{
P2=(P2&0x1F)|0xE0; P0=0xFF; P2&=0x1F;
P2=(P2&0x1F)|0xC0; P0=1<<site; P2&=0x1F;
P2=(P2&0x1F)|0xE0; P0=num; P2&=0x1F;
}
void Delay(uint i)
{
while (i--);
}

void Display()
{
DisplayData = table[NE555_Frequency%10];
DisplayData = table[NE555_Frequency%100/10];
DisplayData = NE555_Frequency >100 ? table[NE555_Frequency%1000/100] : 0xFF;
DisplayData = NE555_Frequency >= 1000 ? table[NE555_Frequency%10000/1000] : 0xFF;
DisplayData = NE555_Frequency >= 10000 ? table[NE555_Frequency/10000] : 0xFF;
for (DisplaySite=3;DisplaySite<8;DisplaySite++)
{
ChooseNixie(DisplaySite,DisplayData[DisplaySite]);
Delay(60);
}
}```

The frequency of NE555 can be seen on the board by turning the potentiometer Rb3 after burning to the single chip microcomputer

Posted on Fri, 08 Nov 2019 12:48:17 -0800 by adammc